CODELAB ๐Ÿš€

Starting Python...
โณ Loading...
๐ŸŽฏ

CODELAB ๐Ÿš€  Cheat Sheet

Creating Objects
create_object()
Makes a new object. Store it in a variable: ball = create_object()
create_complex()
Makes a multi-part object. Add shapes to it with .add_shape()
Position & Size
obj.set_position(x, y)
Move to a spot. 0,0 = top-left. Center = 400, 250. Screen โ‰ˆ 800 ร— 500.
obj.set_size(n)
10 = tiny ยท 30 = medium ยท 60 = big
obj.set_rotation(angle)
Rotate to an angle in radians. 0 = upright. math.pi = half-turn.
obj.set_rot_speed(speed)
Spin forever. 0.05 = slow ยท 0.2 = fast ยท Negative = other way.
Color & Look
obj.set_color("name")
Set color by name. See the color list below!
obj.set_shape("name")
Change the shape. See the shape list below!
obj.set_glow(True)
Makes it glow! Looks amazing on a dark background.
obj.set_trail_length(n)
Comet tail. 0 = none ยท 20 = medium ยท 50 = long
obj.opacity = 0.5
1 = solid ยท 0.5 = see-through ยท 0 = invisible
obj.label = "hi"
Draws text in the center of the object.
Movement & Physics
obj.set_velocity(vx, vy)
vx = left/right ยท vy = up/down ยท Negative vy goes UP
obj.apply_impulse(ix, iy)
A one-time shove. Adds to velocity instantly.
obj.apply_force(fx, fy)
A steady push every frame. Like a rocket or wind.
obj.set_bounciness(n)
1.0 = perfect ยท 0.5 = loses half ยท 0 = dead stop
obj.set_collision(True/False)
True = bounces off walls ยท False = flies through like a ghost
obj.destroy()
Removes the object from the screen forever.
Readable: obj.x ยท obj.y ยท obj.vx ยท obj.vy โ€” read these with print() to see position & speed!
Complex Objects (multi-part)
obj.add_shape("shape", size, "color", offset_x, offset_y)
Adds a part. offset_x/y = distance from center. -y = up ยท +y = down ยท -x = left ยท +x = right
robot = create_complex() robot.add_shape("square", 40, "blue", 0, 0) # body robot.add_shape("circle", 20, "cyan", 0, -48) # head robot.add_shape("circle", 12, "gray", -22, 42) # left foot robot.add_shape("circle", 12, "gray", 22, 42) # right foot
World Functions
set_gravity(n)
Positive = fall ยท Negative = float ยท 0 = space! Try 1 for normal.
set_background("color")
"black" looks amazing with glow + trails!
random_color()
Returns a surprise color every time. Great in loops!
random_number(a, b)
Random number between a and b. Example: random_number(0, 800)
screen_width()   screen_height()
Canvas width and height in pixels.
Timing
await wait(seconds)
Pauses your code for that many seconds. Canvas keeps running! Must write await before wait().
ball1 = create_object() ball1.set_position(200, 300) print("First ball!") await wait(2) # pause 2 seconds ball2 = create_object() ball2.set_position(500, 300) print("Second ball!")
Math
math.pi
ฯ€ = 3.14159... One full circle = 2 ร— math.pi
math.cos(angle)
X-direction of an angle. Used to place things in a circle!
math.sin(angle)
Y-direction of an angle. Works with cos to make perfect rings.
Circle pattern:   angle = (2 * math.pi / num) * i  ยท  x = 400 + radius * math.cos(angle)  ยท  y = 300 + radius * math.sin(angle)
Colors
"red"
"green"
"blue"
"white"
"black"
"yellow"
"cyan"
"magenta"
"purple"
"pink"
"gold"
"orange"
"teal"
"lime"
"sky"
Shapes
โฌค
"circle"
โ– 
"square"
โ–ฒ
"triangle"
โ˜…
"star"
โ—†
"diamond"
โ™ฅ
"heart"
โ—ฏ
"ring"