CS21 Lab 5: graphics

Due Saturday, October 14, before midnight


Programming tips/requirements

1. Line Art

In this first program you'll create a geometric artwork, like the ones by Sol LeWitt. In the file lineart.py, create a program that displays the left-hand side of the image below. This work is currently displayed in the MASS MoCA.

Here are a few steps and suggestions to help you get started. We recommend creating a diagram on paper first - mark the x-axis and y-axis, then write down the (x,y) coordinates of the endpoints of each line.

$ python3 lineart.py 
Enter the window size: 400

I used a line width of 2 for both the lines and the rectangle outline, but feel free to modify this, or change the color of the background or the lines. Next, create a square in the middle of the drawing (the relative size of the square is up to you):

$ python3 lineart.py 
Enter the window size: 400

Create a series of horizontal lines across the square using another loop:

$ python3 lineart.py 
Enter the window size: 400

Finally, allow the user to determine the size of the square window, and make your code flexible enough to resize the drawing to accommodate the new size. Here are a few examples:

$ python3 lineart.py 
Enter the window size: 100

$ python3 lineart.py 
Enter the window size: 600

User entered 600

Here the line separation is constant, but the number of lines changes depending on the window size.

Extra Challenge (no points...just for fun, if you have time)

First option: reproduce the entire painting above (not just the square but the circle too).

Second option: here are a few other Sol LeWitt paintings to reproduce / modify if you are interested. Feel free to use these as inspiration to create your own geometric painting with your own color scheme.

2. Night Sky

Write a program called night.py that generates an animated night sky, using mouse-clicks from the user. Here is an example:

Here are the requirements and some tips for this program:

Extra Challenge (no points...just for fun, if you have time)

There are many ways to extend this animation. You could use different colors to create a different scene, or make the scene simulate a solar eclipse where the moon passes over the sun. One step further, when the sun's light is being blocked out, make the entire picture fade to dark and back to light again.

You could also add more options (through functions) for the user's clicks. Maybe for a while the user could create objects on the ground (trees, etc), or maybe the sky is over an ocean with fish. Or you could make an animated sunrise / sunset.

3. Answer the Questionnaire

Each lab has a short questionnaire at the end. Please edit the QUESTIONS-05.txt file in your cs21/labs/05 directory and answer the questions in that file.

Turning in your labs....

Don't forget to run handin21 to turn in your lab files! You may run handin21 as many times as you want. Each time it will turn in any new work. We recommend running handin21 after you complete each program or after you complete significant work on any one program.