Lab Week 02 - Fall 2023

Tuesday, September 5, 2023


Introduction

This lab is set up so you can learn how to build up a full deliverable that you can submit for credit in this course. As you work on these steps with guidance from your teaching assistant, you should look toward your neighbor to see if they need help (or ask if you need help). You can collaborate in lab during these activities!

In this lab, you will


Create a folder for this lab in your 15-104 folder/directory..


Problem A

Using the default size canvas in the starter file, draw four blue squares of size 50 X 50 at random locations on the canvas so that none of them fall outside the bounds of the canvas. See the first picture below. Your program should only draw four squares once. Once you have that done, modify the program so that it draws the four squares, then clears the canvas to the background and draws four random squares again, then clears the canvas to the background and draws four random squares again, etc. Finally, modify the program so that it does not clear the canvas so you get layers and layers of four random squares. See the second picture below.

Image of only four blue squares  & Imager of layers of four blue squares


Problem B

Using the default size canvas in the starter file, make a circle with radius 50 that follows the mouse as you move it around the canvas. What happens if you repaint the background in your draw function? What happens if you don’t? Update the program once you have it running so that the diameter tracks the horizontal position of the mouse (the farther to the left, the smaller the diameter; the farther to the right, the larger the diameter). See the final picture below.

Lots of varying-sized circles tracking the mouse


Problem C

Put a 20 X 20 square in each corner of a canvas (assuming the canvas is at least 40 X 40). Remember to use the environment variables width and height so that your program will work no matter what the canvas size is. Try out a few canvas sizes to make sure your program works as specified. See the picture below (for a canvas of size 400 X 150).

four squares in the corner regardless of canvas size


Problem D

Make the background of the canvas turn yellow if the mouse is in the top left quadrant, cyan if the mouse is in the top right quadrant, magenta if the mouse is in the bottom left quadrant, and white if the mouse is in the bottom right quadrant. (HINT: You can do this by layering if-else instructions.) Your program should work for any size canvas. (Be sure to try a few different canvases to make sure.)


Once you run out of time, you should submit your completed work for credit.