Rotation in opengl and clearing in opengl
in
Core Library Questions
•
1 years ago
can somebody make the sketch rotate by moving the mouse and clear the sketch by mouse click
import processing.opengl.*;
int x, y, z;
int speed = 10;
color sColor;//sketch color randomiser
//float b;
PImage etch;
color bgColor;//global declaration for random backgrounds
void setup() {
size(700, 630, OPENGL);
etch = loadImage("etchaskechcha.jpg");
background(etch);
translate(width/2, height/2);//centers 3D environment
noFill();//makes it transparent
box(350, 270, 407);//the contruct of 3D environment (w,h,d)
fill(sColor);//colour of sketch
}
void draw() {
lights();// shadow
//pushMatrix();
translate(width/2, height/2);//basically makes sketch visable and centers
translate(x, y, z);//enables movement
noStroke();
strokeWeight(20);//weight of sketch
box(10);//sketch
smooth();
strokeWeight(1.4);//border thickness
//popMatrix();
//restricts sketch to 3D environment
if (z<-200)
z=-200;//limits backward movement
if (z>130)
z=130; //limits forward movement
if (x>203)
x=203;//limits right side
if (x<-203)
x=-203;//limits left side
if (y>150)
y=150;//limits the bottom
if (y<-150)
y=-150;//limits the top
}
//changes colour of sketch
void mousePressed() {
int s = int(random(5));
if (s == 0) {
sColor = color (255, 255, 0);//yellow
println("Yellow");
}
if (s == 1) {
sColor = color (250, 0, 0);//red
println("Red");
}
if (s == 2) {
sColor = color (148, 0, 211); //dark violet
println("Violet");
}
if (s == 3) {
sColor = color (0, 0, 255); //green
println("Blue");
}
if (s == 4) {
sColor = color (0, 250, 0);//orange
println("green");
}
fill(sColor);
}
void keyPressed() {
if (keyCode == UP) {
y-=speed;
}
if (keyCode == DOWN) {
y+=speed;
}
if (keyCode == LEFT) {
x-=speed;
}
if (keyCode == RIGHT) {
x+=speed;
}
if (keyCode == SHIFT) {
z+=speed;
}
if (keyCode == CONTROL) {
z-=speed;
}
if (keyCode == 'C') {
redraw();
}
}
1