# Pages Home Zena Abulhab CS151 - Computational Thinking: Visual Media Zena's CS151 Project1

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Version 14

These are the tools we use.

For this assignment, we were using the Python programming language through TextWrangler to make basic shapes using Python turtle commands. The turtle takes basic commands like "forward (100)" which tells the turtle to draw a line 100 pixels long in the direction it is currently facing, and "left (90)", which tells it to rotate 90 degrees counterclockwise. This assignment introduced us to basic Python code, such as "from turtle import *", which allows us have access to all of the commands the turtle can be given.

In class, I made a square and a hexagon. For the remainder of the project, I created a cross, an "L", and a repeated shape. To start off all of the shapes I made, I first had to call the turtle using the Python command "from turtle import *", which allowed me to access all of the turtle commands, with the asterisk representing "all." The last line of code was always "raw_input  ("Press Return when ready"), or something similar, which prompts the user to press the return key to close the turtle canvas; otherwise, the drawing would disappear very quickly, making it hard to see.

To design the cross (shapeA), I followed the same general pattern of the square-making code, except that instead of turning left all the time, the turning pattern would be left-left-right, which makes the turtle constantly draw three sides of a square, but never fully close it, instead linking it together with others of its kind. Designing the "L" shape(shapeB) was similar, except that I closed off the shape instead of continuing with the left-left-right pattern and I had different "forward" values, which means the sides had different lengths.  For task 5, I combined shapeA (cross) and shapeB (L) into one shape called "ShapeC". I first defined the shapes using the "def" function, e.g. "def shapeA():" and then started typing in the instructions for the turtle below, but indented them one level. By doing this, and using the "def" function, I prevented shapeA from being drawn unless it was told to. I did the same for shapes B and C(which was a call to draw shapeA, move forward 100 pixels, then draw shapeB), then at the end, I called shape C by simply typing in "shapeC". For the last task, I added in a "shapeD" to the previous file, and used a "shapeE" function to call it. Shape D had a variable called "distance" in the parentheses, so I left the "forward" functions defined not by a number, but by "distance". Shape E was used afterward to plug in four different values for the "distance" variable: 100, 80, 60, and 40.

For this project, I did extensions 1 and 3. For extension 1, I defined shapes A, B, and C, and made a function called "callall" at the end that called A, B, and C and drew them all together, then called that function. For extension 3, I made a set of instructions that calls a square, then made it repeat twice by starting with "for i in range (2):", which makes a square twice (the number in the parenthesis is the number of times the instructions are followed.

In this project, I learned how to use the python turtle commands, like "forward", "left", and "up". I also learned how to use indentation in Python to change what I want the code to do, and also how to repeat a set of instructions multiple times.

Labels
• No labels