Friday, October 24, 2014

CSE Intro to Processing 2

Today in class we learned more about the basics of processing. One of which is frameRate. frameRate is how often draw is called a second. So, if I were to write frameRate(100) draw would be called 100 times in a second. We learned about smooth() which is an attribute that smooths out the lines so that they won't look so pixelated. But the coolest thing  we learned  today is an input called if(mousePressed). The input if(mousePressed) is the input used when you want the computer do so something every time the mouse is pressed. For example, if you want the computer to create a circle where the mouse if every time the mouse is pressed you would use the code:

if(mousePressed){
   ellipse(mouseX, mouseY, 50, 50);
 }

This code basically says when the mouse is pressed create a circle, where the mouse is hovering that, is 50 coordinates down and 50 coordinates across. I really enjoyed learning how to use the input if(mousePressed) and I can't wait to create my own code using this input. The code we created in class is down below.

void setup() {
 size(500, 500); // set size of window
 background(7, 80, 0); // set background color
 frameRate(60); // how often is draw called (60 times per second)
 smooth(); // anti-aliasing, smooths lines
} // end setup

void draw(){
 background(7, 80, 0); // redraw background to remove trace, ghosts
 
 if(mousePressed){ // if the mouse is pressed
   ellipse(mouseX, mouseY, 50, 50); // make a circle follow the mouse
 } // end if
 
  }// end draw

“The computer was born to solve problems that did not exist before.”
– Bill Gates
 

No comments:

Post a Comment