# Pages … Home Zena Abulhab CS151 - Computational Thinking: Visual Media Zena's CS151 Project 11 Page History

## Key

• This line was removed.
• Formatting was changed.

...

Task 1 was to make at least four 3D Turtle shapes and add them to our shapes library. In my case, I made a cube, a pyramid, a triangular prism, and a "house" shape.

Image Removed
Image Removed Image Removed

Image Removed
Image Removed
Image Removed
Image Removed

Image Removed
Image Removed
Image Removed Image Removed

Making shapes in 3D is just like making 2D shapes, except now when the turtle turns, it is not only limited to "left" and "right". Rotation around the z axis (turning left or right like before) is called "yaw", "roll" is rotation around the x axis (leaning left or right), and "pitch" is rotation around the y axis (like turning to face up or down). We needed to add cases to the turtle interpreter, so "&" was given pitch up, "^" was given pitch down, "\" was given roll up, and "/" was given roll down. Keeping this in mind, I drew the shapes shown below. The characters used to represent a pyramid, for example, were [F+[(45)(45)&F]F[(45)(45)&F]F[(45)(45)&F]F(45)+(45)&F]. The turtle moves forward, turns left (90 degrees), remembers that position because it will continue from there to make the square base, then turns left 45 degrees, up 45 degrees (pitches up), and goes forward. Then it goes back to the remembered position, turns left 90 degrees, and continues on in the same manner until the pyramid is made. Note that if string needs to be repeated and you don't want to write it all out again, you can use the string multiplication property; writing 'F' * 4, for instance, makes the turtle go forward forward and right left times, drawing a square. The picture below also shows the jitter3 and jitter styles from last week's project.

For Task 3, we needed to improve our code in some way, including doing one of the extensions, so I did extension 7, which was to make another "shape" that was actually a dynamic shape, drawing whatever the file it reads says, and, optionally, what the user inputs in the terminal. I didn't need to change the parent Shape class at all, I just needed to give this dynamic shape class instructions to read the file that was passed in in its init function, or to write the argv into another file (or possibly the same, depending on what is given) if it is given and read that instead. Then, once the parent init function is called, the only difference is that the string passed in is the string read from the file. This code is shown below: Image Added
This "argv" is passed in through whatever line of code is calling the shape to be made; for example, the next pictures show what code I input in a file and into the command line to draw the picture below it. I wrote into the command line the two shapes that I wanted to be drawn. The place the yellow shape expects to get its text from is the first index of the command line, and the blue one expects it from index two. If the command line is not to be used, the argv should be given the value of None instead, so the file will just be read instead.

For my first extension, extension 5, I made a way for the user to type instructions for an L system into the command line and have that be drawn. This involved passing two arguments through the shapes class init, L system class init, readString init (which I made fresh), and the Turtle Interpreter's drawString function: base string (bstring) and rule string (rstring). First off, these two were necessary to differentiate between the base and rule(s) of the command line turtle instructions. The way I organized them was to have index 1 of argv be where the base is, then the ones after just follow the pattern of "base to replace" and "rule to replace it with", so I took advantage of that by using the following code when calling an L system to be made through the tree.py file.  Image Added
As you can see, it is organized into two categories: the base and all the rest, from which we will separate the bases to replace and the rules using the following code: