Friday, 4 March 2011

_04_MoreVariables

//This time we are going to define some variables of
//our own to store some information.  Like a function
//name, a variable definition has three parts.
//First is the variable "type".  This tells Processing
//what kind of information the variable contains.  In
//this example it is:
//
//  int
//
//'int' is short for Integer which just means a whole number
//like 3 , 17 or 19234
//
//An int _can't_ store a fraction.
//
//The next part is a label which is the name of the variable
//You can pick just about any namne for your variable so long as
//A) it starts with a letter
//B) it is a single word with no spaces
//C) it isn't the same as any built in name or label
//
//Finally there is an optional start value for the variable
//The start value is set only once, after that we can change
//the variable inside one of the functions and the variable
//will remember the new value.
//
//There are lots of other variable types that Processing understands
//some of the most commonly used ones are:
//
//  float   |  a 'float' stores fractions like 3.14 or 2.737
//  boolean |  this type can only have the value 'true' or 'false'
//  String  |  a sequence of letters and numbers stored as text
//
int batX = 240;
int batY = 700;


//Here we go again
void setup() {
  size( 480, 800 );
  background( 0 );
}

//Draw a white rectangle in the middle bottom of the screen.
//This time we are using the value of a variable to set the
//position of the rectangle.  Also, you can use some maths to
//work out the final position.
void draw() {
  fill( 255 );
  rect( batX - 50, batY, 100, 25 );
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.