## Computer Programming Turtles and Stick Figures

August 22, 2014

by Lindsey Serio

Python Turtles in WingIDE

Students started the day by discussing what they learned in Python the previous day. This helped the writer to understand the concepts without being totally lost! Teacher Andy asked what functions campers learned yesterday. Some of the things they learned was how to move the turtle in a circle:

turtle.circle (30)

The parenthesis contains what is called an arguement, which dictates in more detail what the turtle should be doing. In this case, the turtle should move in a circle with the parenthesis decpicting the radius of the circle. Here are some more examples:

turtle.right(90)
turtle.left(100)

This code dictates that the turtle should move left or right while the number inside the parenthesis (or “paren”) dictating the degree of the turn.

turtle.color(“red”)

Teacher Andy explained that “red” was not defined to the program so the program would not understand what we meant.  By putting the word in quotes it would reference the color number and produce red for us. We talked about how the turtle would make a black line all the way up until it read the word “red” because the program read from left to right.

turtle.speed(0)

For some reason in Python, zero is the fastest speed. Teacher Andy then went over how to repeat certains sections of commands so that you didn’t have to re-write it for every turtle:

For i in range(4):
turtle.forward(10)

Then he asked the class “How many turtles are on the screen at once and how can we issue commands to one turtles instead of the entire group?” The campers responded that there were four turtles (shown in command above) and that we would have to tell the program what we mean by only one turtle. This means that we can differentiate them by number or by naming each turtle. In the shell of program, campers typed:

alex=turtle.Turle()

This named Alex as one of the turtles. The campers then named all of their different turtles, which was more fun than just calling them turtle.Turtle and then gave them directions using the arguments they learned yesterday:

betsy.backward(100)
for i in range (30):
alex.foward(5)
alex.right(10)
betsy.forward(5)
betsy.right(10)

Teacher Andy then showed them how to make the turtles move into a spiral formation:

betsy.right(90)
charles.right(180)
dennis.right(270)
for i in range (100)
alex.forward (3+i)
betsy.forward (3+i)
charles.forward(3+i)
dennis.forward(3+i)
alex.right(15)
betsy.right(15)
charles.right(15)
dennis.right(15)

See the spiral below:

The campers then learned how to add an element of randomness to their turtles. It was fun for them to watch and see where the turtles might end up. This was represented by the following code:

