Skip to end of metadata
Go to start of metadata

Summary:

This lab is focused on giving us practice in creating a base class with many methods and fields, and then having child classes inherit them. Also, there will be part of the lab focused on creating L-Systems that randomly (stochastically) selects a rule from a given collection of rules. This creates unique creations every time the program is run.

Tasks:

We had Four main tasks for this project, each having a required image.

Required Image 1:The first was to create a L-System that stochastically selects a random rule, as described in the above summary. The required image below demonstrates this action in place, using three tree rules from past projects (seen in the picture next to the first required picture).

Required Image 2: For this task, we had to demonstrate that we can create shapes (three non square/triangle) through the creation of child classes. Below is each shape demonstrating their capabilities.

Required Image 3: Similar to some past projects, we now had to create an indoor scene. However, this time we had to use the above tree and shapes. Below is the required image; take note that I had to change some of my child classes at this point to create certain effects. One alteration can be seen in the triangle shape (mountain), where I added a character in the Turtle_Interpreter to build a string and draw a tree. I inserted this new character into the triangle child class, this making the second required image no longer attainable with my current code (however, I can easily return it back to its original state). Also note to create the plant I actually made three trees (each generated stochastically), the orientations differing, making an especially unique bush every time.

Required Image 4: For the fourth, and final required image, we had to create a mosaic that uses tiles that are made up of a specific amount of individual shapes. I decided to use stars, and I also decided to make the colors alternating and America themed. Below is required image 4 (one shows the tiles separated and one shows them filling the graphics window).

Extensions:

I completed the following extensions:

  • Make non-square tiles. 

As you can see in required image 4, I used stars instead of squares to make the tiles for my mosaic. 

  • Make new L-Systems and add characters to the vocabulary that do interesting things.

In my first task I created a L-System that was a hybrid of the trees that we already know. I then reused this L-System in both my third required image and then my extension piece.

I added an interesting character to draw a tree along the mountain in required image three. The character definition, along with the changed Triangle Class can be seen below.

  • Create a sequence of images to build an animation.

To create an animation I had the drawing of my tree L-System set to a timer using the time.sleep() function. This required me to import time. I did a similar methodology in the creation of a 'growing cross'. Both of these can be seen in the below extension piece.

  • Use a Python Language new to you.

While we have used raw_input language before, we were never really taught any of the specifics of it. I decided to focus on it and I did a good amount of reading before using it in my extension piece. I never knew that raw_input can be used to get user input. This is done by setting it (defining a) variable. Also I had to tune up my knowledge regarding strings and integers and how to swap between the two (I created a function to do this for raw_input returns strings and I needed an integer to designate how plants there would be).

In summation, my extension program is called Farm Simulator that creates a farm based on user answers to simple "Yes" or "No" questions. Below I demonstrate what happens in every situation and here is video of the program where I answer "Yes" to everyone question other than healthy dirt (to get more shapes on the screen) -- http://youtu.be/C45X-bp-Uyg --

Some interesting notes:

  • Everyone question (except the number of plants one) has a very similar format to return "Yes" or "No" and has a built in response to give when someone doesn't input "Yes" or "No"

  • The plants are placed in a random y coordinate within the dirt portion of the screen, while they have a specific x coordinate based on the width of the screen divided by the number of the trees. This makes it so that no matter what number one puts in, all the trees will be on the screen. In the above examples I demonstrated '5' and '10'. Below you can see a very crowded '50'.

What I learned:

I learned that Classes, and the following creation of child classes, can be extremely useful/effective for the creation of objects. The speed to which things are being drawn has drastically improved compared to past projects. Most of my learning came in the form of the extension for I not only did background reading on the language, I got to learn a new skill in a subject that I am very interested, User Input driven Programs. When combining this with my previous knowledge regarding the use of the user's mouse, I think I will be able to create some cools programs in the future. I have done very minor work with Toni and Mike during the beginning stages of this project. 

Labels