• Animating in Python
    9 replies, posted
Okay, since people are wanting to know and I GOT A DUMB RATING I'll give you the code I've been working on. This is my bike [code]''' Bicycle Assignment ''' __author__ = 'Kurt Hansen' __date__ = 'Sept 1, 2009' from cs1graphics import * paper = Canvas(500,200, 'white', 'Kurt Hansen') bike = Layer() ''' Whole Tire ''' tire = Layer() tire1 = Circle(40, Point(0,0)) tire1.setBorderWidth(5) tire.add(tire1) spokes = Layer() spoke1 = Path(Point(0,0),Point(0,40)) spoke1.setBorderWidth(2) spokes.add(spoke1) tire.moveTo(110,160) tire1.setDepth(30) spokes.setDepth(5) bike.add(tire) spoke2 = spoke1.clone() spoke2.rotate(15) spokes.add(spoke2) spoke3 = spoke2.clone() spoke3.rotate(15) spokes.add(spoke3) spoke4 = spoke3.clone() spoke4.rotate(15) spokes.add(spoke4) spoke5 = spoke4.clone() spoke5.rotate(15) spokes.add(spoke5) spoke6 = spoke5.clone() spoke6.rotate(15) spokes.add(spoke6) spokes2 = spokes.clone() spokes2.rotate(90) tire.add(spokes2) spokes3 = spokes.clone() spokes3.rotate(180) tire.add(spokes3) spokes4 = spokes.clone() spokes4.rotate(270) tire.add(spokes4) tire.add(spokes) ''' Second Tire ''' othertire = tire.clone() othertire.move(150,0) bike.add(othertire) ''' Frame ''' frame = Layer() path1 = Path(Point(0,0), Point(60,20)) path1.setBorderWidth(5) path1.setBorderColor('darkRed') frame.add(path1) path2 = Path(Point(60,20), Point(115,-80)) path2.setBorderWidth(5) path2.setBorderColor('darkRed') frame.add(path2) path3 = Path(Point(150,0), Point(115,-80)) path3.setBorderWidth(5) path3.setBorderColor('darkRed') frame.add(path3) path4 = Path(Point(115,-80), Point(30,-70)) path4.setBorderWidth(5) path4.setBorderColor('darkRed') frame.add(path4) path5 = Path(Point(60,20), Point(28,-85)) path5.setBorderWidth(5) path5.setBorderColor('darkRed') frame.add(path5) path6 = Path(Point(30,-70), Point(0,0)) path6.setBorderWidth(5) path6.setBorderColor('darkRed') frame.add(path6) path7 = Path(Point(115,-80), Point(115,-100)) path7.setBorderWidth(5) path7.setBorderColor('darkRed') frame.add(path7) seat = Rectangle(20, 5, Point(28,-85)) seat.setFillColor('Black') frame.add(seat) seat.setDepth(2) frame.moveTo(110,160) frame.setDepth(4) bike.add(frame) paper.add(bike)[/code] This is the environment. [code]''' Environment ''' tree = Polygon(Point(50,80), Point(110,100), Point(110,60)) tree.setFillColor('darkGreen') paper.add(tree) tree.rotate(90) tree.move(300,0) tree.setDepth(60) tree2 = Polygon(Point(0,200), Point(60,60), Point(120,200)) tree2.setFillColor('darkGreen') paper.add(tree2) tree2.setDepth(1)[/code] This is what I've used to do the animation. [code] ''' Animation ''' paper.wait() i = 0 while i<200: bike.moveTo(i, 0) tire.rotate(-10) othertire.rotate(-10) i = i+3 [/code] Basically I moved the bike to the right with the moveTo command and also rotated the tire layers WITHIN the bike layer, so that I didn't have to move the tires independently of the bike. Anything else whiners?
What was it? I'm interested now.
Same haha.
Atleast keep the firstpost and the solution so other people that may have this problem can solve it too.
[QUOTE=maurits150;17199104]Atleast keep the firstpost and the solution so other people that may have this problem can solve it too.[/QUOTE] Yeah I hate when people do that D:
[QUOTE=Pandamobile;17199259]Yeah I hate when people do that D:[/QUOTE] Haven't you heard? The internet exist purely to service one user! If he isn't entertained, the rest of us suffer.
hi letifer
You could do what I do and just make a timer, which is just an int which you increase every frame. Wait for it to hit your specified value. Then reset the value.
Sorry, you need to Log In to post a reply to this thread.