Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Philip Prosapio
CS 151- Thursday Lab

My code is in pwprosap account in the academic server.


For the first task, I was asked to make a main.py file and import my shapeslab2 codes and then run a couple of them. Then I was asked to make two functions in my shapeslab2.py file and run them through my main.py file. This image is picture1.png that is attached to this. Next I was asked to make two more functions in my shapes.py file; this time, the shapes were asked to be outdoor objects (e.g. cars, suns, bushes) and I ran these functions in shapeslab2.py file. This image is picture2.png. Finally I was asked to make two different scenes that would use my previously made outdoor functions. I attached scene 1's image and it is named picture3.png, and scene 2's image is named picture4.png.
This assignment was meant to teach us how to be able to make multiple objects that can be drawn at any scale or any position on the screen. It also helped us to implement many varying and new parameters.

Description of my solutions to the required task

Task 1- The first task asks us to create the new main.py file and import our functions from our original shapeslab2.py file. This was down by using the command import shapeslab2 at the top of the code document.

Task 2- In the second task I made a large triangle, with a simple set of code, but the code that helped the most was my circle function:
goto(x, y)
This allowed me to input a location and scale to easily create multiple circles in my drawing. I combined my triangle and circles to make a basic picture for task one, this picture is titled picture1.png

Task 3- The third task is where things started getting difficult. My first outdoors function was a variation on my circle function that I used in the the last task. It was my sun function. I scaled the circle to 3.5 times bigger and changed the color to yellow to make it into a sun. But the second function was a little more difficult, and that was my truck function. As we all know, a truck is useless without wheels, and that was the key part of the code. With the code below, I was able to place the wheels in the right position, needless of the size that I scaled the entire truck to:
circle(x+25*scale, y-15*scale, scale)
circle(x+150*scale, y-15*scale, scale)
I then mixed the two outdoor functions to make a simple picture of some trucks stuck in traffic. This picture is attached and labeled as picture2.png

Task 4- In the fourth task, I took my functions from before, and created some new ones to make an outdoor scene. This was the most complicated picture because of how many commands I had to put into it and how many objects were in the picture. I took previously made functions such as my sun, trucks, and building to make this photo. By half scaling my buildings and trucks I was able to fit them and make the scene well proportioned. The best thing that I added was the road. By filling it in black I was able to make the center yellow stripe visible. So the final picture was the row of houses, with a road running in front of the houses with two cars and a sun and a couple of birds in the sky. This picture is labeled picture3.png

Task 5- While this task needed less commands then the last scene, it had one added degree of complexity. And that complexity is the use of the random function. At the top of the file I needed to enter the command import random to allow this whole picture to work. When I call the function scene 2, the first command it completes is the bunchOfBirds function that was in my shapeslab2.py file:

shapeslab2.bunchOfBirds(random.random(), random.random())

The two random.random() commands allows the bunchOfBirds function to randomly place my birds across the top of the picture. This makes the flock of 30 birds become generated randomly. I then added a little house with a couple of bushes placed around it. The bushes also were an adaptation from my earlier circle function. This scene is named picture4.png

Extension 1- This extension fulfilled the extension that required me to use the random command. It used the concept of my flock of birds, but made it on an even larger scale. I dyed large portions of the background blue for the night sky, and green for the earth. And then I allowed my stars function to randomly generate hundreds of stars in that night sky. On a smaller note, I learned on this extension to make something white you can enter the command:


This made it possible to make a moon and all the stars in the sky the right color. I named the first extension picture5.png

Extension 2- This second extension fulfilled the extension that asked me to make an additional picture that makes use of creative uses of loops or functions. I decided to make a house on a cliff, overlooking a canyon. The toughest portion of this picture was the bridge that spans the canyon. To give the bridge a slight amount of curve to it, I added in this loop to aid me:

for i in range(45):
The for loop allowed me to repeat the two commands inside of it 45 times by only writing 3 lines, which is very helpful. This second extension was named picture6.png

What I Learned

Easily the two greatest and most helpful things for the future that I learned during this second project are how to use a "for" loop and how to be able to scale and move an object just by changing the input values. These two things allow me to make multiple intricate objects with fewer code lines and I can scale and move the objects with ease. This will make future projects much easier.

Note Again, I did two extensions, and those are the random extension and the additional extension, pictures 5 and 6.

Picture 1

Picture 2

Picture 3

Picture 4

Extension Pictures
Picture 5

Picture 6