Jed Rembold & Fred Agbo
February 26, 2024
When the function to the right is run, what does the screen look like just after 1 second has passed?
def rev_q():
def step():
rect.move(1, 1)
def once():
rect.set_filled(True)
gw = GWindow(200, 200)
rect = GRect(0, 0, 25, 25)
gw.add(rect)
gw.set_interval(step, 20)
gw.set_timeout(once, 1000)
GArc class represents an arc formed
by taking a section of the perimeter of an oval.GArc class is a
GFillableObject, and so you can call
.set_filled() on a
GArc objectdef filled_arc():
gw = GWindow(400, 400)
arc = GArc(50, 50,
350, 350,
90, 135)
arc.set_color("orange")
arc.set_filled(True)
gw.add(arc)

GPolygon classGPolygons are
GFillableObjects, so they can be filledGPolygon function creates an
empty polygon, to which you then can add vertexes.add_vertex(x,y) on the
GPolygon object
x and y
measured relative to the reference point.add_vertex(x,y) adds another new vertex
relative to the reference point.add_edge(dx,dy) adds a new vertex
relative to the preceding vertex.add_polar_edge(r, theta) adds a new
vertex relative to the previous using polar coordinatesdef triangle_by_vertex():
def create_triangle(b, h):
tri = GPolygon()
tri.add_vertex(-b / 2, h / 2)
tri.add_vertex(b / 2, h / 2)
tri.add_vertex(0, -h / 2)
return tri
gw = GWindow(500, 500)
triangle = create_triangle(200, 200)
triangle.set_filled(True)
triangle.set_color("red")
gw.add(triangle, 250, 250)
def triangle_by_polar_edge():
def create_eq_triangle(side):
tri = GPolygon()
tri.add_vertex(0, 0)
for i in range(0, 360, 120):
tri.add_polar_edge(side, i)
return tri
gw = GWindow(500, 500)
triangle = create_eq_triangle(100)
triangle.set_filled(True)
triangle.set_color("green")
gw.add(triangle, 250, 250)
GCompound class makes it possible to
combine several graphical objects so that the entire structure behaves
as a single objectGWindow and
GObject
GCompound,
you place them relative to the reference pointGCompound to a canvas,
you set the location of the reference pointdef my_axe():
def create_axe():
axe = GCompound()
shaft = GRect(-15, 0, 30, 300)
shaft.set_filled(True)
shaft.set_color("brown")
axe.add(shaft)
blade = GPolygon()
blade.add_vertex(0, 0)
blade.add_vertex(200, -50)
blade.add_vertex(200, 50)
blade.set_filled(True)
blade.set_color("gray")
axe.add(blade, -80, 50)
return axe
gw = GWindow(500, 500)
axe = create_axe()
gw.add(axe, 250, 100)