0% found this document useful (0 votes)
3 views

Programming Python Handbook - Logiscool

This document is a course guide for Mix Programming with Python, aimed at students learning to transition from block coding to text-based programming. It covers various topics including motion, positioning, direction, display, and real-world applications of Python. The guide emphasizes the importance of understanding coding concepts through a mix of visual and textual coding methods.

Uploaded by

amitvasa81
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Programming Python Handbook - Logiscool

This document is a course guide for Mix Programming with Python, aimed at students learning to transition from block coding to text-based programming. It covers various topics including motion, positioning, direction, display, and real-world applications of Python. The guide emphasizes the importance of understanding coding concepts through a mix of visual and textual coding methods.

Uploaded by

amitvasa81
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 134

BLOX + TEXT

MIX PROGRAMMING
PYTHON

STUDENT
COURSE NOTES
Mix Programming
With Python
First Edition

Logiscool Singapore
Published by
Logiscool Singapore

#02-254B, Gek Poh Shopping


Center, 762 Jurong West Street 75,
Singapore 640762

Printed in Singapore.

This book was last authored on August 2024.

Copyright © 2024 by Logiscool Singapore, Singapore


All rights reserved. No part of this book may be reproduced, distributed,
or transmitted in any form or by any means, including photocopying,
recording, or other electronic or mechanical methods, without the prior
written permission of the publisher, except in the case of brief quotations
embodied in critical reviews and certain other non-commercial uses
permitted by copyright law.
Contents

Mix Programming Pg 9
1 Introduction Pg 11
Python Pg 13
Real-world applications Pg 14

Motion Pg 15
2 Positioning Pg 17
Direction Pg 20
Movement Pg 22

Looks Pg 27
3 Display Pg 29
Size Pg 30
Opacity Pg 30
Colours Pg 31
Costume Pg 32
Scene Pg 34
Contents

Sensing Pg 43
4 Collision and Touch Pg 45
Inputs Pg 46
Time Pg 47

Data Pg 53
5 Variables Pg 55
List Pg 56
Functions Pg 60

Events Pg 69
6 Signals Pg 73
Clone Pg 75
Contents

Control Pg 79
7 Delay Pg 81
Loops Pg 81
If-Else Statements Pg 82
Cloning Pg 83

Operators Pg 89
8 Arithmetic Operators Pg 91
Boolean Values Pg 91
Comparison Operators Pg 92
Logical Operators Pg 92
String Pg 93
Assignment Statements Pg 94
Other Functions Pg 96
Contents

Physics Pg 105
9 Force and Gravity Pg 107
Friction Pg 109
Speed Pg 110
Collision Pg 111

Pen Pg 115
8 Drawing Pg 117
Pen Size Pg 118
Pen Colour Pg 118
Pen Shape Pg 119
9

Mix
Programming
Transitioning from block coding
to text-based coding is like
discovering that each blox is
actually made of text, and now
you write that text directly.

Introduction
Python
Real-world Applications
10
11

Introduction
Logiscool Coding Road Map:

Blox Mix Text-based


Coding Programming Programming

Why Do We Learn Blox Coding?


We start with blox coding because it makes learning to code fun and
simple. With blox coding, you get to use colorful blocks that fit
together like puzzle pieces to create your programs. This way, you
can focus on understanding how coding works without worrying
about making mistakes with typing. Block coding helps you learn the
basics of programming, like loops and conditions, in a way that’s
easy to understand.

Mix Programming (Blox + Text)


After you’ve gotten the hang of blox coding, it’s time to try something
new: Mix Programming! In mix programming, you’ll start combining
the blocks you’re used to with some simple text-based coding.

Blox to Text
when started:
while True:
x += 10

This helps you see how the blocks you’ve been using are actually
made up of lines of code. Mix programming is like a bridge that
connects what you already know with what you’re going to learn next.
It’s a fun way to start exploring how text coding works while still using
the blocks that make things easy to understand.
12

Introduction
Text-based Programming
Text programming is like building your own LEGO set from scratch.
Instead of snapping together pre-made blocks, you create each
piece by writing out instructions.

write
when started:
yourself
while True:
x += 10

It might seem challenging at first, but everything you learned in block


coding and mix programming will help you along the way. By
mastering text-based coding, you’ll learn how to give your computer
exact commands, unlocking endless creativity and new possibilities!
13

Python
Python is a programming language used by people
all over the world to create games, apps, websites,
and so much more.
Python was created in 1989 by a programmer
named Guido van Rossum. He wanted to design a
programming language that was both powerful
and easy to use, so that more people could learn
to code. Guido named it "Python" after a comedy
Guido van Rossum show he liked called "Monty Python's Flying Circus,"
(Creator of because he wanted the language to be fun and
Python)
accessible.
Since then, Python has become one of the most
popular programming languages in the world.
People use Python for all kinds of things, from
building websites and creating games to controlling
robots and exploring space! It’s used by big
Top companies
companies like Google and NASA, and even by that uses
scientists. Python

Simple Python Program: Multiplication of 12


Output:
num = 12
12 x 1 = 12
for i in range(1, 11): 12 x 2 = 24
print(num, 'x', i, '=', num*i) 12 x 3 = 36
12 x 4 = 48
12 x 5 = 60
12 x 6 = 72
Try inserting this code to a online 12 x 7 = 84
Python Compiler, click run and see
12 x 8 = 96
what is the output
12 x 9 = 108
12 x 10 = 120
14

Real-world Applications
Let’s explore some of the amazing things you can do with Python in the
real world!
this is a cat this is a dog
Artificial ???
Intelligence (AI) :
and Machine
Learning (ML)

Python can help you teach your computer to recognize different


animals. By showing it pictures, like those of cats and dogs, your
computer learns to figure out which is which. This ability is called AI and
ML. With these tools, your computer becomes smarter and better at
understanding what it sees!

