Week 12: Exercises

1. Random Lines

Write a Tkinter program that draws 1000 random lines of length 300 pixels, each with a random color. All line angles should be equally likely.

2. Czech Flag

Write a Tkinter program that draws a Czech flag:

Do not use any external image files – instead, the program should draw the flag itself using filled rectangles and/or polygons.

3. Victory Line

Modify the Tic-Tac-Toe program from the lecture so that when one player wins, it draws a line through the winning squares.

4. Turn to Play

Modify the Tic-Tac-Toe program from the lecture so that it indicates whose turn it is to move.

5. Drawing Lines

Write a Tkinter program that lets the user draw lines. Initially the program should display a blank canvas. If the user clicks and drags the mouse, the program should display a line from the point where the user clicked to the current mouse position. When the user releases the mouse, the line should remain on the canvas. Each line should have a random color.

7. Drawing Squares

Write a program that lets the user draw squares by dragging the mouse. Each square should have a random color.

8. Dragging Squares

Extend the previous program so that the user can move a square to a new position by clicking and dragging it. A moved square should rise to the top of the Z-order.

9. Balloons

Write a program that displays balloons with random colors. Every 3 seconds, a new balloon should appear near the bottom of the screen. Each balloon should rise until it reaches the top of the screen, then vanish.

10. Balloon Game

Extend your program from the previous exercise, turning it into a simple video game. Each time the player clicks a balloon, it should pop and the user should gain a point. If any balloon reaches the top of the screen, the player has lost and the game is over. As the game proceeds, balloons should appear more frequently and move more quickly, so that the game becomes harder and harder. Display a score at the top of the screen.