A)
void setup() {
size(480, 120);
}
void draw() {
if (mousePressed) {
fill(0);
} else {
fill(255);
}
ellipse(mouseX, mouseY, 80, 80);
}
B)
void setup() {
size(400, 400);
stroke(255);
}
void draw() {
line(150, 25, mouseX, mouseY);
}
void mousePressed() {
background(192, 64, 0);
}
C) Alpha transparencia
size(200,200);
background(0);
noStroke();
// No fourth argument means 100% opacity.
fill(0,0,255);
rect(0,0,100,200);
// 255 means 100% opacity.
fill(255,0,0,255);
rect(0,0,200,40);
// 75% opacity.
fill(255,0,0,191);
rect(0,50,200,40);
// 55% opacity.
fill(255,0,0,127);
rect(0,100,200,40);
// 25% opacity.
fill(255,0,0,63);
rect(0,150,200,40);
D)
color c = color(0);
float x = 0;
float y = 100;
float speed = 1;
void setup() {
size(200,200);
}
void draw() {
background(255);
move();
display();
}
void move() {
x = x + speed;
if (x > width) {
x = 0;
}
}
void display() {
fill(c);
rect(x,y,30,10);
}