DEV Community

Cover image for 5 Dice Straight
Scott Gordon
Scott Gordon

Posted on

5 Dice Straight

This is a simple program to draw a 5 dice straight using the graphics module created by John Zelle.

# dice5.py
#   This program draws 5 dice to the screen depicting a straight (1,2,3,4,5).
# by: Scott Gordon


from graphics import *

# Create main window 100 X 200


def main():
    # Create grey background size 1000 X 200 pixels
    win = GraphWin("Dice as Straight", 1000, 200)
    win.setCoords(-10, -2, 10, 2)
    win.setBackground("grey")

    # Draw a single die to the screen at the leftmost edge.
    dice1 = Rectangle(Point(-9.8, -1.80), Point(-6.2, 1.8))
    dice1.setFill("white")
    dice1.draw(win)

    # Clone the remaining 4 dice
    dice2 = dice1.clone()
    dice2.move(4, 0)
    dice2.draw(win)

    dice3 = dice2.clone()
    dice3.move(4, 0)
    dice3.draw(win)

    dice4 = dice3.clone()
    dice4.move(4, 0)
    dice4.draw(win)

    dice5 = dice4.clone()
    dice5.move(4, 0)
    dice5.draw(win)

    # Assign the values to the dices by drawing small dots on them all
    dot1 = Circle(Point(-8, 0), .25)
    dot1.setFill("black")
    dot1.draw(win)

    dot2 = dot1.clone()
    dot2.move(5, 1)
    dot2.draw(win)

    dot3 = dot1.clone()
    dot3.move(3, -1)
    dot3.draw(win)

    dot4 = dot1.clone()
    dot4.move(8, 0)
    dot4.draw(win)

    dot5 = dot2.clone()
    dot5.move(4, 0)
    dot5.draw(win)

    dot6 = dot3.clone()
    dot6.move(4, 0)
    dot6.draw(win)

    dot7 = dot5.clone()
    dot7.move(4, 0)
    dot7.draw(win)

    dot8 = dot6.clone()
    dot8.move(4, 0)
    dot8.draw(win)

    dot9 = dot7.clone()
    dot9.move(0, -2)
    dot9.draw(win)

    dot10 = dot8.clone()
    dot10.move(0, 2)
    dot10.draw(win)

    dot11 = dot7.clone()
    dot11.move(4, 0)
    dot11.draw(win)

    dot12 = dot8.clone()
    dot12.move(4, 0)
    dot12.draw(win)

    dot13 = dot9.clone()
    dot13.move(4, 0)
    dot13.draw(win)

    dot14 = dot10.clone()
    dot14.move(4, 0)
    dot14.draw(win)

    dot15 = dot4.clone()
    dot15.move(8, 0)
    dot15.draw(win)

    win.getMouse()
    win.close()


main()

Enter fullscreen mode Exit fullscreen mode

Top comments (0)