Wednesday, June 1, 2011

Exhibition

This is my final exhibition piece.


 
If/Else Statements

In programming, you can do many things just with a single line of code. But ‘if’ statements let you compare two options, and chooses one depending on whether its conditions are true or false. For example, if you were hungry, then you would eat. Otherwise, you wouldn’t. This is saying that if the ‘hungry’ condition was true, then you would eat. Otherwise, you would not do anything.
The ‘else’ part of this is just adding another option to the scene.  For example, if the hungry condition was false, then it would skip over the eating statement and you would exercise.
My project is a poster that depicts heaven and hell, and in between, the choices you make that determine where you might end up. It is similar to both a quiz and flowchart in the sense that it is asking you questions and depending on the answer you choose points you in a certain direction.
This illustrates my concept of if/else as it compares the two options, heaven and hell, and based on the questions which act as the conditions, determine which outcome you end up at. For example, if the question was “Have you ever stolen anything?” and your answer was no, then you would go up to the next question, else if you said no, then you would go down.
Therefore my project relates to real life as everyone makes choices everyday and this is represents my metaphor ‘Choices determine our path’.

Metaphor

My idea for a metaphor of if/else was to create a poster that displayed something that showed you could take multiple paths which led you to different results depending on the conditions you meet.

For example, this poster is a simple but good representation of if/else, as the flow chart has two different results, and depending on which answers you choose you either end up at 'change something' or 'keep doing whatever you're doing'.

Thursday, May 26, 2011

Programming term - If/Else Statements

Definition:

A conditional statement/expression or construct that perform different actions depending on whether a boolean condition evaluates to true or false.

Conditional statements are used to perform different actions based on different conditions. A boolean condition has only two values - either true or false. For example:

boolean tree = true;

This can indicate whether a particular condition is true, but can also be used to represent any situation that has two states, such as a lightbulb being on or off. 




The if statement consists of the word if followed by a boolean expression, followed by a statement. The condition is enclosed in brackets and must evaluate to either true or false. If the condition is true, then the statement is executed and the processing continues with any statement that follows. If the condition is false, the statement controlled by the condition is skipped, and processing continues immediately with any statement that follows. 

Example:
  if (cMoney < totalMoney) {
             cMoney = cMoney + 20;
}                                        

This is saying that if the cMoney is less than the totalMoney then add 20 to the cMoney and put that value back into cMoney until the condition turns false and reaches the total amount of money. If this condition is originally false, ie. the cMoney is equal or greater than the totalMoney, then it will skip over it to any other processing that concedes it. 


The next part of this is the else statement which gives a true and false condition. 

Example:
if (cMoney < totalMoney) {
             cMoney = cMoney + 20;
  }else{                                    
                                            String limit = "You have reached the limit"       

This is saying the same thing except it adds the else component which means that if the first statement is false, it automatically defer to the else statement where it will say "You have reached the limit".    


The last part of this term is the if..else if..else statements that can be used to select one block of code when there are multiple options. This can be used infinitely.

Example: 
 
if (cMoney < totalMoney) {
             cMoney = cMoney + 20;
          }else if (cMoney > totalMoney) {
             cMoney = cMoney - 20;
}else{                                  
                                            String limit = "You have reached the limit"       

This is adding another condition when the first one is false. It is saying that if the cMoney is not less than totalMoney  but greater than it, then it will minus 20 from the cMoney and replace it with that value, then continue on with the rest of the code after the conditions. 



One last thing about if/else statements are nested if's. This means that there are if statements inside the original if statements which means there are two conditions for the code to pass.


Sunday, May 1, 2011

Experimenting..

I stumbled upon a cool thing today. I found that when I changed the colour at one point, the original screen would be black until you clicked and the boxes collided, and suddenly appeared in colour. I thought this was a nice touch and enphasized the concept how it is not immediately obvious what it does, which causes you to experiment more and interact.

Editing

I think I know why they're sticking together now. I was fiddling around with the speed of the boxes, and changed them to 0.5 speed. But what happened when it collided with another box, was that it reversed its speed to -0.5 which I think may have cancelled each other out and therefore it to be stuck together in one place.

I changed the size of the boxes to be more random but in a limited range, and I want to do the same with colour, but i'm still trying to decide if and how I want the colour to change. On collision? Or on click?

http://www.openprocessing.org/visuals/?visualID=8517

http://www.openprocessing.org/visuals/?visualID=12869

I decided i wanted more visuals so it was more of a sound shape. I found these ripple codes in open processing and I tried to tailor it to my needs. How it worked was when you clicked, it produced a random ripple at that point. I want to make it so that the ripple is produced when the boxes collide.

Progression

Worked on the sound today. I found out that it was right, and i just needed to plug in headphones to hear it. I used the code from the 142 resources page and found that I didn't need the song.close() part as I just want my sound to play when a collision is detected. I put ding.play() into the collision part and saw that it was continuously playing that one ding sound when they collided. So I figured I'd have to put in ding.rewind() so that it would rewind then play the sound again each time. But now I noticed that it was playing two ding sounds as it hit. I was puzzled by this but then figured out that each box was playing its own ding sound which sounded like two in consequence because I have code for each of the two that collide. Thinking that was done, I played it again and now the boxes seemed to stick to each other when they collided and repeated this awful part of the ding sound. Hmm...

So, so far I have 5 boxes that collide (if unnaturally) with each other and bounce off the sides. It seems a little bland to me...