In this week's project we are supposed to get familiar with inheritance and class. Also, we learn how to use dictionary to build better lsystems.
For the first task, I made this picture. These trees are created based on systemI, with iteration number 3. Since there are several replacement for one rule these trees are variable.
I add some simple classes to my shapes document. As you can see, except square and triangle, i build pentagon, hexagon and star.
I also add color fill argument to every class. So that when I want to fill color in these figures I only need to set the fill value True.
Next one is the indoor scene. As you can see, I create this scene only with figures shown above. At first I used loop and square class to build the mosaic floor and wall. To make them look better I set random color but control the range of rgb value. So the wall is generally blue and the floor is brown.
The last task is the mosaic files. I create a simple file with a square and a star. To keep the random color of square and star different I set the star's rgb value in different order with square.
I create a hexagon mosaic picture. It is important to find out the location relationship of nearby files. I did it in this way:
Next part is a new lsystem. I made some change to one of my old lsystem and get a totally new graph. This lsystem is shown below:
rule V FV+FV+FV+FV+FV
rule F FF FFF
iteration number is 3 and angle is 144.
Next one is the tilt trees. To make this I make some change to the drawstring function.
I also build a Ngon class. Since I had written similar code before it's quite easy. This class can draw Ngon with given number of sides. I add fill color argument to it. This is a simple example of class that can build string itself.
In this week, I learned how to use class and dictionary to improve my lsystem and create more interesting graphs. I am now more familiar with these methods.
People I worked with:
This week in lab we explored 3D Turtle! First we had to update our lystems, turtle_intepreter, shapes, and trees files to be able to handle 3D. This was easy because we imported the new 3D turtle module as turtle so we could use all the same code.
We had to add new parameters for pitch, roll, and zpos for many functions, as well as include them in the turtle_interpreter character list.
To create 3D shapes, we made strings using the same characters we used before.
Here are the shapes I created:
Here is a scene I drew: an apple orchard! There is a house and a barn, as well as multiple trees underneath the clouds.
Here is an extra scene I created that is dependent on random placement:
And here is my third task: I decided I wanted to make a Christmas tree with presents around it in honor of the holiday spirit. First I created a Christmas tree by stacking my previously made pyramids. Then I added presents with other shapes.
This week I learned a lot about creating my own character strings to make shapes. It was difficult to think in three dimensions while creating objects.
I worked with Stephanie and Kyle, as well as Maddi and Luc Marrie.
Project 10 was about non-photorealistic rendering. We explored this topic by using the same lsystem.py, turtle_interpreter.py, shapes.py, and trees.py files from Project 9. In the lab, this week in shapes.py and turtle_interpreter.py we introduced new field objects style and jitter, with mutator methods for both of them too.
We also had to updated several other parts of the files. We added a forward function in turtle_interperter to define the styles, as well as updated the applyRules function. In the project, I defined four different styles, 'jitter', 'jitter3', 'normal', and 'dotted'.
We also had to add objects like modval and modstring to go with the functions we copy/pasted in lab.
This is a comparison of normal, jitter, and jitter3 from bottom left to top right, respectively.
This is a comparison of the styles. Top right is a jitter square, top left is a jitter3 triangle, bottom left is a normal octagon, and bottom right is a dotted hexagon.
This is an updated indoorscene.py using a myriad of styles
And lastly I changed the sysTree.txt L-System Slightly (sysTreePP.txt). to make it have some more apples, less branches, and be MUCH taller and longer. The distance of
the tree on the right is actually coded with half the distance and still grows to be that tall.
This week in lab and while doing the project I learned about more practical uses of the field objects and being able to re use objects so efficiently. I also learned about how to change L-Systems to manipulate how a tree looks.
I worked with Stephanie and Kyle, as well as Luc Marrie.
This week the lab was a continuation of the exploration of L-Systems.
We used basically the same lsystem.py and turtle_interpreter.py files as last week, but this week we updated them to designate LSystem and TurtleInterpreter classes, as well as change the code to use dictionaries to store characters used to draw shapes and trees.
We also created a shapes.py file, which contained the classes for filled and unfilled shapes, all of which come from the mother Shape class. The shape class used the _init_ function to create fields using “self.”
The first picture is drawn by trees.py, which was created by making a tree class which was also a stem from the Shape class. It is just a basic L-System drawing with different numbers of iterations:
Here are the shapes I created:
Here is a scene of a tv and lounge area, complete with pictures of plants.
And here is a 5x4 mosaic I drew. The mosaic function was just carefully placing different shapes inside a unfilled square:
During this project I learned about dictionaries, and their use in code. I also learned how to properly place print statements in my code to allow myself to find my errors as I go.
I worked with Stephanie and Kyle, as well as Luc, Maddie, and some TA’s.
In Project 8, we used the turtle module again to explore L-Systems. The purpose of the lab was to familiarize ourselves with L-Systems by using them to draw several different scenes, as well as successfully use classes in our code. Instead of importing turtle to our scene files, we created a Turtle Interpreter class in another file (turtle_interpreter.py) that would enable us to assign turtle functions to characters in L-Systems.
During lab we created the file (lsystem.py) that included all of the functions needed to read and store L-System data in a class. These functions were basically the same from Lab 7. We also created the turtle interpreter file and class, which created functions which just call basic turtle commands. This way, all the code in our scene files can be imported from turtle interpreter instead of turtle itself.
In the drawstring function from the turtle interpreter class, I added characters like ‘L’ and ‘Q’, which draw a leaf and an apple when they appear in the L-System, respectively.
I also added turtle functions like circle to show that I can draw other shapes in my scenes besides L-Systems.
The lab basically consisted of drawing scenes using the L-Systems.
Here is the first required image: it is just basic multi-rule L-systems with strange colorations.
For my second required image, I drew an apple orchard on a hill. The flower clouds are all placed randomly, as are all the plants that aren’t apple trees.
For my third image, I drew a space scene. There are only two different L-Systems included, just with different numbers of iterations to stress the difference between growing L-Systems.
In this project I learned a lot about classes and their practical uses. I also learned more about L-Systems: there were several parts of the last lab that I messed up and was able to conquer by using them once more.
I worked with Stephanie and Kyle on this lab, as well as Luc Marrie.
In Project 7, we explored L-Systems by using the turtle module once
again. The purpose was to familiarize ourselves with L-Systems, as
well as practice strings and lists.
Much of the assignment was part of the lab. I created several key
functions in maurice.py that help to actually draw the pictures. For
example, createFromFile() takes in a file from the lsystem and splits
the lines into a list. This info is turned into a string by
In turtle_interpreter(), I wrote a drawString function which set into
place the code that would read the l_system text as functions from the
turtle module. For example:
In the lab we were supposed to create three pictures.
The first is an abstract picture:
Next an even 3x3 grid, which I chose to make rasta-colored:
And lastly a scene: I chose to do underwater.
As an extension, I threw an l-system tree in my underwater scene from
our second lab as well:
During this lab I learned about L-Systems, which I had never heard of,
and their uses not just in computer science, but in other studies as
well. I worked with Kyle and Stephanie, as well as CJ and Greyson.
In the past we have used turtle to draw pictures of landscapes using basic shapes to make more complex shapes. This week, in Project 6, we used the graphics module and the time module to create animated scenes. The complex shapes are made up of simple shapes defined in graphics.
Our tasks were to make some complex shapes to use in our animated scene and save them in multi_shapes.py. I created the following 5 complex shapes:
And one not so complex shape:
In order to animate a scene of a dance hall party:
After making each complex shape, I appended it to the list “shapes” and then returned the list in order to organize my shapes more effectively:
Then in another file (main.py) I was able to use my complex shape functions to draw and animate the scene with the draw and animate functions I wrote in multi_shapes.py. Here is an example of code I wrote to animate the guitarist in the scene:
This week I learned about the time module and its uses. I also learned how to successfully append lists, which I struggled with in the past.
I worked with Professor Kyle, Professor Stephanie, and Luc Marrie.
In Project 5, I used Terminal, TextWrangler, python, and the sys module with a module of filter functions I coded to create different collages displayed by the “display” and “graphics” modules. Last week I had created the filter functions, which change colors and add different effects to pictures. This week I edited the putPixmap function to use alpha blended color effects in order to create a collage, instead of just a bunch of pictures overlapping, as well as creating another filter function. I also created new functions that would take information stored in lists to establish image size and create the actual collage.
Here is an example of the code from the part of the function buildCollage() that allowed me to use my filter functions:
Here is an example of a list I used:
I used my functions to create this collage:
And after I used the functions to create this cover photo (this code needed an input of a picture of the user in the command line):
A majority of the work this week consisted of writing code for the collage-building functions. I learned a lot about lists. I didn’t have much of a clue about what they were and now I think I know how to successfully manipulate them to do cool stuff (like create collages!). I also learned more about assigning variables, which was a concept I have struggled with in the past.
This week I worked with Stephanie and Kyle, as well as Luc Marrie and CJ Johnson.
For Project 2, we used the pre-written display and graphics modules to show a Pixmap image of the picture above (me). I wrote a filter program in which I made a series of functions that mess with the color of images. I also created a function to designate the location of a Pixmap image through parameters, called putPixmap.
By using these filters I was able to create a collage of pictures of myself in a Warhol like painting:
I did this by first cloning each Pixmap image and then using the putPixmap function to choose the location of each new “map.” By using my filters, I could use a different color coordination on each image.
I also created a more complex collage of these flowers by using many of the same procedures.
Lastly, I created a function that would remove the blue background from the initial picture used in the lab. Code from the function is previewed below:
During this lab I learned a lot about graphics module and using computers to manipulate images. I also learned more about assigning strings of code to variable and then using these variables again later in code. I had been struggling with this concept and this could be the first project I properly pulled it off.
During this project I worked with Stephanie and Kyle, as well as two TAs named Matt and Charles. I also worked a little bit with Dan, CJ, and Luc.
Project 3 had us again using Terminal, TextWrangler, python and the simpleTurtle module. Last week we defined functions that draw a number of different regular and complex shapes, and used these functions to draw different pictures of landscapes. This week we learned about the sys module and its uses for typing code into the command line in terminal. We also scaled our shapes code and our landscapes code in order to be able to draw our scenes in multiple different sizes and anywhere on the page.
Here is a picture of three different fish tanks on one page.
Next I drew a new scene, with my old scene scaled down as a fish tank in the corner. There is a clip of my old scene out the window as well.
Lastly, I used the sys module to add a parameter to my bedroom scene specifically related to color: depending on what number you type after you call the python file, the wall background will be a different color. If you type in a number less than 10, python will draw the original bedroom scene. But if you include a number greater than 10, it will draw the bedroom with this background:
And if you put nothing in the command bar, it will draw the bedroom with this background:
During this project I learned about the sys module and its uses. I also learned about how to use conditional statements in my code to make it shorter and more efficient. Both of these concepts were new to me.
During this project I worked with Kyle in the lab, and a little with CJ Smith.
Hey all, here's my project 2. For this project, I first created a simple code that would create a house. Then, I created a code that would allow me to create 4 houses in a row, each one varying in size according to my specifications. I also created a code that would draw a segment of street. Finally, I coded a tree, then a program that would draw three trees at once according to size specifications.
Here are some screen shots:
Here is a snapshot of program of the multiple object code
finally, here is my first town, which includes the street program as well
And last but not least, here is my second town. I used the street program twice and placed 8 houses next to one another.
I wish that I had started on this project earlier and went to the TA hours, because I spent longer than I thought I would coding all of my shape programs. I would have loved to have tinkered with color fills to really make the images come alive. However, I felt as though I gained a lot in terms of further understanding turtle commands beyond basic movement functions, and that's really useful. Learning how to program shapes within code will undoubtedly save a lot of time in the future.
In our second project, A Shape Collection, we created complicated scenes involving functions that created different objects from a few functions of simple shapes. The purpose of this project was to practice creating more complicated functions with multiple parameters.
In our second lab, we were asked to create a few functions that were copied into a python file, shapes.py. One of the functions, goto(x,y), made the cursor move to a specified location of coordinates x,y without drawing. This function is central to all of the functions that draw shapes. Another function, block() when called creates a block at coordinates x,y with variables width and height. A third function, bunchofblocks() called the block function three times, drawing a pile of three blocks at coordinates x,y and at a variable scale (with 1 being the natural size.)
I then created a new python file, main.py, which would call the functions in shapes.py. To call these functions we wrote a statement, "import shapes" in the main.py file that would allow us to import functions from this file by creating a secondary data table. I prepended each of these functions with "shapes." to let python know that it is using the data table from that file.
In part 2, in the shapes.py file I created two more functions. The first function when called draws an octagon. I wrote it so that the cursor would draw forward with a variable length and then turn 45 degrees a total of eight times. The second function when called draws a triangle with a variable length on its bottom side, with angles of 80, 80 and 20 degrees.
Picture 1 shows the result of running the functions bunchofblocks() octagon() and triangle() respectively from left to right.
For step 3 in the shapes.py file, I then created two more functions which draw a tree and a building at a variable x,y coordinate and a variable scale when called. For both of these functions, a scale of 1 would draw the shapes in their natural size. The tree() function draws a triangle function over a block function that looks like a stump. The building() function calls a series of 6 block() functions to create the outline of the building, windows and a door, as well as an octagon() function that serves as the door handle.
Picture 2 shows the result of running the tree and building functions at their natural size (scale = 1.)
Part 4 of the assignment required us to create an outdoor scene by calling the functions that we made in steps 2 and 3. For this scene, I included four tree() functions, two building() functions and an octagon() function in a new function, town1() all at coordinates that were placed in the parameters of each function. Different values for the "scale" parameters were used.
Picture 3 shows the result of running the town1() function: a drawing of a familiar town.
In part 5 of the assignment, I created a function that draws a scene of the inside of a restaurant with booths. For this function I had to create a few more functions in the shapes.py file. I created rightchair() (a right facing chair), leftchair() and table() functions which draw a series of rectangles with the block() function. A light() function used the block() and octagon() functions. When called, it would draw a japanese style light. A divider() function was used to separate the tables. Another function, diningset(), incorporated the functions that draw a table, a right facing chair, a left facing chair, a divider and a light when called. This function used a scale parameter where 1 is the natural size. In the main.py function I called for the diningset() function four times to create an image of four booths in a restaurant.
Picture 4 shows the result of running the town2() function.
I combined two extensions by making a new function town3(), which replicated the town2() function and added random colors and widths to each object. To make the function randomly color the objects, I imported the random functions by writing the command "import random" in the beginning of the shapes.py file. I called for random colors by generating a random integer from 1 to 7 by writing the command "random.randint(1,7)." I then used the "if" statement to call for a color that was assigned to an integer from 1 to 7.
This snapshot shows the commands that I used to generate an integer that corresponds to a color for each object.
I used another "if" statement to determine the thickness of the pen. If the random integer from 1 to 7 were greater than 3, then the pen would be 5 (times the "scale" parameter) pixels thick. I used the "else" command to set the width of the pen to a length of 1 pixel (times the "scale" parameter) if the random integer was less than or equal to 3.
Picture 5 shows the extension that involves using random colors and widths.
By doing this project, I became comfortable with using more complicated functions with multiple parameters. Also, I gained a familiarity with new commands involving random numbers and conditional statements.
-The goal of this project was to create different line styles that could be used to make more interesting shapes and L system images.
-In task 1 the object was to make lines that were broken in the middle. In order to do that I had to first regenerate values that saved the position of the turtle at various points using a gaussian distribution. Then I had to find the midpoint of the segment and then draw the line to the midpoint that is broken up by the values generated. The picture generated by my TaskA.py simply called three triangles to draw using the styles: 'broken', 'normal' and 'jitter' in that order.
Then I had to create a dash line style that could be used in a shape. So, I added an if statement to my interpreter's forward function. In order to create the dashes I first divided the distance by the dashlen to get the number of dashes needed per length. Then I saved the starting position and looped through the dashes. I looped through the dashes only half of the dashes because in my loop I had to go through the two dash lengths. I had to put the pen down and draw a dash and then pick the pen up and go forward by a dash and repeat that. Then I needed to put self.dashLen in my init function and create a dash method in my interpreter in order to set the value of the dashLen. Then I had to go to my shapes class and enter in a self.dashLen in my init function and add a setDash method that applied the dashLen. Then I added a triangle to my previous drawing in order to display my dash:
I then decided to take on the extension of creating more linestyles that I could apply to my shapes. I created an if statement in my interpreter that called for the linestyle 'parallel'. In this linestyle I took the original lines of the shape and added a second line parallel to it in a different color. In order to do this I first drew the line normally and saved the position. Then I went back to the starting position, turned right 90 degrees went forward by a dashLen and then turned and drew a second line. Then I went to the ending position of my original line and continued my shape.
Then I tried to create a shape that looked edgy because it had a dashes line around it. I created a loop like I had for the dash linestyle and went forward by a dash and then turned 90 degrees and went out by a dash and then turned 90 degrees and went back in and went forward again.
The last linestyle I created looked folded over. In to do that I used the edgey for loop, but I took out a few turns and it created a foldover look. The shapes I created looked like this:
The foldover is the bottom left, the edgey effect is the bottom right and the parallel effect is the bottom middle.
Then I had to add the linestyles I created to my scene from last week. I applied my parallel effect to the picture frame, my broken effect to the house and the dash effect to the roof of the house. Then I used jitter on my sun because I thought it gave it an abstract look.
-Lastly I had to create my own parametrized stochastic multi-rule L-system (system1.txt). This was very hard because I had to include a replacement strings. I sort of used the L-system model from class except I modified it a good amount and left out the last two rules.
One from class
rule F (50) f [!(30) -F<g(5)L>][!(40)+F<g(5)L>]!F
rule (x)f (1.5*x)f (1.25*x)f (1.7*x)f
rule (x)- (x*1.2)- (x*0.8)- (x*1.05)- (x*1.0)- (x*0.95)- (x*0.87)- (x*1.12)- rule (x)+ (x*1.2)+ (x*0.8)+ (x*1.05)+ (x*1.0)+ (x*0.95)+ (x*0.87)+ (x*1.12)+
rule F (20)f[!(10)-F<(10)L>F(10)][+F(10)!<L>F][!(10)-FF<L>+F(10)][!(10)-F<L>+F(10)]
rule (x)f (.85*x)f (.95*x)f (1.05*x)f (1.15*x)f
rule F (20)f[!(10)-F<(10)L>F(10)][+F(10)!<L>F][!(10)-FF<L>+F(10)][!(10)-F<L>+F(10)]
rule (x)f (.85*x)f (.95*x)f (1.05*x)f (1.15*x)f
Mainly, I thought I wanted to make a shape that looked like bushes. So, I added leaves to the middle of each branch I made and had four different replacements for f. In the end it came out looking more like feathers than a bush, so I went with it. I used the broken linestyle on it and then uses the sysTree2.txt to create a tree utilizing the 'edgey' linestyle.
-I learned about how to create multi rule l-systems using branches and having multiple replacements.
For this project, we were to make scenes out of complex objects made of primitive Zelle graphics objects. We were to take these objects that we created and put them together in some way to make a recognizable scene. After that, we were to animate our scene in some way.
To make my scene, I first made three different python files. Each file would become one of my complex graphics objects. This time, I made a car.py, house.py and road.py. Each of these files had an init function, an animate function, and a test function to make sure my code worked as I had intended. To make a car, I used rectangles for the body, hood, and windows, and circles for the wheels. My init function created the shapes for the car and placed them in the right place. After it created them, it added them to a list which would keep the shapes together to look like a car; this would be especially helpful when I started to animate my car. Next, I wrote my animate function. This function looped through all the parts(shapes) of my list(whole car) and moved them forward. Because they are in a list, they all moved forward together, putting the car into motion. I passed the move method the parameters -10, 0 so that it would move to the left, the direction that I built my car to be facing. Once my car was built and moving, it looked like this:
Next, I went on to make the road that the car would travel on in my scene. To do this, I made a long black rectangle that would fill up the whole width of the window so that it looked like a road that was coming and going from both sides. ?After making the rectangle, I made another very thin rectangle to be the yellow dividing line for the road. This shape did not need any animation for my animate function simply contained a return statement. In the end, the road looked like this:
After making the road, I made the house which consisted of a square, a 3 sided polygon (triangle), and smaller rectangles for the windows and door. My init function made all these shapes and placed them in the right place. After, it colored each thing to look nice and fit in with the house. The house also did not need to be animated so its animate function simply contained a return statement. The house looked like this:
After making all of the individual complex shapes, I started to make my scene.py file to make my scene come together. To do this, I first made an init method which made an empty list, then added 3 house objects, a road object, and a car object to the list. Each specific object's init function was used with specific coordinates to put everything in the right place to make the scene recognizable. In the end, the function returned the list of objects. Next, I made a draw function. The draw function looped over each part of the list of objects which contained duples. It would look at each duple and use the aggregate.draw() function to draw the second object of each tuple which was the object itself. After the draw method, I made the animate method. This method took a sceneList as a parameter, looped through all the tuples in the list and if the first element (which said what kind of object it was) was a car, it used the car's animate function, if it was a house, it used the house's animate function, and if it was neither of those, it must have been a road so it used the road's animate function. When that function was complete, it made a scene that looked like this:
After the scene.py file, I made a scene2.py file. This file contained only a main() function that made multiple copies of my scene in different locations and different sizes. This main() function used scene.py's init function to make a scene with specific parameters, then did it again using different parameters therefore making two different versions of the same scene. Then, it entered a loop which moved each car a certain number of times. To be creative, I made the first car move only 10 loops forward then park, and the second car moved off the screen but at a slower pace. That scene looked like this:
Once again, I tried to use the eval() function instead of using if statements, but this time was not able to figure out how to get obj to be simply the text it represents and not a string. When saying eval(obj.animate(obj,0, None)) obj returns a string. I wanted to figure out how to make it use the letters of the string to represent what function to call, but was unsuccessful.
From doing this project, I learned how to make complex shapes out of primitive objects. I also learned how to use the time package to help me animate drawings. This was the first time I was able to create a scene that I was proud of without having to make what felt like a million turtle commands. I realized how helpful the Zelle graphics package can be when trying to make complex shapes and scenes.
For project three, we were to edit our code from our Colby scenes from project 2 to take advantage of looping and add parameters. We added parameters such as scale and fill to determine whether the shapes we were drawing would be filled or not. This also allowed us to make multiple scenes in different places and different sizes. Finally, we took advantage of command-line arguments so we could control our code from the command-line itself.
To complete the project, I first edited my block function to take a fill parameter. To do this, I copied my old block function into a new file and edited it so that if I passed it a True parameter it would fill the block. I then added another parameter that would take a color to fill the box with. I decided to code it so that it could receive either an r,g,b value in a tuple or a color name in a string. To do this I simply made the parameter one value which would allow either a tuple or a string. Next, I did the same thing with my simpler shapes. I had already taken advantage of loops wherever I could, but I added the color and fill parameters. In doing that, I had to use if statements that would see if the shapes were supposed to be filled or not. If they were, fill evaluated to True and it would make a shape filled in by that color. If fill evaluated to False, the else statement would run and turn the turtle black and draw an unfilled shape. After that, I edited my original scene to accept a fill parameter with colors and to take more advantage of looping. I made it so that things could either be filled or not. If they were not filled, the turtle would make everything black. If they were filled it would fill the trees brown and green and make the library whatever color was passed to it. I then made a compose1 file which drew multiple versions of my scene and ended up looking like this:
After that, I made a file Compose2 which put my scene inside a window that was on a blue wall. To do that I set the background color to blue, drew a white box, drew panes on the box, then put my scene in the box making it look like a window. It ended up looking like this:
Finally, using sys, I edited my original scene to take its parameters from the command-line. First, I entered the parameters 10, 20, and 0.5 for the X, Y, and scale parameters. It looked like this:
Next, I entered the parameters -50, -20, 1.5 as the X, Y, and scale parameters. It looked like this:
From doing this project, I learned about command-line arguments which I had been wondering how to do anyway. I was glad to get a chance to use them in a practical setting to write code that wouldn't have to be edited every time I wanted to change something about how it runs. I also polished my skills with using variables to make functions have the ability to be changed in order to make them different sizes based on some scale.