Data
Analytics :
(Weather
forecast)
In this example, we use Python to analyze weather data, such as
temperature and humidity. By examining these data points, Python
helps us forecast whether it will remain sunny, become cloudy, or if rain
is expected. This demonstrates how data analytics can be used to
effectively understand and predict weather patterns.

Robotics and
Automation :

Python is a key tool in robotics, allowing you to program robots to


move, sense, and perform tasks automatically. With Python, you can
control robots to follow lines, avoid obstacles, and complete missions.
LEGO Education’s kits, like LEGO Mindstorms and Spike Prime, use
Python to make learning robotics fun and interactive,
15

Motion
noun [motion]

the action or process of moving


or being moved.

Positioning
Direction
Movement
16
17

Positioning
Positioning: Tell your actors where to go
Horizontal Position runs from the left to the right side
Vertical Position runs from the top to the bottom

Tell your actors to go to


the X position only

Tell your actors to go


to the Y position only

Tell your actors go to


both X position and Y
position

By default, we are using


the cartesian coordinate
system.

Y-Position X Position= 190


Y Position =115
X Position= 0
Y Position =115
X Position= -230
Y Position =115 X Position= 230
Y Position =-0

X Position= -230 X Position = 0


X-Position
Y Position =0 Y Position = 0
The pencil is at
the center
X Position= -110
Y Position =-115 X Position= 0
Y Position =-115 X Position= 190
Y Position =-115
18

Positioning
Increment: Increase (+)
Decrement:Decrease (-)
Make your actor go
towards the right

Make your actor go


towards the left

Make your actor go higher

Make your actor go lower

These are variables

Increment
Y Position

Decrement X Position Increment X Position

Decrement
Y Position
19

Positioning
Positioning: Telling where your actors to go

This "go to" blox code is


fastest way for your actors
to go to a certain location
on the screen without
determining its position

*Mouse
Pointer =

Example:

Top left Corner Top right


Corner

Y
Center Position
Random
Position
Bottom
Bottom left go to
right
corner Pencil
Corner

X Position
20

Direction
A Direction refers to the path which someone or something moves
Rotate: Turning your actor to a certain direction
A degree is a unit used to represent the measurement of an angle on
how much to rotate. A full circle has 360 degrees.

0/360

315 45

270
90

225 135

180

Examples

1.

2.
21

Direction
Point: face towards the direction of something

Make your actor points


towards the direction of
something

Program your actors


to how you want them
to rotate

This is a variable

Example:

r
Point towards ne
To
pl cor
eft the cupcake ht
co p rig
rn
er To

Bo
t tto
lef m
rig
m
otto r Random c or ht
B ne ne
r position r
co
22

Movement
Movement is an act of moving

Make your actor moves by how many steps


you want

10 steps

Make your actor moves from one


position to another position in a
certain duration

Make your actor


bounce off, if it
is touching the
edges
23

Positioning
x=0

y=0

setPosition(0, 0)

x += 10

x -= 10

y += 10

y -= 10

coordinateSystem = "center"

goTo(UFO)
goTo(Pointer.position)
goTo(Position.random())
goTo(Position.center)
goTo(Position.topLeft)
goTo(Position.bottomLeft)
goTo(Position.topRight)
goTo(Position.bottomRight)
24

Direction
This is a variable
called “heading”

heading = 135

turnRight(30)

turnLeft(20)

pointTowards(UFO)

rotationStyle = "leftRight"
rotationStyle = "allAround"
rotationStyle = "none"

variable value
(expression)
Assignment

heading = 135

*We’ll dive into the concepts of variables, assignment, and


expressions later.
25

Movement
move(10)

glideSecondsTo(1, 10, 50)

bounceOffEdge()

Those highlighted in blue are called Functions. They’re like shortcuts


in your code that perform actions with just one command. Instead of
writing out all the steps each time, you can use a function to make
things happen quickly and easily.

*We’ll explore the concept of Functions in more detail later on.


26

Sample Program

when started:
show()
heading = 90
setPosition(50, 7)
while True:
move(10)
wait(1)
turnRight(15)

When Started,
set the direction to 90 degrees angle, then
make the actor go to position: x = 50, y = 7.
Forever, make the actor move by 10 steps every second then
turn 15 degrees to the right
27

Looks
noun [looks]

the appearance of someone or


something

Display
Size
Opacity
Colours
Costume
Scene
28
29

Display
Display: How do you want your actors to be shown on the screen?

Make your actor


appear in front of
selected actor

Make your actor


appear behind
selected actor

Make your actor


appear in front
of all other
actors

Make your actor appear a few layers


forward
Make your actor
appear behind
of all other
actors

Make your actor appear a few layers


behind other actors

Make your actor say something


30

Size
Size: How big or small something is

Increasing and decreasing


the size of your actor

Opacity
Opacity describes how faded an object is

How faded do you


want your actor to
be?

Increase the Decrease


opacity of the opacity
your actor of your actor
31

Colours
Each colour has a tint hue and tint shade. Tint adds an extra layer of
colour.
Tint hue: The colour spectre (rainbow)
Tint shade: The lightness and darkness of the colour.

Tint Hue

Tint
Shade

RGB colors, which stand for Red, Green, and Blue, are the primary
colors of light. This concept provides a more accurate representation of
how colors are displayed in the digital world.

RGB colour values range from 0


to 255, with 255 being the
maximum intensity of a primary
When B colour.
(blue) is
set to 255:
R: 255, G: 255, B: 0

Red

R: 0, G: 255, B: 255
Yellow Magenta

White
Green Blue R: 40, G: 62, B: 55

Cyan
32

Costume
Costumes are skins of an actor. An actor can have more than 1
costume.
*Costumes of an actor can be found in the design tab

Choose the
costume
that you
want your
actors to Costume name: Axolotl Pink Idle
wear
on Land

Costume name: Axolotl Pink Jump 5

Costume name: Axolotl Pink


Hurt on Land
33

Costume
Switch to the Switch to the
previous next costume
costume of the of the actor
actor

Costume name is the


Costume index is the name of a costume.
identity of a It is also a variable.
costume. It is also a
variable.

