# Graphics-CT #1
# Draw a picture on a piece of paper showing what this draws when it runs.
import basic_graphics
def draw(canvas, width, height):
# assume (width,height) == (300,300)
canvas.create_rectangle(10, 10, width-10, height-10, fill=None)
(cx, cy, d) = (width*2/3, height/3, width/10)
L = [ ]
for i in range(-2,3):
(dx, dy, r) = (cx+d*i, cy+abs(d*i), d/2)
canvas.create_line(dx, dy, cx, cy+100)
canvas.create_oval(dx-r, dy-r, dx+r, dy+r, fill="gray")
L.append((dx, 30+10*i**2))
canvas.create_polygon(L, fill="gray")
(x0, y0, x1, y1) = (20, 20, 100, 200)
canvas.create_rectangle(x0, y0, x1, y1, fill="gray")
canvas.create_oval(x0, y0, x1, y1, fill="white")
textY = height-60
canvas.create_line(20, textY, width-20, textY)
canvas.create_text(width/2, textY, text="CT1",
font="Arial 16", anchor="s")
canvas.create_text(width/2, textY, text="(What will this draw?)",
font="Arial 16", anchor="n")
basic_graphics.run()
# Graphics-CT #2
# Draw a picture on a piece of paper showing what this draws when it runs.
import basic_graphics
def draw(canvas, width, height):
(x1,y1) = (200,0)
for x in range(50,500,200):
for y in range(x, 400, 150):
canvas.create_line(x,y,x1,y1)
canvas.create_text(x,y,text=str((x,y)))
(x1,y1) = (x,y)
basic_graphics.run()