This document discusses variables in coding and provides examples of their use. It introduces different data types for variables like integers, floats, characters, and booleans. It demonstrates how to assign values to variables and how variables can be used in expressions and statements. Special processing variables like size, background, mouseX and mouseY are described for creating dynamic sketches. The document concludes with an exercise to create an interactive line composition using variables.
3. Variables:
 Data
 types
Â
int
 count
 =
 0;
Â
float
 score
 =
 43.71;
Â
char
 letter
 =
 'a';
Â
boolean
 niceWeather
 =
 true;
Â
4. Variables:
 Assign
 values
Â
int
 x
 =
 0;
Â
line(x,
 10,
 x,
 200);
Â
x
 =
 50;
Â
line(x,
 10,
 x,
 200);
Â
5. Variables:
 Assign
 values
Â
int
 x
 =
 0;
Â
Â
Â
Â
Â
 //
 ok
Â
int
 y
 =
 0.3;
Â
Â
Â
 //
 error:
 float
 value
Â
z
 =
 10;
Â
Â
Â
Â
Â
Â
Â
Â
 //
 error:
 not
 declared
Â
char
 c
 =
 true;
Â
 //
 error:
 wrong
 type
Â
6. 1
 +
 2
 +
 3
 +
 4
 +
 5
 =
 ?
Â
1
 +
 2
Â
Â
Â
Â
 3
 +
 3
Â
Â
Â
Â
Â
Â
Â
Â
 6
 +
 4
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
 10
 +
 5
 =
 15
Â
9. Variables:
 Usage
Â
int
 sum
 =
 0;
Â
sum
 =
 1
 +
 2;
Â
sum
 =
 sum
 +
 3;
Â
10. Variables:
 Usage
Â
int
 sum
 =
 0;
Â
sum
 =
 1
 +
 2;
Â
sum
 =
 sum
 +
 3;
Â
sum
 =
 sum
 +
 4;
Â
sum
 =
 sum
 +
 5;
Â
11. Variables:
 Usage
Â
int
 sum
 =
 0;
Â
sum
 =
 1
 +
 2;
Â
sum
 =
 sum
 +
 3;
Â
sum
 =
 sum
 +
 4;
Â
sum
 =
 sum
 +
 5;
Â
println(sum);
Â
12. Expressions
Â
int
 a
 =
 3;
Â
int
 b
 =
 5;
Â
int
 c
 =
 a
 +
 b;
Â
a
 =
 b
 *
 2;
Â
c
 =
 c
 +
 a;
Â
13. Expressions
 in
 statements
Â
int
 x
 =
 100;
Â
int
 y
 =
 20;
Â
fill(x);
Â
line(x,
 y,
 300,
 y
 *
 2);
Â
15. Sta%c
 sketch
Â
 size(200,
 200);
Â
 background(0);
Â
 line(100,
 50,
 0,
 0);
Â
 ellipse(100,
 100,
 20,
 20);
Â
16. Dynamic
 sketch
Â
void
 setup()
 {
Â
 size(200,
 200);
Â
 background(0);
Â
}
Â
void
 draw()
 {
Â
 line(100,
 50,
 0,
 0);
Â
 ellipse(100,
 100,
 20,
 20);
Â
}
Â
17. Dynamic
 sketch
Â
void
 setup()
 {
Â
 size(200,
 200);
Â
 background(0);
Â
}
Â
void
 draw()
 {
Â
 line(100,
 50,
 mouseX,
 mouseY);
Â
 ellipse(mouseX,
 mouseY,
 20,
 20);
Â
}
Â
18. Excersises
Â
E4:
 Create
 a
 dynamic
 interac.ve
 line
 composi.on.
Â
19. Thank
 you.
Â
Copyright
 Till
 Nagel,
 FH
 Potsdam,
 10/2010
Â