Programming Project

Back to Home

Programming in NetLogo

What it looks like:



Here you can see the

What it makes:


This is a circle obviously. This was made by making the turtle move forward a little bit, and then making it turn a turn a little bit.


This was made using my polygon button with an adjustable number of sides.


Making the full flower was the hardest to approach, but after I understood how to make one petal, the rest was easy.

Making a micro-colony in NetLogo


Using Logo I made a simulation of a colony of turtles eating their food source, which grows back, and reproducing. If the turtles did not eat enough, they would lose energy and die. A healthy grass grow-back to turtle population could be obtained and the number of turtles would not increase or decrease dramatically.

This is the code to make the whole thing work:


In the code you can see the individual blobs of code, each with a function such as the turtle moving or grass grow-back. Learning Net Logo was a good first step into learning Python. You can do similar things in the two programs such as make different shapes


Programming in Python



Number guessing game!


To get introduced to Python, I created a number guessing game which will have the user guess a randomly generated number ranging from 1 to 10

The code:


If the user guesses too high, the program will prints "No. Lower", likewise if the user guesses too low, the program prints "No. Higher".
If the correct number is guessed the program will print "You got it!". Also, if the user guesses 3 times and does not guess the number correctly, the program will print "Too many guesses". This can of course be altered to allow more tries by changing the "<5" to a larger number.




Like all other programming languages, Python includes conditionals and repeats. One other thing it includes that is utilized in the number guessing game is user input. User input can be seen as "raw_input" in the code.

Conditionals and Loop:

So long as the user has guessed less than 5 times the conditions underneath will be carried out. Note that "Elif" stands for else/if

Raw Input

When a user types anything and gives it to the program to use is raw input. When the user is asked their name in the number guessing game, that would be raw input. When the user inputs numbers in the game that is also considered raw input

Fractal Images


Much similar to the work done in Net Logo, in python I made squares, circles, and other things. The most interesting thing is the star fractal images though. They could be set to be made at any size and looked quite interesting.
Here is just a simple star:





All that the turtle is doing is going forward, turning, and repeating that process until a full 5 pint star is made.
An addition to the code of the star can be made to allow a much more elaborate fractal image to form.





This is the code to make the fractal star work. While it may not seem like a whole lot of code, it will make any size fractal star you tell it to. Custom size can be put in by the user when they run the module and type in "star2(length, level)" except they would replace the length and level with their own numbers such as 100 and 4 (what I used to make the fractal star shown here).

Home


Programming in Processing(Yes, That's what its called)


The first thing that we did in processing was create a smiley face. To do this we had to search up how to create different shaped such as ellipses(circles), arcs, and lines. Using these three things I was able to make a smiley face. I had to pay attention to things such as the size of things and the location of them which we could control by setting their x and y coordinates. Setting the x and y coordinates was tricky because the origin of the plane is in the top left of the window and not in the middle as everyone is used to.

Here is the completed smiley face:

And here is the code that I used to make it:

In my code I implemented a function where the user could set the coordinates of where they want the the face to be made and the face would be drawn at that location. I had to individually set each of the features to move in tandem with the main circle of the head by doing some basic addition and subtraction.

Later on in the day we made the faces follow wherever the user's mouse was on the screen and it had some interesting result.


Luckily the makers of programming implemented a function to make it simple to do this (mouseX,mouseY)

To make this even more interesting, I made the face bounce and made it change colors at the same time.

This is what it looked like when I combined bouncing and color changing. To make it change color this is what I put into the code in the fill section:

This would set the color or fill to change as time progressed making a pretty cool bouncing smiley face.