# Pages Hyeon-Seung Yu’s Home Hyeon-Seung (Alex) Yu's Project 2: A shape Collection

You are viewing an old version of this page. View the current version.

Version 10

# Summary:

There are three main objectives in this project: 1) create complex shapes by using the basic shapes through function 'def', 2) add more parameters to function such as 'side' and 'scale', and most importantly 3) create my own library and functions inside it, then import those functions to a different python file in order to draw a complex scene.  The key to success in this project was to make sure my basic and complex shapes can be drawn in any place and scale.  Again, adding parameters to the functions was essential to succesfully drawing the shapes.

# Basic Shapes:

My basic shapes are semi-circle and right triangle.  As the instructions required the basic shapes to have some parameters, I made sure that my semi-circles and right triangles can be drawn at x&y location with a given side.  The command below allowed me to control the coordinates.

The images below are my own basic shapes and the block shape, which I used extensively for my aggregate shapes.

One thing to note about the right triangle is that I actually imported 'math' library in order to use a command, which calculates square root of some values.  Although it is quite obvious, the reason I wanted to use command for square-root was that I needed to draw hypothenuse by using the Pythagorean theorem.  Below is a snippet of the command.

In order to control the size of my basic shapes, I added a parameter like this, .  Below is the image of the basic shapes drawn at random places, using the random loop control.

(required picture 1).

With these basic shapes, I am going to draw two shapes that are related to space or space travel.  My aggregate shapes are rockets, launch pad, and spaceships.  Before I show the image of those shapes, I would like to talk about how I managed to put together basic shapes to create aggregate ones.  First, I had to sketch the shapes and calculate the orientations of turtle and the scale of which the sides need to increase or decrease.  Below is the snippet.  In the end, I just had to try different orientations and scales multiple times.

.

Below is the image of my aggregate shapes draw randomly in different locations and sizes.

.

Before I start to draw my space scenes using the aggregate shapes above, I also created a star shape by using for loop command.

Although it looks really simply, I had to think about how I could shift the angle by same amount eight times.  The snippet is the answer..  Because I needed to make each line come back to original line and then turn right by 45 degrees, I used goto and included i within the angle command.

Now I am going to draw my space1, which is going to be a scene of a rocket getting to be launched.  Below is the image.

.  Although the distance between the stars and rockets is unrealistic, I tried to put them apart as far as possible by using random.randint command and certain integer ranges.  One pair of rocket and launch pad seems thicker because I added a parameter pensize.

For the second scene, we are now in space with stars and space ships.  Again, I used random loop control in order to draw the shapes in different locations.

.

One very important thing to note about the below snippet is the name of command, shapelib.star.  shapelib is the name of my python file in which I wrote codes for star, spaceship, and other shapes.  If I import the library 'shapelib' to main.py, then I am able to use the codes of the shapes from shapelib inside main.py.

It is very easy to do so..

# Extensions:

1) I created another quasi complex shape using the basic shapes: satellite.  Compared to drawing rocket, launch pad, and space-ship, writing codes for satellite was more difficult because some shapes were not touching other shapes.  Again, calculating the heading of turtle and increment/decrement in scale was essential.

.

2) Because I wanted just more than stars as background ingredients for space, I wanted to draw blackhole.  The end-result does not like real blackhole, but it uses loop control function and creates an interesting image.  At first, I simply made a line drawing bigger circles, which I expected to illustrate a sort sucking-hole image.  But it did not.  Thus, I switched to using one of my basic shapes, semi-circle, and made it rotate around its starting point by 10 degrees 36 times.(36*10=360 degrees).  This result looked a lot better, so I included in my extension.

.  Doesn't the black circle in the center look like it's absorbing the surroundings?

3) I already mentioned using random.randint command.  One advantage of this random command is that I can now set different ranges for different parameters.  This can be useful when setting different locations/ranges for different shapes.

4&5) In order to add more parameters and use other turtle properties, I simply had to edit my original codes for aggregate shapes.

For a tip, once the number of parameter starts to increase, it becomes easier to forget to include them when calling the functions.

Regarding using color randomly, I actually borrowed the codes from this website:https://trinket.io/python/f0a2314bf3.  The idea is quite simply.  Create a variable 'color' which has different values, i.e. colors.  Then use random.choice(color), which is one of the random packages, to draw with different colors.  Although I am not sure whether this is the most efficiency way to paint in different colors, this is surely one way to do so.

6) Below is the final image, which uses almost all of my shapes: stars, space-ships, satellites, blackholes, and rockets with different colors and pen width at different locations.

Labels
• No labels