# Pages … Yixuan Qiu’s Home CS151 Yixuan's CS151 Project 11: 3D Scenes Page History

## Key

• This line was removed.
• Formatting was changed.

### 1. Summary

In this project, I used the 3D turtle to build some interesting 3D shapes, implemented 3D drawing styles, and created interactive tools to take user input from the command line to build strings or L-systems for drawing shapes. Different from the 2D turtle, the 3D turtle has three rotation types–roll('/' '\'), yaw('+' '-'), and pitch('^' '&')–along x, y, z axes.

I also took advantage of f-strings to flexibly format strings and recursion to build binary trees.

For my first task, I made 5 new 3D shape classes–Cube, House, Cylinder, BasketballHoop, and Sphere. I used parametrized strings to make the task easier. I extended the 'jitter' and the 'dotted' styles to 3D to draw the house and the cube.

...

To draw a basketball, I used the Sphere class with a string incorporating a symbol 'C' that represents a circle. I let a circle rotate for 72 times to make a sphere.

...

Here is my scene from different points of view:

For my third task, I chose to make an additional scene in architecture.py, as shown below.

...

Secondly, I made the Spanish Pavilion at Expo Milan 2015.

###### Image Modified (image source: http://b720.com/portfolio/expo_milan/)

I created three classes--Pavilion_left, Pavilion_middle, and Pavilion_right--to simply the process of building up the pavilion.

...

In my drawPavilion function, I made a for loop to draw the three parts of the pavilion, and it efficiently shortened the code.

### 5. Extensions

#### 1) Implement 3D drawing styles.

(a) Pick an NPR style--Jackson Pollock.

...

In case you cannot figure out what the shapes are, the first one is a stack of cubes, and the second one is a dodecahedron.

##### (b) A color gradient style.

In my parallel function in TurtleInterpreter, I made a for loop to increase the r, g, b values of the lines along the z-axis.

#### 2) Pick some semi-complex shapes and create efficient designs for them.

For my second extension, I chose to draw a dodecahedron. In my Dodecahedron class, I first made the bottom half and then moved the turtle up to draw the other half so that the design is more efficient.

#### 3) Make an additional scene.

For the third extension, I decided to make a piece of installation art. Only from one point of view can you see the real shape. It turns out to be a Christmas tree!

...

Then, I make the turtle pitch down after it draws a triangle so the triangles can form a wreath.

#### 4) Use the 3D turtle to create an interactive tool for creating L-systems. Take user input from the command line to define base strings and rules.

In interactiveTree.py, I made a program to take user input from the command line to set the base string, rules, and iterations. It allows the user to add a number of new rules depending on the input 'number of rules' on the second line.

...

Since the draw method in Tree class already includes a command to set the string, it does not work if I set the string again. So Professor Layton suggested adding an if statement before the line of building strings, so that it only builds strings if the string is an empty string.

#### 5) The 3D turtle allows you to attach a function to the right mouse button. Whenever the user clicks the right mouse button in the window, the function gets called.

In my TurtleInterpreter, I created a rightClick method that takes a function as a parameter to call the setRightMouseCallback method.

...

A ball gets drawn after I click the right mouse button.

#### 6) Design a generic shape class that reads its string from a file. See if you can combine this with some interactivity so the user can edit a string and then look at the result immediately.

For my last extension, I created a generic shape class called Generic in shapes.py. I allow the user to input the filename from the command line.

...

And this draws a green pentagon:

### 6. Reflection

Through the project, I learned to draw 3D shapes using parametrized strings, positioned and scaled the shapes to build 3D scenes, implemented 3D drawing styles, made complicated shape strings, and created interactions between user and the program. I also deepened my understanding of classes and inheritance. Additionally, I learned to make strings efficiently based on the regularity of the shapes. Although I spent a large amount of time thinking about the design, I gained so much after finally realizing my shapes, because thinking generates happiness.

...