Wednesday, June 17, 2015

Bouncing Ball!

Today I will be changing this code (by Seb Lee-Delisle on Open Processing) This code prints a program that has a ball bouncing and its speed and height changes realistically like a ball.  

The first thing we are going to do is clean up the code and change the double slashes (//) to pound signs (#) Now we are going to change void setup(){} and void draw(){} to def setup (): and def draw (): and delete all the semi colons and curly brackets. Next we are going to add colons after all the if statements. Next we are going to delete the word float every time it appears. Next we are going to delete the else form the last if statement. Now we are going to change  void mousePressed(): to if (mousePressed): Now we are going to change the double lines in this statement; if ((x > width - w) || (x <= 0)): to the word "or" Now we are going to add 
  global x 
  global y
  global w
  global h
  global speedY
  global speedX
under def draw (): 
Your code should look like this:


Your code should should successful print a program that shows a bouncing ball.


String of Random Circles!

Today I will be changing this program (by Cater Beeman/Karsten Weiss on Open Processing) to Python mode. 

As usual the first thing we will do is change void setup(){} and void draw(){} to def setup (): and def draw (): and get rid of all the semi colons (;) and all the curly brackets ({}) and add colons (:)next to all the if statements. Now get rid of the word float and the word break, as we do not need use these in this case in Python. So far your code should look like this:



Now we are going to get rid of the lines of code; switch(key) and case 'c': and instead put in  key.lowcase == "c" Your code will look like this: 

When you run it you should get a program that draws something like this (when you click and drag the mouse): 


Monday, June 15, 2015

Random Lines!

Today I will be converting this code (by Tara Milani on Open Processing) This code prints out a program that draws a bunch of lines or random sizes and colours all starting at the same point, its a very easy code.  All we have to do is change void setup() { } and void draw() { } to def setup (): and def draw (): and delete all the semi colons (;)  Your code will look like this:



Your program should draw random lines, looking something like this (but ever changing): 



Friday, June 12, 2015

combineCircular!

Today we will be converting this program by tara milani on open processing from java to python. This program uses math to draw a series of ellipse to make a pattern. 

As usual the first thing we will do is change void setup(){} and void draw(){} to def setup (): and def draw (): and get rid of all the semi colons ( ; ) Next we are going to get rid of the word float everywhere it appears, we d this because we do not need a float to declare a variable in python. So far your code should look like this:



 Now, right under def draw (): we are going to add global a (new line) global b (new line) global y (new line) global x We do this because in python when a variable is called in only looks for the variable under the draw function, but by adding global it knows to look outside the function. Your code should now look like this: 





Now you're done, your code should print out a program that draws a series of circles into a pattern. 



Thursday, June 11, 2015

Parabola!

In this tutorial I will be changing this code (made by 유창희 on open processing) to python from java. This code prints out a program that draws a parabola using math functions.   

First things first, we are going to change void setup(){} and void draw(){} to def setup (): and def draw (): Than delete all the semi colons and 
indent everything following our setup and draw functions. 
Than we are going to change float angle, y; to angle = 1. We do this because in
python we d not need to declare these as floats, we only need to set a value to angle. 
Than we are going to add global angle right under  def draw (): We do this because 
in python when we add angle into the math function it is only searching for angle in the 
def draw (): function, but by adding global angle it knows to look outside the function. 
So far your code should look like this:     



Than we are going to change the color codes for background and fill to RGB codes. background will be background(255,248,237) and fill will be fill(255,149,149)After that we change angle++ to angle+=1 Your code should look like this:  

When you run it you should get a program that draws a parabola and finishes like this:





DRAWING BALL!

I’m going to be changing the very simple code for this program (by Shipransh Agrawal on Open Processing) from Java to python. 
This code prints out a program that has a circle follow our mouse, so you can draw with it. This code uses mouseX and mouseY in place of the position for the circle, making it so the circle follows the x and y position of your mouse when you move it around. The code also makes it so the circle changes color in different shades of red.  
First things first lets change the set up and draw to the proper format for Python (def setup (): and def draw ():) Then we are going to delete the text following the double slashes, as these are comments we do not need. After that all we have to do is get rid o the semi colons. Your code should look like this:


Wednesday, June 10, 2015

If/else and True/False statements!

Today I will be showing you how to convert a example from here. The example we will be converting is this one:

First things first, let me explain what is happening in this program. This program contains an “if true or false” function. An “if true or false” function  means something will happen If something is happening else something else will. In this case if the mouse is clicked the box will turn white from black. 
The first thing we are going to do is change the void setup () { } and void draw () {} to def setup ():  and def draw (): Next we are going to get rid of all the semi colons because in Python we just do not need them. After that we must change all the double slashes (//) to pound signs (#) because the parts following are made into a comment but in Python // is the sign for division in a math problem. So far your code should look like this:

Next we are going to change the if  and else statements so they work on Python. To do this all we have to do is get rid of the curl brackets ( { } ) and replace them with a colon ( : ) After you do that your code should look like this: 

Next we are going to change the way our if true statement looks. All we have to do is change if (mousePressed == true): to if mousePressed is True: 
The final thing we need to do is move copy and paste our rect(25,25,50,50) directly underneath both fill functions . Your code should now look like this:


And when you run it you should get a 100 by 100 pixel sized screen with a 25 by 25 pixel black square that changes to white when you click your mouse.