for t in turtle.turtles
t.forward (1+random(D*3)
t.right(random()*60-30)

Then they assigned colors to each of the turtles:

alex.color(‘red’)
betsy.right(90)
betsy.color(‘blue’)
charles.right(180)
charles.color(‘green’)
dennis.right(270)
dennis.color(‘yellow’)

After that, Teacher Andy taught the campers how to track how long the program has been running. He explained the logic behind the code by talking about the terms used in the code. The argument that would be used would be the term “print.” The term comes from the fact that in the 70s computers used to “print” on punchcards to mark the passage of time. Andy demonstrated this by typing print ‘sup’ in the Python shell and having “sup” show up on the screen. He then typed:

a=0
print a
a=a+1
print a

He asked the campers to work out what would print on the screen. In the first two lines, a would equal zero. In the last two lines we have to remember the the computer reads right to left for formulas, so it would add A to 1 and print 1. By that logic…

a = 0
print a
for i in range(100):
a=a+1
print a

The computer will then repeat everything 100 times while adding 1 each time. The shell started printing 1…2…3…all the way to 100. This will keep track of how long the program is running, Andy estimated it to be about .3 milliseconds. In the console they programmed:

for t in turtle.turtles():
t.forward(1+random()+3)
t.right (random()*90(45)

Processing

The campers were eager to move over to Processing. They opened up the program and Teacher Andy explained that there was no shell for this program like for Wing IDE. The errors would be displayed at the bottom of the screen. They started with the bare minimum needed for processing to work:

void setup() {

}

void draw() {

}

Andy explained that we would be putting code inside of setup and draw inside of the curly brackets. He had campers type the following:

void setup () {
size (500,500);
}
void draw() {
rect (100,100,100,100)
}

I have marked the code sections in colors to make it easier to explain. In the red section “size” denotes a function. The 500s represent the size the we want the window to be. You can input this to be the size of your computer screen but Andy chose 500 to make it easier to switch between the output and the processing program. This code will make a screen pop up in 500 X 500 pixels. In the blue section we told the computer to create a rectangle. The first and second hundreds will move the rectangle along the x and y axis. The third hundred is the width of the rectangle and the fourth hundred is the heigh of the rectangle. Andy explained that x and y are opposite in the computer programming world from what campers learned in math class.

The campers then re-wrote the code for an ellipses instead of a rectangle and discovered the for a rectangle the coordinates are determined from the top left corner whereas with an ellipses they are determined from the center of the ellipse.

Next, campers went over how to code for a line. A lot of discussion was had about how many points a line had and it was discovered that there would be two points for the beginning of the line and two points for the end:

void draw() {
line (100,100,200,300)
}

To move the top point to the right you would use the first argument, say 300. To move the top line down you would change the second argument, say 200. Campers learned to design the arguments of the line function as:

line(x,y,x,y)

But they needed to distinguish between them so we know that they are two different sets of coordinates:

line(x1,y1,x2,y2)

One of the campers asked how many arguments were needed for a triangle. They figured out:

void draw () {
triangle(0,0,300,100,100,300)

There is a coordinate for every point of the triangle.

Stick Man

The big project for the day was building a stick man based on everything the campers had learned about shapes and coordinates. Some of the younger students were learning advanced fourth grade math! Teacher Andy began the project by sketching out a simple stick figure in paint and asking the campers to describe the image. Here’s what they came up with:

1) A line for the body, drawn up and down, perfectly vertical.
2) 2 diagonal feet, starting at the bottom of the body and going outwards.
3) A circle at the top of the body. The center of the head is perfectly aligned with body vertically.
4) Arms going straight across the body, perfectly horizontally.

The campers talked through the paint image, mapping out coordinates for each point on the stick figure. Here’s what they came up with:

