Your First Sketch
Learn the basics: set up a canvas, draw shapes, and understand how setup() and draw() work.
Every Glitchlab program starts with two special functions: setup() and draw(). The setup function runs once at the very beginning — it's where you set the size of your canvas. The draw function runs over and over, about 60 times per second, which is what makes animation possible. Let's start simple: set up a canvas and paint it sky blue.
Try it!Try changing "skyblue" to "hotpink" or "midnightblue" — what happens?
Now let's add some shapes! Use rect() to draw a rectangle and circle() to draw a circle. Each shape needs a position (x, y) and a size. For rectangles, you give the top-left corner, width, and height. For circles, you give the center and radius.
Try it!Try moving the sun by changing its x and y numbers. Can you make it bigger?
Let's build a little scene! You can draw as many shapes as you want. They stack on top of each other in the order you draw them — shapes drawn later appear on top. Use triangle() for a roof and text() to add words.
What to try next
- Add a window to the house (hint: draw a small blue rectangle on the house)
- Change the colors to make a nighttime scene — try a dark blue background and a white moon
- Add more houses or trees to build a whole neighborhood
- Try drawing clouds using a few overlapping white circles