Contents
- graphics_test.py
- pick4.py
- randint_example.py
- rectangle.py
- tictactoe.py
graphics_test.py 1/5
[top][prev][next]
# Graphics Test Script
# by Sara Sprenkle
from graphics import *
win = GraphWin("My Circle", 500, 500)
point = Point(50,50)
c = Circle(point, 10)
c.draw(win)
win.getMouse()
pick4.py 2/5
[top][prev][next]
# Simulate the VA Pick4 Lottery game
# by CSCI111, 9.21.2012
# import random module
from random import *
print("The winning Pick 4 lottery number is ", end='')
for i in range(4):
ranNum = randint(0,9)
print(ranNum, end='')
print()
# Why doesn't the following code work as an alternative correct solution?
#print(randint(0,9999))
randint_example.py 3/5
[top][prev][next]
# Demonstrates what happens when 0000 is used as input to randint
# In response to DanJoseph's question
# by Sara Sprenkle, 09.24.2012
from random import *
for trial in range(50):
print( randint(0000, 9999) )
rectangle.py 4/5
[top][prev][next]
# Draw a rectangle using the graphics API
# by CSCI111
from graphics import *
# create the rectangle
point1 = Point(50, 50)
point2 = Point(100, 100)
r = Rectangle(point1, point2)
# Alternatively,
# r = Rectangle( Point(50, 50), Point(100, 100))
# draw the rectangle
win = GraphWin("My Rectangle", 100, 100)
r.draw(win)
# pause
win.getMouse()
# shift the rectangle to the right by 10 pixels
r.move(10, 0)
# pause
win.getMouse()
# Find out the new coordinates for the rectangle
upperLeft = r.getP1()
bottomRight = r.getP2()
print( "upper left coordinates: (", upperLeft.getX(), ",", upperLeft.getY(), ")" )
print( "lower right coordinates: (", bottomRight.getX(), ",", bottomRight.getY(), ")" )
win.getMouse()
win.close()
tictactoe.py 5/5
[top][prev][next]
# Create full-size tic-tac-toe board
# By CSCI111
#
# NOT COMPLETE YET
#
from graphics import *
WINDOW_DIM=200
tictactoeBoard = GraphWin("Tic Tac Toe Board", WINDOW_DIM, WINDOW_DIM)
width = tictactoeBoard.getWidth()
height = tictactoeBoard.getHeight()
# first vertical line
point = Point(WINDOW_DIM/3, 0)
point2 = Point( WINDOW_DIM/3, WINDOW_DIM )
line = Line(point, point2)
line.setOutline("purple")
# second vertical line
point3 = Point(WINDOW_DIM*2/3, 0)
point4 = Point( WINDOW_DIM*2/3, WINDOW_DIM )
line2 = Line(point3, point4)
line2.setOutline("purple")
tictactoeBoard.getMouse()
Generated by GNU enscript 1.6.4.