Lab 2: Draw a Picture

Your assignment: Draw a picture.

The goal:

  • Practice looking up API documentation - useful for using any code library

  • Practice calling functions - a basic building block of all computer programs

  • Practice working with RGB colors - used in graphics, web design, and even LED lighting

  • Practice commenting and formatting code properly - required to make code maintainable

  • Practice working with graphics coordinates - also used in document layout and web design

Requirements

To get full credit:

  • Use the same project and repository that you used for Lab 01. If you forked your repository from mine, you should already have a folder for lab 2. Use that folder, and the lab_02.py file inside. Otherwise create one.

  • Use several different colors.

  • Make a coherent picture. Don’t make abstract art with random shapes, because that doesn’t require a full application of what we’ve learned to a real use-case.

  • Use multiple types of graphic functions. Include circles, ellipses, rectangles, lines, polygons and more in your drawing. It is certainly possible to make great art with just squares, but the point of the lab is to practice using multiple functions.

  • Use a single blank line in your code to break up logical sections. For example, when drawing a tree, put a blank line ahead of, and after. See the example code below.

  • Use comments effectively. For example, when drawing a tree, put a comment at the start of those drawing commands that says # Draw a tree. Remember to put one space after the # sign.

  • Put spaces after commas for proper “style.”

  • Use PyCharm to inspect your code for warnings. Fix warnings that you encounter.

Tips

To select new colors use: https://www.google.com/search?q=color+picker

Copy the values for Red, Green, and Blue from the color picker. Do not worry about colors for hue, saturation, or brilliance.

Keep in mind the order of code. Shapes drawn first will be at the “back.” Shapes drawn later will be drawn on top of the other shapes.

Also, remember you can look up the available commands, called the “API” at: https://arcade.academy

Example Lab

../../_images/final_program.png
 1"""
 2This is a sample program to show how to draw using the Python programming
 3language and the Arcade library.
 4"""
 5
 6# Import the "arcade" library
 7import arcade
 8
 9# Open up a window.
10# From the "arcade" library, use a function called "open_window"
11# Set the window title to "Drawing Example"
12# Set the and dimensions (width and height)
13arcade.open_window(800, 600, "Drawing Example")
14
15# Set the background color
16arcade.set_background_color(arcade.color.AIR_SUPERIORITY_BLUE)
17
18# Get ready to draw
19arcade.start_render()
20
21# Draw the grass
22arcade.draw_lrtb_rectangle_filled(0, 800, 200, 0, arcade.color.BITTER_LIME)
23
24# --- Draw the barn ---
25
26# Barn cement base
27arcade.draw_lrtb_rectangle_filled(30, 350, 210, 170, arcade.color.BISQUE)
28
29# Bottom half
30arcade.draw_lrtb_rectangle_filled(30, 350, 350, 210, arcade.color.BROWN)
31
32# Left-bottom window
33arcade.draw_rectangle_filled(70, 260, 30, 40, arcade.color.BONE)
34arcade.draw_rectangle_filled(70, 260, 20, 30, arcade.color.BLACK)
35
36# Right-bottom window
37arcade.draw_rectangle_filled(310, 260, 30, 40, arcade.color.BONE)
38arcade.draw_rectangle_filled(310, 260, 20, 30, arcade.color.BLACK)
39
40# Barn door
41arcade.draw_rectangle_filled(190, 230, 100, 100, arcade.color.BLACK_BEAN)
42
43# Rail above the door
44arcade.draw_rectangle_filled(190, 280, 180, 5, arcade.color.BONE)
45
46# Draw second level of barn
47arcade.draw_polygon_filled([[20, 350],
48                            [100, 470],
49                            [280, 470],
50                            [360, 340]],
51                            arcade.color.BROWN)
52
53# Draw loft of barn
54arcade.draw_triangle_filled(100, 470, 280, 470, 190, 500, arcade.color.BROWN)
55
56# Left-top window
57arcade.draw_rectangle_filled(130, 440, 30, 40, arcade.color.BONE)
58arcade.draw_rectangle_filled(130, 440, 20, 30, arcade.color.BLACK)
59
60# Right-top window
61arcade.draw_rectangle_filled(250, 440, 30, 40, arcade.color.BONE)
62arcade.draw_rectangle_filled(250, 440, 20, 30, arcade.color.BLACK)
63
64# Draw 2nd level door
65arcade.draw_rectangle_outline(190, 310, 30, 60, arcade.color.BONE, 5)
66
67# --- Draw the tractor ---
68
69# Draw the engine
70arcade.draw_rectangle_filled(600, 120, 140, 70, arcade.color.GRAY)
71arcade.draw_rectangle_filled(590, 105, 90, 40, arcade.color.BLACK)
72
73# Draw the smoke stack
74arcade.draw_rectangle_filled(580, 175, 10, 40, arcade.color.BLACK)
75
76# Back wheel
77arcade.draw_circle_filled(490, 110, 50, arcade.color.BLACK)
78arcade.draw_circle_filled(490, 110, 45, arcade.color.BLACK_OLIVE)
79arcade.draw_circle_filled(490, 110, 35, arcade.color.OLD_LACE)
80arcade.draw_circle_filled(490, 110, 10, arcade.color.RED)
81
82# Front wheel
83arcade.draw_circle_filled(650, 90, 30, arcade.color.BLACK)
84arcade.draw_circle_filled(650, 90, 25, arcade.color.BLACK_OLIVE)
85arcade.draw_circle_filled(650, 90, 18, arcade.color.OLD_LACE)
86arcade.draw_circle_filled(650, 90, 5, arcade.color.RED)
87
88# --- Finish drawing ---
89arcade.finish_render()
90
91# Keep the window up until someone closes it.
92arcade.run()

Other Examples

Here are some images from prior years:


Turn In

Refer back to Quick Reference for a reminder on how to turn in this lab. You need to do a:

  • git add *

  • git commit -m "Lab 02"

  • git push

  • Find the lab on github.com

  • Copy the URL

  • Go to the class website and turn in the lab.

Remember, if there are errors on the lab that you want to correct and get full credit for, you can. Once corrected, go through all the steps above. You must resubmit the lab to the class website (not just upload to git) otherwise I don’t get notified to look at the lab again. You have 7 days (to the hour and minute) to submit the lab again.