2D to 3D help
in
Programming Questions
•
2 years ago
im currently doing a challenge at my uni which involves creating a 3D etch a Sketch . my group has managed to do a 2D version but cant get around doing it in 3D plz help.
2D Version code :
int xpos = 150;
int ypos = 150;
int rectWidth;
boolean left;
boolean right;
boolean up;
boolean down;
color bgColor;//global declaration for random backgrounds
PImage etch;//loads image of the frame of etch a sketch
void setup() {
size(700, 630,P3D);
frameRate(50);
etch = loadImage("etchaskech.jpg");
fill(51, 255, 51);// the sketch colour
smooth();
//background(128);//grey background
noStroke();
rectWidth = width/2;
background(etch);// frame
}
void draw() {
if (keyPressed) {
if (key == 's'){
//off button
background(0);
// Button turns off
smooth();
strokeWeight(4);
fill(200);
ellipse(width/2, height/2, width/3+25, height/3+25); // gray edge
fill(134, 45, 0);
ellipse(width/2, height/2, width/3, height/3); // red button
strokeWeight(2);
stroke(0);
ellipse(width/2, height/2, width/6, height/6); // black color
line(width/2, height/2-20, width/2, height/2-75);
}
else if(key == 'e'){
exit();
}
if (left) {
xpos -= 1;
}
if (right) {
xpos += 1;
}
if (up) {
ypos -= 1;
}
if (down) {
ypos += 1;
}
}
//background(etch);
//this changes the background colours to the 5 random colours assigned with integers
//changes the colour of the marker
//clears the screen
if (mousePressed) {
int bg = int(random(5));
if (bg == 0) {
bgColor = color (255, 255, 0); //yellow
}
else if (bg == 1) {
bgColor = color (255, 255, 255); //white
}
else if (bg == 2) {
bgColor = color (225, 0, 0); //red
}
else if (bg == 3) {
bgColor = color (148, 0, 211); //dark violet
}
else if (bg == 4) {
bgColor = color (0, 255, 255); //aqua
}
background (bgColor);
if (bg==0) {
fill(0, 0, 255);//when screen yellow marker turns blue
}
else if (bg== 1) {
fill(0, 0, 0);// black
}
else if (bg== 2) {
fill(51, 255, 51);//green
}
else if (bg== 3) {
fill(255, 255, 0);//yellow
}
else if (bg== 4) {
fill(255, 69, 0);//red/orange
}
background(etch);
}
if (xpos<72)
xpos=72;
if (ypos<106)
ypos=106;
if (xpos>630)
xpos=630;
if (ypos>537)
ypos=537;
rect(xpos, ypos, 1, 1);
}
void keyPressed() {
if (key == CODED) {
if (keyCode == LEFT) {
left = true;
}
if (keyCode == RIGHT) {
right = true;
}
if (keyCode == UP) {
up = true;
}
if (keyCode == DOWN) {
down = true;
}
}
}
void keyReleased() {
if (key == CODED) {
if (keyCode == LEFT) {
left = false;
}
if (keyCode == RIGHT) {
right = false;
}
if (keyCode == UP) {
up = false;
}
if (keyCode == DOWN) {
down = false;
}
}
}
1