PYTHON: Animation - a cube
This is my first attempt at an animation in Python.
I get the pink Fuzzle to draw a cube.... the Fuzzle is my trademark - I first had Fuzzles on my Cyberphysics site (my son first designed them for me - and my daughter improved them further!) - they also joined me on Cybercomputing.
The first thing we have to do is import the 'turtle'.
import turtle
We then have to set up the screen, decide on a screen size using screen.setup(x-value,y-value), and choose a colour for that screen.
screen=turtle.Screen()
screen.setup(550,550)
screen.bgcolor("dark green")
We can then set the cursor to be a Fuzzle. To do this we have to import an image (gif or png) to our library. We can then add the shape to the screen and make it our 'turtle' - deciding on the colour we want it to draw lines in...
screen.addshape("FuzzlePINK.png")
fuzzle = turtle.Turtle("FuzzlePINK.png")
fuzzle.shape("FuzzlePINK.png")
fuzzle.color("pink")#We have set the colour of the lines we will draw with the Fuzzle to be pink!
The movement of the Fuzzle is done using 'turtle commands':
fuzzle.rt(90) #Here the cursor (turtle - in this case a Fuzzle) makes a right turn of 90o
fuzzle.down() #Here we put the pen down (start making a mark on the screen)
fuzzle.forward(200) #Here we move the Fuzzle forward 200 pixels - and as the pen is down, we draw a line as we move.
fuzzle.rt(90)
fuzzle.forward(200)
fuzzle.rt(90)
fuzzle.forward(200)
fuzzle.rt(90)
fuzzle.forward(200)
fuzzle.rt(315)
fuzzle.forward(170)
fuzzle.rt(135)
fuzzle.forward(200)
fuzzle.rt(45)
fuzzle.forward(170)
fuzzle.up() #Here we lift the 'pen' up - as we want to move the Fuzzle without drawing a line.
fuzzle.rt(90)
fuzzle.forward(283)
fuzzle.rt(90)
fuzzle.down() #Now we have the Fuzzle where we want him we put the pen down again - to strat drawing.
fuzzle.forward(170)
fuzzle.rt(45)
fuzzle.forward(200)
fuzzle.rt(270)
Here is the result of our work.... enjoy!