3D objects
Cube [] cube = new Cube [200];
PShape e;
float angle;
float angle2 = 0.0;
float angle3= 0.0;
float speed1 = 0.01;
float offset = 10;
float scalar = 100;
float speed = 0.01;
void setup() {
size(800, 800, P3D);
e =loadShape("tinker (1).obj");
background(0);
for (int c = 0; c < cube.length; c ++) {
cube [c] = new Cube (random(800), random(800), random(400), random(5, 10));
}
}
void draw () {
background (0);
lights();
strokeWeight(3);
stroke(255);
//noStroke();
noFill();
//fill(193,193,193,50);
angle +=0.5;
pushMatrix();
translate(width/2, height/2);
rotateY(radians(angle));
box(700);
popMatrix();
pushMatrix();
scale(2);
translate(200, 250,50);
rotateY(radians(angle));
rotateX(radians(90));
noStroke();
fill(36, 67, 255);
shape(e,0,0);
popMatrix();
pushMatrix();
angle2 +=speed;
float x = offset + cos(angle2) * scalar;
float y = offset + sin(angle2) * scalar;
translate(width/2, height/2+y, x);
rotateY(radians(angle));
noStroke();
//stroke(random(255),random(255),random(255));
fill(192, 70, 255);
sphere(20);
popMatrix();
pushMatrix();
for (int c = 0; c < cube.length; c ++) {
cube [c].update();
cube [c].display();
}
popMatrix();
pushMatrix();
float x2 = offset + cos(angle3) * (scalar +100);
float y2 = offset + sin(angle3) * (scalar + 100);
angle3 +=speed1;
translate(width/2+x2, height/2, y2);
rotateY(radians(angle));
rotateX(radians(angle));
stroke(random(255), random(255), random(255));
fill(112, 255, 36);
noStroke();
sphere(10);
popMatrix();
}
/// Cube class ( I change to the sphere at the end but still call it Cube).
class Cube {
float angle3= 0.0;
float speed1 = 0.01;
float offset = 10;
float scalar = 100;
int dir = 1;
float s,x3, y3,z3;
int ex3,ey3,ez3;
Cube(float tx3, float ty3, float tz3,float ts){
x3 = tx3;
y3 = ty3;
z3 = tz3;
s = ts;
}
void update(){
// x3 = offset + cos(angle3) * (scalar -100);
// y3 = offset + sin(angle3) * (scalar -100);
//angle3 +=speed1;
ex3 +=(x3 -ex3)*0.1;
ey3 +=(y3 -ey3)*0.1;
ez3 +=(z3 -ez3)*0.1;
x3 += 1* dir;
y3 += 1*dir;
z3 += 1*dir;
if( z3 > 400){
dir = -1;
}
if( x3 > 800){
dir = -1;
}
if( y3 > 700){
dir = -1;
}
if( z3 < -100){
dir = 1;
}
if( x3 < 0){
dir = 1;
}
if( y3 < 200){
dir = 1;
}
//for(int i = 0; i > 100; i++){
//float r = map ( i , 0 , 155,0,255);
//}
}
void display(){
pushMatrix();
translate(ex3, ey3,ez3);
rotateY(radians(angle));
rotateX(radians(angle));
stroke(random(255),random(255),random(255));
fill(random(255),random(255),random(255));
noStroke();
sphere(s);
popMatrix();
}
}
Comments
Post a Comment