User Tools

Site Tools


courses:2009.10.13.intro_prototyping

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

courses:2009.10.13.intro_prototyping [2009/10/13 07:49]
130.239.179.56 created
courses:2009.10.13.intro_prototyping [2010/11/03 00:45] (current)
130.239.61.133 fixed typo
Line 1: Line 1:
 +====== oct 13: Introduction to programming with Processing: variables and functions ======
 +
 +
 +==== Variables ====
 +
 +In summary: a variable is a container with a name and content (memory space). It is used to store a value. ​
 +  ​
 +In Processing you have specifically declare the type of variables you are using:
 +<​code>​
 +boolean a = true   // create a variable "​a"​ of the type "​boolean"​ (true or false)
 +int b = 0;         // create a variable "​b"​ of the type "​int"​ (integer)
 +float c = 0.0;     // create a variable "​c"​ of the type "​float"​ (number with decimal precision)
 +byte d = 127       // create a variable "​d"​ of the type "​byte"​ (number between 127 and -128) 
 +char e = '​A' ​      // create a variable "​e"​ of the type "​char"​ (character)
 +</​code>​
 +
 +File built during the class: {{:​courses:​variables_00.zip|}}
 +
 +<​code>​
 +// declare our variables, at the right level/scope so they are accessible throughout the program
 +int circleSize = 15;
 +int circleX = 20;
 +int startX = 100;
 +int startY = 20;
 +int delta = 40;
 +
 +void setup(){
 +
 +  size(600,​400);​
 +  smooth();
 +  frameRate(30);​
 +  println("​starting up");
 +
 +}
 +
 +
 +void draw(){
 +
 +  // println("​loop"​);​
 +  // background(100);​
 +  fill(100, 10);
 +  rect(0, 0, width, height);
 +
 +
 +  // startX ​ = mouseX;
 +  // startY = mouseY
 +  delta = mouseX;
 +
 +
 +  // 10x10 circles
 +  for(int counterY = 0; counterY <10 ; counterY = counterY + 1){
 +
 +    for(int counter = 0; counter < 10 ; counter = counter + 1){ 
 +      // println("​counter:​ " + counter);
 +      fill(255);
 +      ellipse(startX + delta * counter, startY + delta * counterY, circleSize, circleSize);​
 +    }
 +
 +  }
 +
 +}
 +</​code>​
 +
 +
 +==== Functions ====
 +
 +  * a structured block of code
 +  * it has a type, a name and can have parameters (values passed to it)
 +
 +A simple function of type //void// called //setup// and it requires no parameters
 +<​code>​
 +void setup(){
 +
 +}
 +</​code>​
 +
 +Another function called //fill// and it can have different number of parameters
 +<​code>​
 +fill(0); ​            // greyscale
 +fill(100, 200);      // greyscale and alpha
 +fill(255, 0, 0);     // RGB
 +fill(255, 0, 0, 20); // RGB and alpha
 +</​code>​
  
courses/2009.10.13.intro_prototyping.txt · Last modified: 2010/11/03 00:45 by 130.239.61.133