Processing commands
PROCESSING COMMANDS
Int
- Description: Datatype for integers, numbers without a decimal point. Positive or negative values.
- Examples:
int a; // Declare variable 'a' of type int
a = 23; // Assign 'a' the value 23
int b = -256; // Declare variable 'b' and assign it the value -256
- Syntax:
int var
int var= value
- Parameters:
var variable name referencing the value
value any integer value
Float
- Description: Dataype for numbers with decimals.
- Examples:
float a; // Declare variable 'a' of type float
a = 1.5387; // Assign 'a' the value 1.5387
float b = -2.984;
// Declare variable 'b' and assign it the value -2.984
- Syntax and parameters: Same as the command int.
String
- Description:
- Examples:
- Syntax:
- Parameters:
Fill
- Description: Sets the color used to fill shapes.
- Examples:
size(400, 400);
fill(153);
rect(120, 80, 220, 220);
size(400, 400);
fill(204, 102, 0);
rect(120, 80, 220, 220);
- Syntax:
fill(rgb)
fill(rgb, alpha)
fill(gray)
fill(gray, alpha)
fill(v1, v2, v3)
fill(v1, v2, v3, alpha)
- Parameters:
rgb (int) color variable or hex value
alpha (float) opacity of the fill
gray (float) number specifying value between white and black
v1 (float) red or hue value (depending on current color mode)
v2 (float) green or saturation value (depending on current color mode)
v3 (float) blue or brightness value (depending on current color mode)
noFill
- Description: Disables filling geometry. If both noStroke() and noFill() are called, nothing will be drawn to the screen.
- Examples:
size(400, 400);
float x1 = 80;
rect(60, 40, 220, 220);
noFill();
rect(120, 80, 220, 220);
- Syntax:
noFill()
Stroke
- Description: Sets the color used to draw lines and borders around shapes.
- Examples:
- Syntax:
stroke(rgb)
stroke(rgb, alpha)
stroke(gray)
stroke(gray, alpha)
stroke(v1, v2, v3)
stroke(v1, v2, v3, alpha)
- Parameters: Same parameters as the previous one.
Background
- Description: sets the color used for the background of the Processing window. The default background is light gray. This function is typically used within draw() to clear the display window at the beginning of each frame, but it can be used inside setup()
- Examples:
background(152,190,100);
PImage img;
img = loadImage("Hokkaido.jpg");
background(img);
- Syntax:
background(rgb)
background(rgb, alpha)
background(gray)
background(gray, alpha)
background(v1, v2, v3)
background(v1, v2, v3, alpha)
background(image)
- Parameters: Same paremeters except the last one.
image
(PImage)
PImage to set as background (must be same size as the sketch window)if
- Description: Allows the program to make a decision about which code to execute. If the test evaluates to true, the statements enclosed within the block are executed and if the test evaluates to false the statements are not executed.
- Examples:
for (int i = 5; i < height; i += 5) {
stroke(255); // Set the color to white
if (i < 35) { // When 'i' is less than 35...
stroke(0); //...set the color to black
}
line(30, i, 80, i);
}
- Syntax:
if (test) {
statements
}
- Parameters:
test
any valid expression that evaluates to true or falsestatements
one or more statements to be executedelse
- Description:
- Examples:
size(400, 400);
for (int i = 20; i < 380; i += 20) {
if (i < 140) {
line(120, i, 320, i);
} else {
line(80, i, 360, i);
}
}
size(400, 400);
for (int i = 20; i < 380; i += 20) {
if (i < 140) {
line(120, i, 320, i);
} else if (i < 260) {
line(80, i, 360, i);
} else {
line(0, i, 400, i);
}
}
- Syntax:
if (expression) {
statements
} else {
statements
}
if (expression) {
statements
} else if (expression) {
statements
} else {
statements
}
- Parameters:
expression
any valid expression that evaluates to true or falsestatements
one or more statements to be executed
while
- Description: Controls a sequence of repetitions. The while structure executes a series of statements continuously while the expression is true. This function can be dangerous because the code inside the while loop will not finish until the expression inside while becomes false. It will lock out all other code from running (e.g. mouse and keyboard events will not be updated).
- Examples:
- Syntax:
while (expression) {
statements
}
- Parameters: Same parameters
for
- Description:
- Examples:
// Nested for() loops can be used to
// generate two-dimensional patterns
size(400, 400);
for (int i = 120; i < 320; i = i+20) {
for (int j = 0; j < 320; j = j+20) {
point(i, j);
}
}
- Syntax:
for (init; test; update) {
statements
}
for (datatype element : array) {
statements
}
- Parameters:
init
statement executed once when beginning looptest
if the test evaluates to <em>true</em>, the statements executeupdate
executes at the end of each iterationstatements
collection of statements executed each time through the loopdatatype
datatype of elements in the arrayelement
temporary name to use for each element of the arrayarray
name of the array to iterate through
Comentarios
Publicar un comentario