CS151 HW#3

Tara Davidson '10

Write up:

  1. A brief description of the task (in your own words): In this task, I created more shapes in addition to the shapes I made in lab to create an image of a handful of shapes in a horizontal line. In addition, I simplified my call to the function so that each shape could be called by a given character and could be called in a string of characters, such as: processString('lst'). This required the use of "for" loops, as well as if, elif, and else statements. My first 3 shapes were a line, a triangle, and a star. I imported the shape functions into linear.py to create sceneA:
    Picture of sceneA.py:


    After I created sceneA, I created grid.py to create a grid with 10 columns of shapes. This meant that after every 10th character in my processString() a new row of shapes had to be created. I did this by using modulus so that if every character in my string was assigned a number according to it's position in the string, then if that number divided by 10 had a remainder of 9, a new row was created. To do this, I had to create another "for" loop and use more if, else statements.
    Picture of sceneB.py:


    The final part of the project involved incorporating a partner's shapes into my linear.py so that I could call her shapes into my scene of a horizontal line of shapes. I sent Alyssa my own shapes via an email attachment and she sent me hers, too. She used a different width with her shapes and spaced her shapes differently than mine so I adjusted my scene so that all the shapes where of similar thickness and spaced better.
    Picture of sceneC.py:


  2. Provide the english description of the grid drawing algorithm: 1) Create the window for the turtle and move the turtle to the far left of the screen. 2) Count the length of the string. 3) For each character in the string draw the shape. 4) If the character in the string is not the 11th character in the row, move the turtle over 20 pixels so that the next shape can be drawn in the string. 5) If the character in the string would be the 11th character in the row, pick up the turtle, move it back to the begininning of the row, turn it right, move it down, turn it right, put the turtle down and then draw that shape.
  3. Explain your algorithm and why it works: I created a window, and used the goto command to move the turtle to (-200,0), the far left of the screen. Then, I used an outer "for" loop. My loop started with: for i in range(len(string)): so that the length of the string was calculated and each character in the string would be executed by using range. Within the loop, my first statement was to draw the appropriate shape according to the letter in the string. Then, I used "if" and "else" statements. If: the 10th column was not filled, I shifted the turtle horzontally right. Else: if the 10th column was filled, I shifted the turtle vertically down by picking up the turtle, moving it back to the beginning of the row, turning it right, moving it down, turning it right, putting the turtle down and then drawing that shape. Then I called the function.
  4. EXTENSIONS I did Extention 5 and added colors to all my shapes. I used structured colors by using: color(red, green, blue) and putting values between 0.0 - 1.0 for each shape. This extension was put in my tsdavids_shapes.py file. I also did Extension 2 and extended the conditional to allow for more shapes that I created. I created blue/green square shape as well as a a brown tower shape. These shapes are also in my tsdavids_shapes.py file. I called my square with 'q' and my tower with 'o' in my string. My additional shapes can be seen in sceneD:
    Picture of sceneD.py:


    The other extension I did was Extension 3, working Alyssa's shapes into my grid scene. I did this by calling her shapes by capital letters and inserting those capital letter calls in my processString() in my grid2.py file. Scene E shows this grid:
    Picture of sceneE.py: