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.





No comments:

Post a Comment