In this drawing machine I’m creating 3D shapes like cube and sphere that move in all three directions. There is some code for saving the frames and background have random rectangles and ellipse in different directions.
float circleX;
float circleY;
float i = 180;
float r = 0;
void setup()
{
size(640,400,P3D);
}
void keyPressed()
// if the ‘a’ key is pressed the image will reset, if the ‘s’ key is pressed it will take a screenshot
{
if (key == ‘h’) {
background(255, 255, 255);
}
if (key == ‘a’) {
saveFrame(“drawing-####.png”);
}
}
void draw()
{ for (int i =0;i<width;i+=800)
{
//translate(width/2 -500,height/2+100);
translate(random(0,400),random(0,400),random(0,400));
stroke(random(0,255),random(0,255),random(0,255));
rect(i,i,pmouseX,pmouseY);
}
if (mousePressed)
{
ellipse();
}
else
{
box();
}
}
void box()
{
frameRate(30);
background(0);
//background(random(0,255),random(0,255),random(0,255));
camera(mouseX, height/2, (height/2) / tan(PI/6), width/2, height/2, 0, 0, 1, 0);
translate(width/2,height/2);
rotate(r);
stroke(255);
noFill();
box(100);
r = r + 0.1;
}
void ellipse()
{
if(random(height) >= 10)
{
circleX =(random(width));
circleY= (random(height));
stroke(random(mouseX),random(mouseY),random(mouseY));
strokeWeight(1);
fill(random(mouseX),random(mouseY),random(mouseY),100);
ellipse(circleX,circleY,40,40);
camera(mouseX, mouseY, (height/2) / tan(PI/6), width/2, height/2, 0, 0, 1, 0);
translate(mouseX,mouseY);
sphere(40);
}
}