Quickstart Examples

Some examples to quickly begin creating amazing things with pyDraw!

Example #1: Drawing

We can draw a simple emoji onto the screen with Ovals. We will mimic: "😯" with a gray background.

from pydraw import *

screen = Screen(800, 600)
screen.color(Color('gray'))

face = Oval(screen, 100, 0, 600, 600, Color('yellow'))
face.wedges(40)

eye1 = Oval(screen, 200, 200, 85.71, 100)
eye2 = Oval(screen, 500, 200, 85.71, 100)

eyebrow1 = Rectangle(screen, 157.14, 150, 100, 5, rotation=-16)
eyebrow2 = Rectangle(screen, 517.85, 150, 100, 5, rotation=16)

mouth = Oval(screen, 350, 400, 85.71, face.height() / 109)

screen.stop()
Example #1 Output

Note that we calculated those numbers using these formulas:

Example #2: Animation

We can animate our face now by adding an animation loop and having our eyes blink every 3 seconds (note that we've now switched to the proportions-based calculations):

Example #2 Output

Notice how we replaced:

with this in order to create an animation loop:

Example #3: Input

Now we will move our emoji's mouth based on the mouse's position:

Example #3 Output

Notice how a new method was added:

And below that method we tell the screen to listen for input:

Last updated

Was this helpful?