some hints about programming in graphics
Theme: make your coordinates flexible when possible
Boxes1.py | Boxes2.py | Boxes3.py |
---|---|---|
from graphics import * def main(): win = GraphWin("boxes", 500, 600) box1 = Rectangle (Point(0,50), Point(50, 100)) box1.setFill("green") box1.draw(win) box2 = Rectangle (Point(0,100), Point(50, 150)) box2.setFill("red") box2.draw(win) box3 = Rectangle (Point(0,150), Point(50, 200)) box3.setFill("blue") box3.draw(win) win.getMouse() win.close() main() |
from graphics import * def main(): win = GraphWin("boxes", 500, 600) box_x = 100 box_y = 25 box1 = Rectangle (Point(box_x,box_y), Point(box_x + 50, box_y+50)) box1.setFill("green") box1.draw(win) box2 = Rectangle (Point(box_x,box_y+50), Point(box_x + 50, box_y+100)) box2.setFill("red") box2.draw(win) box3 = Rectangle (Point(box_x,box_y+100), Point(box_x + 50, box_y + 150)) box3.setFill("blue") box3.draw(win) win.getMouse() win.close() main() |
from graphics import * def main(): win = GraphWin("boxes", 500, 600) box_x = 100 box_y = 25 width = 200 height = 50 box1 = Rectangle (Point(box_x,box_y), Point(box_x + width, box_y + height)) box1.setFill("green") box1.draw(win) box2 = Rectangle (Point(box_x,box_y+ height), Point(box_x + width, box_y+ 2 * height)) box2.setFill("red") box2.draw(win) box3 = Rectangle (Point(box_x,box_y+ 2 * height), Point(box_x + width, box_y + 3 * height)) box3.setFill("blue") box3.draw(win) win.getMouse() win.close() main() |