void draw() {

(body) line(100,150,100,450);
(left leg) line(100,350,50,450);
(right leg) line(100,350,150,450)
(arms) line(50,250,150,250)

They had to define everything to the computer in order to get the output to be a stick figure. The campers learned that humans are not like machines in that if you told a human to draw a stick figure each figure would be a little bit different and this is what is wonderful about humans. What’s great about computers is that you have the ultimate control in depicting your unique stick figure. Campers wrapped up class by modifying their stick figures to their liking.

## Adding Color and Texture to 3D Models

August 14, 2014

by Lindsey Serio

In our 3D Animation Camp campers have been learning how to add color and texture to their 3D models. A texture is an image added to the face of a 3D model. It can give life to an object or character by giving them light, color and depth. Check out a video of another one of our students animations here.

First, campers learned how to add color to their 3D Model by coloring individual faces on the model. A face is any flat surface on a 3D model, typically the outside surface of the object.  Campers had the option to use either the monkey object or just a plain sphere.

The campers had already learned how to add solid color by utilizing the materials tab located on the right side of the screen. Under the materials tab was a list of paints the monkey was using. Teacher Joe explained the process of coloring as adding paint to a palette. They chose the option “+” in the dropdown menu and typed in the name of their new color. The default name for the new material is “material” so Joe re-named it “red”. He clicked the white box located below the material list to bring up the color wheel and selected a red.  He added another material and named it “green.” The campers then added their own two colors.

Teacher Joe explained that by default Blender pulls the first color on the material list and ignores the rest. He had the campers go into Edit Mode and then Free Select Mode. They deslected everything and then he clicked a face on the monkey’s eye. He pressed shift and right click to choose multiple faces at once. He selected the Monkey’s entire eye. He then left clicked the Green material and left clicked the option Assign that was right under the materials list. This created a laser green-eyed monkey! The campers then had a great time adding more colors to their models; some had bloodshot monkey eyes, some monkeys had unicorn horns, etc. Teacher Joe reminded them that they can use subdivision surfaces to put more colors on their models. Subdivision surface is a modifier within blender the multiplies the number of faces on a model.

To introduce the concept of adding textures to models Teacher Joe had to first explained what the process is actually called; UV Mapping. It means to take a 2D image and wrap it around a 3D model to give it shape and texture. He showed a jpeg file of a Minecraft skin as an example.

If you cut the minecraft skin out and folded it on certain edges it would turn into a 3d Minecraft character, kind of like paper dolls. The camp then opened a new file and inserted a cylinder object into their file. Joe showed them the textures that they would be working with, five different images of unwrapped barrels. These 2D images were going to be wrapped around their cylinder objects in Blender. Teacher Joe urged the class to think about what the cuts on the texture would look like. The camp explained the cuts as two rectangular cuts for the sides of the barrel and two circle cuts for the top and bottom of the barrel.

Back in Edit Mode the campers moused over to the Sharing/UV tabs on the bar on the left side of the screen. They then marked the seams that would indicate to Blender where to cut and where to flatten the 2D barrel image that they were going to import onto the cylinder. They selected the cylinder’s circle as a flat edge by using ALT plus right click on the mouse. They then clicked “marked seam” on the left bar to bring up a red line around the edge of the top and bottom circles on the cylinders.

Teacher Joe then brought up the point that if we imagined the cylinder’s circles coming off the model and flattened the remaining piece, what would the issue be? A camper pointed out that the ends of the cylinder are still stuck together. It would have to be cut so that it is not a closed loop or we can’t apply the texture. The campers then selected one edge on the cylinder to unwrap and then selected the “edge select” icon at the bottom of the screen. They selected “mark seams” plus the A button to bring up a red indicating line. Now that the cylinder was properly marked the texture would cut and flatten properly to it.

Now the campers had to flatten and put the texture onto the cylinder. They split the screen into a 3D view of the cylinder on the left and a 2D view of the texture on the right. Each camper chose between five barrel textures: a dark wooden barrel, a light wooden barrel, two barrels with “explosion” markings and a barrel marked “dino oil.” The students then uploaded their chosen texture to the 2D side of the screen.  After that was done they pressed A to select the whole texture and U to unwrap it. White lines appeared to indicate one the texture where it had been cut and unwrapped.

Campers then went to left hand side of the screen to apply the texture. They simply selected their texture from a dropdown menu. They could now all see their texture on their 3D model.

INSERT 3D MODEL W/ TEXTURE

The white lines on the left side of the screen indicated where it pulled the texture from.

The campers then realized they couldn’t really see their 3d object very well. Teacher Joe showed the campers how to duplicate the one light the existed on the 3d model into a bunch of lights placed all around the model like a constellation of stars. Once the object was lit up it was obvious that the texture wasn’t lined up properly on the cylinder. The campers went into island select mode so that they could grab the white outlines on the texture and move them to the appropriate areas.  They also scaled on the x and y axis to make the indicating lines bigger or smaller depending on what they wanted to show up on the barrel. Teacher Joe informed them that only what was inside the white indicating lines was what was going to be used. Lastly, they scaled the textures containing text along the x-axis in order to flip the image over and make it readable.

## Coding New Tools in Minecraft!

August 8, 2014

by Lindsey Serio

On Wednesday this week campers worked on programming new tools into their Minecraft Game. There are many details involved in programming the tool, from dictating the qualities the tool will have to how to make Minecraft recognize it as a tool.

First, under the Materials section of the campers code campers coded the attributes or qualities of the new tool such as how much damage it does. We expressed the with the following code:

StaticToolMaterial fireTool=EnumHelper .addToolMaterial “fireTool”, 2, 1500, 14.0F, 10.0F, 30.

“ToolMaterial” resulted in and error, we had to choose from the drop down menu after left-clicking on the error. We chose “Import Tool Material” and this fixed the error. The section in quotations, “fireTool” stands for whatever the name of your tool is. For example some students named their tool “bananaTool” or “waterTool.”

Let’s go through the code piece by piece so we can understand it a bit better. The number 2 in the code stands for the tools classification. Zero stands for wood, one stands for stone, two stands for iron and three stands for diamond. We used the number 2 for iron. The 1500 is the max number of uses before the tool breaks. 14.0F stands for how fast it will break blocks. To give you an idea, diamond breaks blocks at a speed of 8.0 and gold breaks blocks at a speed of 12.0 so our input will breaks breaks pretty quickly. 10.0F  is the amount of damage the tool will do. Diamond is 3 and gold is 0. This amount of damage will change for each tool you have, which is the definition of a modifier. The last number, 30, is an indicator of how easy the tool will be to enchant. The higher the number, the higher the enchant ability of the item.

Next, we went into our New Items section to write the code for the new item. The previous section dictates the actions the tool will take once used but this section makes the tool available for use. Campers coded the following:

//NEW ITEMS

public static Item firePickAxe = new My PickAxe (“firePickAxe”, fireTool);

This code tells Forge to utilize the custom pickaxe. The last thing campers did was something called “registering” their code. This is the second piece that helps the game turn the code into a usable item:

GameRegistry.registerItem(firePickaxe.getUnlocalizedName

Campers finished up by working on their textures in Paint.net. We hope to see you in Minecraft Hacking Club this year for more in depth Minecraft modifications!

## Robotics Camp Uses Color Sensors

August 1, 2014

by Lindsey Serio We have been having epic amounts of fun in our Robotics Camp. We dove into color sensors on Thursday. The students worked in the Lego NXT program to graphically code directions for the robot to take. The program they are working on looks something like this: Students drag block pieces out from […]

## Our Second Jr Minecraft Camp!

July 31, 2014

by Lindsey Serio We were stoked to hold our second Jr Minecraft Camp for campers 6 to 8 years old! A few observations from our Jr Minecraft Camp Davey learned from Teacher Josh that using an anvil to break down resources with also break down your tools. You can find name tags in dungeons. Our volunteer, […]

## An Introduction to Web Design

July 25, 2014

by Lindsey Serio In Fab Lab Camp this week we covered a subject that we haven’t covered in quite a while: Web Design. We gave students a 3 hour introduction to the basics of html completely from scratch (no help from wordpress or anything else, just bare coding) and they caught on super quick! Here’s […]

## Why Coding Matters.

November 2, 2013

by Andy Stoller I don’t think there’s anyone left who honestly thinks that computers are still just a “fad;” Ken Olson, president of the now-defunct company Digital Equipment Corp said, in 1977, “There is no reason anyone in the right state of mind will want a computer in their home.” What Ken lacked in foresight, […]

## Introducing our new Engaging Technology in Education Meetup

October 15, 2013

DETAILS: Day: October 16th is our first Kick-off meeting Place: MakersFactory space in downtown Santa Cruz, 877 Cedar Street, Suite #122 Time: 6:30-8pm Cost: FREE! Includes light supper! Sign-Up: Email krissie@makersfactory.com to reserve your spot today. Space is limited. The Engaging Technology in Education meetup is a forum to bring local Santa Cruz County educators […]

## First Friday 4 The Girls

September 27, 2013

It’s time for another evening together to celebrate that sweet spot where art and technology merge. For Santa Cruz’s next First Friday on October 4th, we’ll be featuring award-winning art educator Kathleen Crocetti, a local community mosaic muralist (her students’ work is displayed on numerous Santa Cruz bridges) and creator of the fashionTEEN event. The […]