1-4 for different brushes. A and D to rotate
xxxxxxxxxx
float cvRot;
float xV;
String Brush = "normal";
int tick;
ArrayList < Paint > painting = new ArrayList < Paint > ();
void setup() {
size(1000, 1000, P3D);
xV = width / 2;
background(35, 35, 35);
}
void draw() {
lights();
background(35, 35, 35);
fill(255);
textAlign(CENTER, TOP);
textSize(32);
text("Rotation: " + String(round(cvRot)), width / 2, 0);
text("Brush: " + Brush, width / 2, 40);
if (keyPressed) {
if (key == 'a' || key == 'A') {
cvRot += 0.05;
}
if (key == 'd' || key == 'D') {
cvRot -= 0.05;
}
}
if (mousePressed) {
if (Brush == "erase") {
erase();
} else {
painting.add(new Paint(mouseX - xV, mouseY));
}
}
translate(xV, 0, 0);
for (Paint mark: painting) {
mark.render();
}
tick++;
}
void erase() {
for (int i = 0; i < painting.size(); i++) {
if (abs(painting.get(i).yP - mouseY) < 5) {
painting.remove(painting.get(i));
i--;
}
}
}
void keyPressed() {
if (key == '1') {
Brush = "normal";
}
if (key == '2') {
Brush = "sizenamic";
}
if (key == '3') {
Brush = "diamond";
}
if (key == '4') {
Brush = "scribble";
}
if (key == 'r' || key == 'R') {
painting.clear();
}
if (key == 'e' || key == 'E') {
Brush = "erase";
}
}
class Paint {
float xP, yP, yR;
String br;
Paint(float x, float y) {
xP = x;
yP = y;
br = Brush;
yR = cvRot;
}
void render() {
pushMatrix();
noStroke();
rotateY(cvRot - yR);
translate(xP, yP);
if (br == "normal") {
fill(255);
box(20);
} else if (br == "sizenamic") {
fill(255);
box((xP + yP) * 0.1);
} else if (br == "diamond") {
fill(255);
rotateX(tick / 10);
rotateZ(tick / 10);
sphereDetail(2);
sphere(20);
} else if (br == "scribble") {
fill(255);
stroke(255);
strokeWeight(10);
line(random(-20, 20), random(-20, 20), random(-20, 20), random(-20, 20));
}
popMatrix();
}
}