Contents
- animate.py
- circleShiftAnim.py
- circleShift.py
- pick4.py
animate.py 1/4
[top][prev][next]
# Simple demonstration of animation.
# by Sara Sprenkle
from graphics import *
from time import sleep
STEPS = 100
window = GraphWin("Simple Animation", 400, 400)
window.setBackground("orange")
current = Point(60,60)
circ = Circle(current, 50)
circ.setFill("blue")
circ.draw(window)
end = window.getWidth()
dx = (end - current.getX())/STEPS
for step in range(STEPS):
circ.move(dx, 0)
sleep(.1)
window.getMouse()
window.close()
circleShiftAnim.py 2/4
[top][prev][next]
# Move a circle to where the user clicked
# By CS111
from graphics import *
from time import sleep
canvas = GraphWin("Move the Circle", 500, 500)
# create the circle in the upper left
circle = Circle( Point(50,50), 50)
circle.setFill("fuchsia")
circle.draw(canvas)
# put the directions in the top center of the canvas
directions = Text( Point(250, 20), "Click where you want to move the circle to.")
directions.draw(canvas)
# get the mouse click from the user
newCenterPoint = canvas.getMouse()
# move circle to where the mouse was clicked
# get x and y from the center point
newX = newCenterPoint.getX()
newY = newCenterPoint.getY()
# find the difference between them and the original center
diffInX = newX - circle.getCenter().getX()
diffInY = newY - circle.getCenter().getY()
# move the difference
STEPS=100
for movement in range(STEPS):
circle.move(diffInX/STEPS, diffInY/STEPS)
sleep(.05)
# wait for the mouse click
canvas.getMouse()
canvas.close()
circleShift.py 3/4
[top][prev][next]
# Move a circle to where the user clicked
# By CS111
from graphics import *
from time import sleep
canvas = GraphWin("Move the Circle", 500, 500)
# create the circle in the upper left
circle = Circle( Point(100,50), 50)
circle.setFill("fuchsia")
circle.draw(canvas)
# put the directions in the top center of the canvas
directions = Text( Point(250, 20), "Click where you want to move the circle to.")
directions.draw(canvas)
# get the mouse click from the user
newCenterPoint = canvas.getMouse()
# move circle to where the mouse was clicked
# get x and y from the center point
newX = newCenterPoint.getX()
newY = newCenterPoint.getY()
# find the difference between them and the original center --> diff
diffInX = newX - 100
diffInY = newY - 50
# move the difference
circle.move(diffInX, diffInY)
# wait for the mouse click
canvas.getMouse()
canvas.close()
pick4.py 4/4
[top][prev][next]
# Display the numbers that are selected by the magic
# ping-pong ball machine for Pick4 VA Lottery, all on one line
# By CS111
# import random module
import random
print("The Pick4 Number is ...", end=" ")
# loop 4 times
for x in range(4):
# generate a random integer between 0 and 9
print(random.randint(0, 9), end="")
print()
Generated by GNU Enscript 1.6.6.