from Graphics import * myCanvas = Window() myCanvas.close() myCanvas = Window("My Masterpiece", 200, 300) myCanvas.setBackground(Color("white")) p = Point(100, 50) d = Dot(100, 50) d.draw(myCanvas) d.getX() d.getY() L = Line(Point(0,0), Point(100,200)) L.draw(myCanvas) start = L.getP1() start.getX() end = L.getP2() end.getY() for n in range(0, 200, 5): L=Line(Point(n,25),Point(100,100)) L.draw(myCanvas) for n in range(0, 200, 5): L = Line(Point(n, 25), Point(100, 100)) L.draw(myCanvas) wait(0.3) L.undraw() C = Circle(Point(100, 150), 30) C.draw(myCanvas) centerPoint = C.getCenter() C = Circle(Point(100, 150), 30) C.draw(myCanvas) C.setOutline(Color("red")) C.setFill(Color("yellow")) myCanvas C.setWidth(5) myColor = Color(255, 175, 175) # Program to draw a bunch of # random colored circles from Graphics import * from random import * def makeCircle(x, y, r): # creates a Circle centered # at point (x, y) of radius r return Circle(Point(x, y), r) def randColor(): # creates a new color using # random RGB values red = randrange(0, 256) green = randrange(0, 256) blue = randrange(0, 256) return Color(red, green,blue) def main(): # Create and display a # graphics window width = 500 height = 500 myCanvas = Window("Circles",width,height) myCanvas.setBackground(Color("white")) # draw a bunch of random circles with random colors. N = 500 for i in range(N): # pick random center, point, and radius in the window x = randrange(0,width) y = randrange(0,height) r = randrange(5, 25) c = makeCircle(x, y, r) # select a random color c.setFill(randColor()) c.draw(myCanvas) main() def makeCircle(): # creates a Circle centered at point (x, y) of radius r x = randrange(0,width) y = randrange(0,height) r = randrange(5, 25) return Circle(Point(x, y), r) def makeCircle(w, h): # creates a Circle centered at point (x, y) of radius r # such that (x, y) lies within width, w and height, h x = randrange(0,w) y = randrange(0,h) r = randrange(5, 25) return Circle(Point(x, y), r) def makeCircle(): # creates a Circle centered at point (x, y) of radius r x = randrange(0,width) y = randrange(0,height) r = randrange(5, 25) return Circle(Point(x, y), r) C.move(10, 5) # Moving circle; Animate a circle... from Graphics import * from random import * def main(): # create and draw the graphics window w = Window("Moving Circle", 500, 500) w.setBackground(Color("white")) # Create a red circle c = Circle(Point(250, 250), 50) c.setFill(Color("red")) c.draw(w) # Do a simple animation for 200 steps for i in range(200): c.move(randrange(-4, 5), randrange(-4, 5)) wait(0.2) main() # Moving circle; Animate a circle... from Myro import * from Graphics import * from random import * def main(): # create and draw the graphics window winWidth = winHeight = 500 w = Window("Bouncing Circle", winWidth, winHeight) w.setBackground(Color("white")) # Create a red circle radius = 25 c = Circle(Point(53, 250), radius) c.setFill(Color("red")) c.draw(w) # Animate it dx = dy = 3 for t in timer(15): # move the circle c.move(dx, dy) # make sure it is within bounds center = c.getCenter() cx, cy = center.x, center.y if (cx+radius >= winWidth) or (cx-radius <= 0): dx = -dx if (cy+radius >= winHeight) or (cy-radius <= 0): dy = -dy wait(0.01) main() computer.beep(0.005, 440) beep(1, 440) beep(0.75, 440) beep(1, 440) beep(1, 450) computer.beep(1, 440) beep(1, 440) computer.beep(1, 440) beep(1, 880) computer.beep(1, 880) beep(1, 440) computer.beep(1, 440) beep(1, 440) beep(1, 880) 261.63*2**(1/12) beep(1, 27.5) beep(1, 4186) robot = makeRobot("Scribbler", ask("Port?")) s = makeSong("c 1; d 1; e 1; f 1; g 1; a 1; b 1; c7 1;") robot.playSong(s, .75) beep(2, 660) beep(2, 665) beep(2, 660, 665)