This is a condition that checks if the actor is wearing the selected


costume.

Example

1.
10 11 12

Costume name: Costume name: Costume name:


Axolotl Pink Jump 3 Axolotl Pink Jump 4 Axolotl Pink Jump 5

2.
10 9 8

Costume name: Costume name: Costume name:


Axolotl Pink Jump 3 Axolotl Pink Jump 2 Axolotl Pink Jump 1
34

Scene
Scenes are background of the stage. A stage can have more than 1
scene.
*Scenes of the stage can be found in the design tab.

Choose a
background for
your stage
Stage name: Planets

Scene name: Try Again

Scene name: Good Job Purple


35

Scene
Switch to the Switch to the
previous scene next scene of
of the stage the stage

Backdrop name is the


name of a scene. It is
Backdrop index is
also a variable.
the identity of a
scene. It is also a
variable.
Check if the backdrop is
currently the one you have
selected

Examples

1.
1 2 3

Scene name: Scene name: Scene name:


Planets Try Again Good Job Purple

2.
1 3 2

Scene name: Scene name: Scene name:


Planets Good Job Purple Try Again
36

Scene
In logiscool, "Move parallax" refers to the background/scene moving.
*Will dive deeper into this topic in class, trainer to demonstrate in
class

Background move to the right

Background move to left

Same concept

Coding Example:

When started, move the


actor to the center. Switch
the scene to "Planets" and
switch costume to
“Axolotl_Pink_Idle_on_Land”,
then make the actor visible.
Forever, pick a random
costume index of the actor
from 1 to 9, every second.

Create 2 events to check:


if the left arrow key is pressed, switch
the scene to the previous one.
if the right arrow key is pressed,
switch the scene to the next one.
37

Display
show()

hide()

goBefore(UFO)

goAfter(UFO)

goToFront()

goForwardBy(1)

goToBack()

goBackwardBy(1)

say("Hello World!")
38

Size
This is a variable
called “size”

size = 30

size += 10

size -= 10

Opacity
This is a variable
called “opacity”

opacity = 60

opacity += 10

opacity -= 10
39

Colours
variable: tint

tint = 100

tint += 10

variable: tintHue

tintHue = 50

tintHue += 10

variable: tintShade

tintShade = 50

tintShade+= 10

setRgbTint(0, 0, 255)

colour code setCssTint("#0000ff")


begins with #

resetTint()

variable += value
drop down menu for
some blox only variable -= value
variable /= value
variable *= value
40

Costume
variable: costumeName

variable: costumeId

setCostume(UFO_2)

nextCostume()

previousCostume()

To be used in a
condition

Example:

if isCostumeSelected(UFO_2): if costumeId == 1:
show() show()
41

Scene
variable: sceneName

variable: sceneId

setScene(Planets)

nextScene()

previousScene()

isSceneSelected(Planets)

To be used in a
condition

Spring_Forest_Starry_Night.move(-10)

Street_Light_Evening.moveLayer("Evening", -10)
42

Sample Program

when started:
while True:
setCostume(randrange(1, 30, 1))
if isCostumeSelected(Axolotl_Pink_Walk_1):
say(costumeName)
else:
say(costumeId) when started:
show()
wait(1) size = 50
setScene(Planets)
while True:
goTo(Pointer.position)

when keyPressed("down arrow"):


size -= 10

when keyPressed("up arrow"):


size += 10
43

Sensing
present participle [sensing]

be aware of (something)

Position & Collison


Input
Others
Time
44
45

Position & Collison


Touch: come into or be in contact with something.
Collision: more than 1 object clash into each other.

Clone

Clone
Actor
Check if your actor is
touching other actors
and their clones.Returns
a true or false value. The orange is touching the Axolotl
and its clones, therefore, the
answer is True.

Collision shape defines the


area that the object occupies
and is used to detect any
touches or collisions.

Let's check out how different collisions affects the actor:


Shape of
Box Circle Costume

Touching Touching Not Touching


46

Position & Collison


Distance: How far are you from something.

Automatically calculate the distance of


your actor from something.

Pointer X refers to Pointer Y refers to


the X position of the Y position of
where the where the
mouse-pointer is mouse-pointer is
at. This is a at. This is a
variable. variable.

Input
An input is something you give to a computer, like pressing a key or
clicking a mouse, to make it do something.

Check if your mouse pointer is touching your


actor. Returns a true or false value.

This block of code checks if the mouse


pointer is (clicked down) on any part of the
screen. Returns a true or false value.

Check if a key is pressed on your


keyboard.
Returns a true or false value.
47

Time
Timer is used to measure time.
A timer starts time from 0 seconds.

It is also a variable as it keeps


changing its value as it counts
When you use a timer, it will
appear at the screen

Set the time back to 0 seconds

This example will show you how to use a timer:

First, define a variable to


store the value of the timer

Always, reset the timer to


make the timer starts from 0
Starts from 0
Then show the
variable on the screen

Continue
counting
Forever, set the value of the variable time
to the timer
This way, the timer will be updating and
counting
48

Time
A date is a specific day, month, and year used to mark a point in time.

Get the Current Date.


(DD,MM,YYYY)

Get the current value of the


attribute you have selected

Year Month Day

This is a variable.

Get the number of days since the


year 2000.

Get the number of days


between 2 dates

Date 1 Date 2

Example:

Output:
49

Position & Collison


physics.collisionShape = "box"
physics.collisionShape = "circle"
physics.collisionShape = "polygon"

touching(Axolotl_Pink)
touching(Edge.top)
touching(Edge.bottom)
touching(Edge.left)
touching(Edge.right)
touching(Edge.vertical)
touching(Edge.horizontal)
touching(Edge.any)

touchingActorOrClone(Axolotl_Pink)

variable: Pointer.x
variable: Pointer.y

distanceTo(Pointer.position)
50

Input
variable: Pointer.isDown

isPointerOver()

isKeyPressed("space")

isKeyPressed("right arrow")

isKeyPressed("a")

Others
variable: username

