Now that a very basic overview of Python is out of the way, let's get back to some drawing!

I'll return to the code that we started earlier, our rectangle on a 300 x 200 point canvas:

Download: file
print("Hello world!")
size(300, 200)
rect(10, 10, 200, 100)

Let's continue where this left off. It could be nice to add a little bit of color. Before issuing the command to draw a rectangle, first set the fill color.

Download: file
print("Hello world!")
size(300, 200)
fill(1, 0.5, 0)
rect(10, 10, 200, 100)

Run it and see what happens — the rectangle is now orange. The fill color took three arguments, in this case the values for red, green and blue. Setting red to 1 means red is 100%, green is 0.5 which really means 50%, and blue is at 0%. Go ahead and try some more color values, always keeping between 0 and 1.

There's still more that fill can do, as an example, adding a fourth value also sets the transparency of the color:

Download: file
print("Hello world!")
size(300, 200)
fill(1, 0.5, 0, 0.5)
rect(10, 10, 200, 100)

It might be hard to tell that the rectangle is 50% transparent, until you draw another rectangle that overlaps this one:

Download: file
print("Hello world!")
size(300, 200)
fill(1, 0.5, 0, 0.5) # Orange, with 50% transparency
rect(10, 10, 200, 100) # The first rectangle
rect(30, 30, 200, 100) # A second rectangle

I'm also introducing another helpful Python concept here, leave yourself some comments! Anything written in a line after the # will be ignored by Python and is only there to help you understand what your code is doing. From here on out, feel free to leave notes to yourself right there in your code.

If you want the color of the second rectangle to be different, just be sure to set the color before drawing the rectangle

Download: file
print("Hello world!")
size(300, 200)
fill(1, 0.5, 0, 0.5) # Orange, with 50% transparency
rect(10, 10, 200, 100) # The first rectangle
fill(0, 0, 1, 0.5) # Blue, with 50% transparency
rect(30, 30, 200, 100) # A second rectangle

As a refresher, the rect needed four values from us, two that specify where the lower left corner of the rectangle starts, and two more for the width and height of the rectangle.

Try changing rect to oval and run the script again:

Download: file
print("Hello world!")
size(300, 200)
fill(1, 0.5, 0, 0.5)
oval(10, 10, 200, 100)
fill(0, 0, 1, 0.5)
oval(30, 30, 200, 100)

Nice!

Instead of going through all of DrawBot's shapes and color options here in this guide, I'd like for you to be familiar with DrawBot's own documentation. Continue experimenting with the shapes, and fill and stroke settings that you find in DrawBot's documentation and Quick Reference Guide.

This guide was first published on Dec 14, 2018. It was last updated on Dec 14, 2018.
This page (Basic Shapes and Colors) was last updated on Oct 24, 2020.