ask("What's your
name?")
To be used in a
condition
51

Time
Timer.read()

Timer.reset()

Date.now()

Date.from(2000, 12, 24)

Date.daysSince2000()

Date.getFullYear()
Date.getMonth()
Date.getDate()
Date.getDay()
Date.getHours()
Date.getMinutes()
Date.getSeconds()

Date.daysBetween(Date.from(2024, 1, 1), Date.from(2024, 8, 9))


52

Sample Program
Simple Actor Movement Code.

When:
“a” key is pressed - move left | “d” key is pressed - move right
“w” key is pressed - move up | “s” key is pressed - move down

If actor touches any edges, then make actor go to position: x = 0, y = 0.

when started:
setPosition(0, 0)
show()
while True:
if isKeyPressed("w"):
y += 10
if isKeyPressed("s"):
y -= 10
if isKeyPressed("a"):
x -= 10
if isKeyPressed("d"):
x += 10
if touching(Edge.any):
setPosition(0, 0)
53

Data
noun [data]

Data are information that is


stored in or used by a
computer.

Variables
List
Functions
54
55

Variables
A variable is a value that can change, depending on conditions or on
information passed to the program. When defined in the stage, it is
called a global variable and when it is defined in the actor, it is a local
variable.

Initialisation refers to the process of


assigning an initial value to a variable
when it is created. Variables can be
created before the start of the
program (global) or during the
program (local)

Show the value of the variable on the


screen

Do not show the value of the variable


on the screen

After a variable is created, you can


access the value of the variable using
this blox code

After a variable is created, you can


change the value of the variable using
this blox code

Increase the value of the


Decrease the value of the
variable
variable
56

List
An array is a data structure that can store a list of elements.

This is an array
The elements in this examples are:
block
Apple, Orange and Banana

To create an array:
The array blox array have to be
defined within the “define
variable” blox to become a list/
array variable.

To add/remove elements:
Elements

During
: Add
Initialisation

List: Apple, Grape Delete


Element Count: 2

During Program:

List (before): Apple, Grape


List (after): Apple, Grape, Orange
Element Count: 3

List (before): Apple, Grape, Orange List (before): Grape, Orange


List (after): Grape, Orange List (after):
Element Count: 2 Element Count: 0
57

List
Elements and Indexing
Each item in an array is called an
element.
List: Apple, Grape, Orange
In this example: Apple, Grape and
Element Count: 3
Orange are elements. There are 3
elements in the list.

An index in an array is a
List: Apple, Grape, Orange numerical position used to access
a specific element within the
Index Index Index array. The Index of an array starts
0 1 2 from 0, referring to the first
element.

Element
This Blox will return the index of
the element of the array selected.
If the element does not exist, it
will return -1.
Index of “Apple” is 0

Index
This blox will return the element
corresponding to the selected
index number in the array.
Index 1 of List is “Grape”

Index value This blox will replace the element


at the selected index with a new
value. Can be use for both strings
and numbers.
List (before): Apple, Grape, Orange
List (after): Apple, Grape, 100
Element Count: 3
58

List
Elements and Indexing

Element
Index
Add a new element at the
selected index of the array.

List (before): Apple, Grape, Orange


List (after): Apple, Kiwi, Grape, Orange
Element Count: 4

Remove the last element


of an array

List (before): Apple, Grape, Orange


List (after): Apple, Grape
Element Count: 2

Index

Remove the element at


the selected index in the
array.
List (before): Apple, Grape, Orange
List (after): Apple, Orange
Element Count: 2

Index value
Increase/Decrease the
value of the element
at the selected index
of an array. Can be
used for both strings
List (before): Apple, Grape, 100
and numbers. *Best to
List (after): Apple, GrapeS, 89
only use on numbers
Element Count: 3
to avoid errors.
59

List
Contain function in List:
Check if the list contains
whatever you have typed in.
It will return 1 if it is true
and 0 if it is false.
List: Apple, Grape, Orange
Item: Orange (1), Banana (0), Kiwi (0)

List: 153, Banana, Fruits


Item: Orange (0), banana (0), 153 (1)

Reverse the elements in a List:

List (before): Apple, Grape, Orange, Kiwi


List (after): Kiwi, Orange, Grape, Apple
Element Count: 4

Extend List with another List:

Extend the list (array), with


elements from another list (array)

Example:

Before: After:
List_1: Grape, Kiwi List_1: Grape, Kiwi, Apple, Banana
Element Count: 2 Element Count: 4
List_2: Apple, Banana List_2: Apple, Banana
Element Count: 2 Element Count: 2
60

Functions
Functions are self-contained blocks of code that perform a specific task
or set of tasks and can be called or invoked whenever needed in a
program, keeping your code neat and tidy.

Do you know that most of the blox you have used before are functions?

Let’s take a Look at this blox:

This function is a big

= blox consisting of 2
smaller individual
bloxs.

Both perform the same tasks

Notice how your


program is now

= shorter? That’s
because functions
work like shortcuts!

In your previous Blox programming courses, you learned about signals,


which are a basic concept similar to functions. Just like functions, signals
perform specific tasks when broadcasted. They are an early way to
understand how functions work because they help you see how you can
create a block of code that does something specific, and then use it
whenever you need, just like a function in more advanced
programming.
61

Functions
Functions have two main steps:
1. You create or define the function by writing it.
2. You use the function by calling it whenever you need it.

Step 1: Function Definition

Function name Parameters


The name you give Inputs that the function can take
to the function to to perform its task. These are
identify and call it local variables

Function Body
The block of code
that defines what
the function does.

Return statement
The output the function
produces. Not all
functions need to have a
return value.
62

Functions
Step 2: Calling the Function

Calling a function means


instructing your program to
execute the block of code
inside the function, allowing
it to perform its task with
any inputs (parameters) and
possibly return a result.

counter is a local variable

Parameters, value of the variable


counter is passed as a parameter

Calling function
Calling function_1, with the value
of the counter as the parameter.
The return value is then stored in
the variable counter.
63

Functions
Parameters (or arguments):

parameter 1 parameter 2 Parameters in a function are


used to pass information or
values into the function. They
act like variables for the actual
values you want to use when
you call the function.
Parameters are local variables
that only exist and can be
accessed within that function.
However, not all functions need
to have parameters

Passing arguments:
parameters 1 parameters 2

parameters are like variables


for the actual values you want
parameter 1 is set to -1 to use when you call the
parameter 2 is set to 2 function.

example:

parameter 1 is set to 87
parameter 2 is set to -9

since,
value_1 is parameter 1
value_2 is parameter 2

value_1 = 87
value_2 = -9
64

Functions
Return value:
The return value of a function is the output or result that the function
produces after completing its task. When a function is called, it can
process the inputs (or parameters) given to it and then send back a
value to the part of the program that called it.

The return value can be


of any type, such as a
Boolean, strings,
numbers, or even more
return statement complex data structures
like lists.

To call a function with a return


value, use this call block to assign
the result to a variable. This way,
you can use the result of the
function later in your program.

number_1 = 13

Examples of a function without return value:

Functions without a return


statement perform their tasks
without sending any value
back; they simply carry out an
action. They are similar to
signals.
65

Variables
number_1 = -8

number_2 = 5

showVariable(ref number_1)

hideVariable(ref number_1)

variable: number_1
variable: number_2
variable: number_3

number_1 = 10
number_2 = 10
number_3 = 10

number_1 += 1
number_1 -= 1
number_1 /= 1
number_1 *= 1
66

List
[ "Orange", "Apple" ]

List = [ "Orange", "Apple" ]

List.append("Grape")

List.remove("Grape")

List.clear()

List.insert(2, "Grape")

List.pop()

List.pop(1)

List.index(0)

List[1]

List[1] = 10
67

List
List_1.extend(List_2)

List_1[1] += 23
List_1[1] -= 23
List_1[1] /= 23
List_1[1] *= 23

List_1.count("Apple")

List.reverse()

Sample Program
List = [ "Apple", "Orange" ]

when started:
while True:
showVariable(ref List)
if isKeyPressed("a"):
List.append(ask("What do you want to add?"))
if isKeyPressed("d"):
List.remove(ask("What do you want to remove?"))
if isKeyPressed("space"):
List.clear()
68

Functions
The def keyword is used to define a new function in Python. When you
write def function_name(): you are creating a function and giving it a
name.

A function is identified by
its name followed by
parentheses (), which may
also contain parameters,
that the function uses to
def function_1(value_1, value_2):
perform its task.

To be used in a
return (value)
function only

2 ways to call a
function

function_name(value 1, value 2)

Example: Get the bigger number between two numbers.

#Function Definition #Calling Function


def get_Max(value_1, value_2): when started:
if value_1 > value_2: bigger_number = get_Max(5, 8)
return value_1 say(bigger_number)
else:
return value_2
69

Events
noun [event]

a thing that happens or takes


place

Events
Signals
Clones
70
71

Events
Events block are used at the top of any codes. We use events blocks to
tell our actors what to do when something changed.

The start of every program

The program will run when


your actor is touched.
What do you want your actor
to do when it has been
touched?

The program will run when


your actor is clicked.
What do you want your actor
to do when it has been clicked?

The program will run the moment your mouse-pointer


touches the actor.
What do you want your actor to do at the moment when
the pointer enters the actor?

The program will run the moment your mouse-pointer


leaves the actor.
What do you want your actor to do at the moment when
the pointer leaves the actor?
72

Events
Events block are used at the top of any codes. We use events blocks to
tell our actors what to do when something changed.

What do you want to


do when your scene
switches to the one
you have selected?

Keys are keys on your


keyboard
What do you want your
actor to do when you
pressed certain keys?

Examples

When the left


arrow key is
pressed, the will
actor move
towards the left
When the right key
arrow is pressed,
the actor will move
towards the right
73

Signals
Signals allow actors to communicate with each other.

To allow actors to communicate


with each other, the first step is to
send a signal. Thus, these
"broadcast signal" blocks are
used.

Both blocks have the same function.


However, the "broadcast signal and wait" block refers to
waiting until the signal have finished broadcasting then
continue the program.

After a signal is sent, it has to be


received either by other actors or
by the actor who broadcast it.
So, what do you want your actor
to do when the signal after
receiving the signal?

Examples

Forever, check if the actor is touching the left


edge. If, it is touching the left edge, then
broadcast the signal - game_over. After the
signal is received, hide the actor and switch the
scene to Try Again.
74

Signals
Signals allow actors to communicate with each other.

Similar to the previous


bloxs, however, these
bloxs sends a data value
along with the signal.

The data value is


stored in this
variable blox

After a signal is sent, it has to be received either by other


actors or by the actor who broadcast it.
So, what do you want your actor to do when the signal after
receiving the signal?

Examples

When started, make the actor go to the


position: x=0, y=0, then display it on the
window, Next, broadcast the signal -
message1 with data value of 9.

After the signal is received with the


data, check if the value is equal to 10.
If true, say: “Data value is 10”
else say: “Data value is NOT 10”
75

Clone
A clone is a duplicate or a copy of an actor.

Whenever these blocks are


used:

You have to use this


block of code

This block of code tells your clones what actions to do. Without
this block, your clones would not be able to do perform
anything.
The block of code is used for clones only.

Examples

When started, make the actor go to the


center and reduce its size by 50%, then
show. After that, clone itself 2 times.

After it is cloned, make the clones go to a


random position and reduce its size to
40%, then show
76

Sample Program
This simple program demonstrates how to use events bloxs for when
you are creating clones and sending signals, enabling your program to
perform specific actions. Give it a try!

Program Explanation
Left-clicking the mouse creates a clone
that spawns at a random position. The
clone is programmed to move forward
continuously.

If the clone touches any


edges, it will be deleted
If the clone touches any
edges, it will be deleted
and it will be printed on
the screen
77

Events
when started:

when touched:

when clicked:

when keyPressed("space"):

when pointerOver:

when pointerOut:

when pointerOut:

In Python, the colon (:) signals the start of a code block associated with
a condition or function.
In when started:, the colon
when started : signals that the indented
setPosition(0, 0) lines should run when the
Indented
show() lines program starts, grouping
related instructions under
specific conditions.
78

Signals
broadcast("signal1")

broadcastAndWait("signal1")

when signalReceived("signal1"):

variable: event.data

broadcastData("message1", 10)

broadcastDataAndWait("message1", 10)

when dataReceived("message1"):

Clone
when cloned:
79

Control
noun [control]

determine the behaviour or


supervise the running of.

Delay
if-else Statements
Loops
Cloning
80
81

Delay
Delay: to make something happen at a later time.

The wait function is used to


delay the program.
Wait for a certain amount of
time before running other
codes

Wait until a condition is true, then


continue

if-else statement
A condition is a specific requirement or expression that evaluates to
either true or false, determining the flow of a program or decision-
making process.

The if statement allows you to make


a logical comparison between a value
by testing for a condition and
returning a result if that condition is
true

The if/else statement executes the if


block of code if a specified condition
is true. If the condition is false, the
else block of code will be executed.
82

Loops
In coding, a loop is a sequence of instructions that keeps repeating until
a certain condition is reached.

Continuously repeat the same action


over and over again. Repeat forever
without stopping.

This is a while loop, which


continuously repeat the same action
over and over again while the
condition remains true. It only stop
when the condition becomes false.

This is a for loop, which continuously repeat the same action for
a specific number of times.

Here’s how it works:


The phrase "Get each item of range 0 to 10 with step 1 as
value" means that the loop will start at 0 and continue up to a
maximum value that is less than 10, increasing by 1 each time. In
this case, the maximum value is 9.
The loop will run 10 times, covering the values 0 through 9.
The current number is stored in a variable named "value".
Any actions placed inside the loop will be executed for each
number within this range.
83

Cloning
Cloning refers to duplicating or creating a copy of something

These blocks of code are


used to create 1 or more
clones.

Both blocks serves the same


purpose. Actor Clone
However, the "create clone of
something and wait" block
refers to waiting until the clone is
created before continuing the
program.

Actor
A variable that stores the
clone count
number of clones of the
=5
actor

Verify if the actor and its created clones are


actually clones or not. Return true or false
value.

Delete one clone at a time

Delete all the clones of an


actor.

5 clones
created:
A list of all the clones created from an
actor
84

Cloning
The index of a clone of an actor.
clone id

These 2 bloxs are used to get


the information of the clone.

Examples

Infomation of the
clone
85

Delay
wait(1)

while not (condition):

example:
while not (counter == 3):
pass

if-else statement
if (condition):
actions

if (condition):
actions
else:
actions

example:
if (counter == 3):
show()
else:
hide()
86

Loops
while True:

while (condition):
actions

while counter <= 5:


say(counter)

for value in range(0, 10, 1):


actions

for value in range(0, 10, 1):


say(value)
wait(1)
87

Cloning
variable: isClone

list variable: clones

variable: cloneCount

createClone(UFO)

createCloneAndWait(UFO)

deleteClone()

deleteAllClonesOf(UFO)

variable: cloneId

getClone(1)

getCloneOf(1, UFO)
88

Sample Program

chosen_clone = randrange(0, 10, 1)

when started:
show()
size = 30
setScene(White)
while True:
showVariable(ref chosen_clone)
createClone(self)
wait(2)

when cloned:
size = 15
goTo(Position.random())
while True:
if cloneId == chosen_clone:
say(concat("Chosen: ", cloneId))
wait(1)
broadcast("signal1")
deleteClone()
else:
say(cloneId)

when signalReceived("signal1"):
chosen_clone = randrange(chosen_clone + 3, chosen_clone + 10, 1)
89

Operators
noun [operator]

Math operators define the basic


operations that act on numbers

Arithmetic Operators
Boolean Values
Comparison Operators
Logical Operators
String
Assignment Statements
Other Functions
90
91

Arithmetic Operators
An arithmetic operation is a basic action like addition, subtraction,
multiplication, or division.

Addition Subtraction

Add 2 numbers Minus one number from the


together other

Multiplication Division

Multiple one number with the Divide one number from the other
other
Modulus
The modulus is the remainder after dividing
one number by another. 10 3 = 3,
remainder 1. The answer is 1.

Boolean Values
A Boolean value represents a truth value: whether it is TRUE or FALSE.

The statement The statement is


is correct incorrect. Opposite of
true
No values stored in the
variable yet
92

Comparison Operators
Comparison operations compare two values and return a Boolean
result, either True or False.

First number First number is


is more than more than or
the second equals to the
number second number

First number First number is


is less than less than or
the second equals to the
number second number

First number First number is


is equals to Not equal to the
the second second number
number

Logical Operators
Logical operators are generally used for combining two or more
relational statements. They return Boolean values, either True or False

Logical Logical Logical


AND operator OR operator NOT operator

returns true only if returns true if either oppose its original


both statements statement are true, truth. True becomes
are true, else else returns false false. False becomes
return false true
93

String
A string is a series of characters.
Example of strings: "Apple" "Orange" "Red" "Hello!" "Xyz123"
*Sometimes numbers itself can also be considered strings

Transform every letter


of the string to Capital
letters

Transform every letter


of the string to small
letters

Count the number of


characters in a string

Concatenation: to link
something together in a
series or chain. Link 2
strings or values together
94

Assignment Statements
An assignment in Python is when you store the result of an expression
in a variable using the equals sign (=)

Variable = Expression
assignment

Types of assignment in Python:


Simple Assignment (=) Multiply and Assign (*=)
Add and Assign (+=) Divide Assignment (/=)
Subtract and Assign (-=) Modulus and Assign (%=)

How does += operator works?


This example shows
that the += operator
variable: apples = 10 first takes the
apples = apples + 2 current value of
apples += 2 apples = 10 + 2 apples (10), adds 2
apples = 12 to it, and then
Answer: apples = 12. updates apples to
the new value (12).
How does *= operator works?
This example shows
that the *= operator
variable: apples = 3 first takes the
apples = apples x 6 current value of
apples *= 6 apples = 3 x 6 apples (3) multiply
apples = 18 by 6, and then
Answer: apples = 18. updates apples to
the new value (18).
Try yourself:
variable: apples = 10
What is the value of apples?
apples /= 5
95

Assignment Statements
An expression in Python is a combination of values, variables,
operators, and function calls that, when evaluated, produces a single
value.

Left-hand side (LHS) Right-hand side (RHS)


Variable = Expression
assignment

Examples of Expressions:
variables: total_fruits = 0, apples = 10, oranges = 8, kiwi = 5

Statements Explanation

apples = 2 Expression can be a single value

This is incorrect. LHS of an


5 = kiwi assignment statement must be a
variable that can store a value.

apples = 3 + 2 An expression can include other


apples = kiwi variables, meaning you can use
apples = oranges - 1 the values stored in variables to
total = apples + oranges + kiwi create expressions.

These statements are incorrect


kiwi + 2 = oranges - 1 because the assignment must
apples + 3 = 13 have a variable on the LHS of the
total + kiwi = oranges + apples =. Here, both sides are
expressions, which is not allowed.

Try yourself: which statements are correct?

apples = total - 3 apples + kiwi = kiwi + apples


apples + 1 = kiwi - 1 apples - 2 = oranges
oranges = apples*2 + 3 total = oranges + apples + 5
96

Other Functions
Range with step Function:
This function generates a
sequence of numbers starting
from 0 to 9, and increases by
1 with each step. It is used in
a for loop.
Pick Random with Step
Function: This function
randomly selects a number
between 0 and 10, increasing
by 1 with each step.

Math Operation Function:


This function allows you to perform a
specific operation (like finding the maximum,
minimum, sum, power, etc.) of the two
numbers provided.

example:

Round to Digits Function:


This function rounds a given
In this example, the number (the first parameter) to
number 10.327 is a specified number of decimal
being rounded to 2 places (the second parameter).
decimal places, so the
result would be 10.33.
97

Other Functions
Y X
Inverse Tangent Function:
This function finds the angle in
degrees between the positive x-
axis and a point.
y - axis
point(y,x) = point(5,3)
*good to know (not tested).
Formula:

Angle
x - axis

This blox applies a selected mathematical


operation to a given number. We will only go
through certain functions which are important.

Absolute Value Function:


This function turns negative value to
positive value. - 32 becomes 32

Random Number Function:


This function picks a random
number between 0 and 42.

Square Root Function:


This function returns the square
root of a number. Square root of 64
is 8.
Rounding Off Function:
This function round a number off to
the nearest whole number. 54.48
becomes 54.
98

Other Functions
Trigonometry is the study of the relationships between the angles
and sides of right-angled triangles, Trigonometry uses functions like
sine (sin), cosine (cos), and tangent (tan) to give you a number that
tells you something about an angle. These numbers are usually between
-1 and 1.

=1 =0 =1

Sine wave Cosine wave Tangent


Graph Graph Graph

This blox applies a


Print Function
selected data type
Prints a text to the
conversion, which
screen
means changing
from one type to
another, such as
numbers to strings.
*good to know (not Comment Function
tested) Comment
something on your
code
99

Arithmetic Operators

value + value value * value value % value

value - value value / value

Boolean Values

True False None

Comparison Operators

value < value value > value value == value

value <= value value >= value value != value


100

Logical Operators
condition and condition

condition or condition

not condition

Sample Program

when started:
setPosition(0, 0)
while True:
show()
if isKeyPressed("space") and not touching(Edge.top):
y += 10
while not not isKeyPressed("space"):
pass
101

String
len("hello")

"HeLLo".lower()

"hello".upper()

concat("Hello ", "World")

In Python, a string is identified by being enclosed in double quotes (“”)

Hello + “” = “Hello” = “Hello”

Value String String


Value

In text-based programming, it is important to put strings inside double


quotes (“”). This helps the computer understand that the text is meant to
be a string, which is just a series of letters or characters. If you don't use
the quotes, the computer might think the text is a variable name or a
command, and this can cause errors.

This is correct, a number value does


variable = 123 not need to be enclosed in double
quotes

This is wrong, a series of characters


variable = Hello need to be enclosed in double
quotes, because it is a string

variable = “Hello” This is correct, this is a string


102

Other Functions
range(0, 10, 1)

randrange(0, 10, 1)

min(1, 2)
max(1, 2)
sum(1, 2)
pow(1, 2)
zip(1, 2)
divmod(1, 2)

Math.atan2(5, 3)
Math.roundToDigits(5, 3)

print("Hello!")

#"This is a comment"
103

Other Functions
Math.abs(45)
Math.random(45)
Math.round(45)
Math.floor(45)
Math.ceil(45)
Math.sqrt(45)
Math.sin(45)
Math.cos(45)
Math.tan(45)
Math.asin(45)
Math.acos(45)
Math.atan(45)
Math.ln(45)
Math.log(45)
Math.exp(45)
Math.pow10(45)

str(1) bin(1)
repr(1) oct(1)
number(1) hex(1)
list(1) chr(1)
bool(1) ord(1)
abs(1) reversed(1)
all(1) sorted(1)
any(1)
104

Sample Program

Lucky_Number = 0
Your_Number = 0
Score = 0

when started:
show()
while True:
showVariable(ref Score)
Lucky_Number = randrange(1, 11, 1)
while not (Your_Number >= 1 and Your_Number <= 10):
Your_Number = ask("Pick a number from 1 to 10:")
say("Choose a number between 1-10")
#"Check if 'your number' is equals to the 'lucky number'"
if Your_Number == Lucky_Number:
say("You Win!")
Score += 1
else:
say("You Lose!")
#"reset 'my number'"
Your_Number = 0
105

Physics
noun [physics]

the physical properties and


phenomena of something.

Force & Gravity


Friction
Speed
Collision
106
107

Force & Gravity


Force is a push or pull on an object that can cause it to change its
speed, direction, or shape.

An example of force is kicking a soccer ball: When you


kick a soccer ball, the force from your foot makes the
ball move across the field.

Force can also be applied to move objects


from one point to another

Amount
of force

Apply certain amount of force


Direction
to the actor, in a certain
direction. The greater the
force applied, the further the
object moves from its original
position.

When an object is static, it is at rest and does not move, regardless of


forces acting on it.

This is a variable

When static is off, the object


can move freely, but when
static is on, the object remains
fixed in place and does not
move.

*To explore the physics engine in your code, you must set static to off,
allowing the object to move and interact with forces.
108

Force & Gravity


Gravity is a force that pulls objects toward each other, with Earth's
gravity pulling everything toward its center.

Isaac Newton, in the 17th century,


discovered gravity after observing an
apple fall from a tree, which made him
wonder why objects fall down instead of
floating away. He realized that a force
pulls objects toward Earth, which he
named gravity. This discovery helped
explain how planets move and became a
foundation for modern physics.

allows you to control the allows you to control the


strength of gravity in the strength of gravity in the
vertical direction. Pulling vertical direction. Pulling
the actor down. the actor up.

allows you to control the allows you to control the


strength of gravity in the strength of gravity in the
horizontal direction. horizontal direction.
Pulling the actor to the Pulling the actor to the
right. left.
109

Friction
Friction is the force that opposes the motion of an object when it
comes into contact with another surface.

Imagine pushing a block across


Force a table, the roughness of both
Friction the block's bottom surface and
the table creates friction.

This frictional force opposes the direction of the block's movement. As a


result, the block's speed decreases as it moves, and eventually, the
block comes to a stop. The amount of friction depends on the materials
of the block and the table. As the surface roughness increases, the
friction increases.

In this context, damping is the effect of friction gradually slowing down


and eventually stopping the movement of the object.

This is a variable

The higher the damping value,


the faster the object's motion
slows down and comes to a
stop due to increased
resistance. Value from 0 to 1.

Increase or decrease the


damping value

damping = 0.5 damping = 0.2 damping = 0.1


Force

Distance
110

Speed
Speed is the measure of how fast an object is moving, calculated as the
distance traveled divided by the time it takes.

This is a variable

Velocity is the speed of an object in a specific direction, which describes


how fast something is moving and where it is going.

This example shows that


Backward Forward velocity depends on both
the speed and direction
of the car, to move
forward or backward.

Speed

Direction
(speed angle) How fast do you want your
object/actor to move and in
what direction do you want
your actor to move to?

These are variables. velocity of


your object along the x and y-
axis

The speed angle indicates the direction in which


the object is moving.

Angular velocity measures how quickly an object, like a ball, spins or


rotates around a fix point or axis.

How fast do you want


your object to rotate.
111

Collision
Collision is an occurrence where two or more objects come into contact
with each other, often resulting in a change in their motion or shape.

Collision: ON

If collision is turned off,


Collision: OFF
objects will pass through
each other as well as
through the walls.

Enable the selected wall to collide


with the actor/objects.

Disable the selected wall, allowing


the actor/object to pass through it.

This blox controls whether the


actor can detect collisions
between the walls or with other
actors. If it is turned off, it is
unable to detect any collisions.

These are variable that returns a


boolean value.
112

Force & Gravity


variable: physics.isStatic

physics.isStatic = False
physics.isStatic = True

physics.applyForce(10, 0)

physics.horizontalGravity = 0

physics.verticalGravity = 0
113

Friction
variable: physics.damping

physics.damping = 0.1

physics.damping += 0.1
physics.damping -= 0.1
physics.damping /= 0.1
physics.damping *= 0.1

Speed
variable: physics.speed
variable: physics.speedAngle

variable: physics.velocityX
variable: physics.velocityY

physics.setVelocity(10, 0)

physics.setAngularVelocity(10)
114

Collision
variable: physics.isCollides
variable: physics.isSensor

physics.isCollides = True
physics.isCollides = False

physics.isSensor = True
physics.isSensor = False

physics.enableWall("top")

physics.disableWall("top")

Drop down ("any")


menu of ("top")
enable and ("bottom")
disable wall ("left")
("right")
("vertical")
("horizontal")
115

Pe n
verb [pen]

write or compose.

Drawing
Pen Size
Pen Colour
Pen Shape
116
117

Drawing
The pen tool in logiscool replicates the action of a human when using a
pen

Start drawing

Stop drawing

When the costume of


an actor is stamped, it
becomes part of the
background.

Remove or Erase the


drawings and stamps

Examples
118

Pen Size
Pen size refers to how thick or thin your pen ink is.

Increase the pen size certain


value

Decrease your pen size by


certain value

Pen Colour
Set a pen colour either from using a hue value
or choosing from the colour palette.

Set the pen shade


119

Pen Shape
Pen Shape refers to the shape of your pen tip.

In logiscool, pen tool, there are 3


shapes available: circle, triangle and
square.

By default, the circle shape is used .

These are
variables

Examples
120

It's Drawing Time!!


Draw your favorite characters, animals, food, superheros, and
more...
121

Drawing
pen.down()

pen.up()

clearPenTrails()

stampCostume()

Pen Size
variable: pen.size

pen.size = 1

pen.size += 1
pen.size -= 1
pen.size /= 1
pen.size *= 1
122

Pen Colour
variable: pen.shade
variable: pen.hue

pen.setCssColor("#0000FF")

pen.hue = 50

pen.hue += 10

pen.shade = 50

pen.shade += 10

Pen Shape
variable: pen.shape

pen.shape = 0
pen.shape = 3
pen.shape = 4
My Notes
My Notes
My Notes
My Notes
My Notes
My Notes
My Notes
My Notes
My Notes
My Notes

You might also like