Loading...
Logo
Processing Forum

Beginner questions

in Programming Questions  •  2 years ago  
Hi,
 
I'm a beginner in programming and I would be very grateful if someone could help me, please.
What I'm trying to do is:
 
- rotate many objects around themselves (3D rotation around  a vertical axis on each object); (Note: I've tried every examples provided in References and Examples from Processing but none of them worked.)
 
- when mouse is pressed an ellipse appears and I want all objects on the screen "absorbed" by that ellipse (all objects moving for the inside of the ellipse continuously); when the mouse is released everything returns to the way it was in the beginning.
 
- I would like that the ellipse that appears when mouse is pressed increase size while the mouse is being pressed, but not very much.
 
Here´s the program:
 
(Note: some words are written in Portuguese so I add a comment with the traduction or explanation)
 
 
class classecristal {  "classecristal" is the name I gave to the class
int x1;
int y1;
int x2;
int y2;
int x3;
int y3;
int x4;
int y4;
int velocidade;  // "velocidade" means speed 
color cor; // "cor" means color

classecristal (int recebex1, int recebey1, int recebex2, int recebey2, int recebex3, int recebey3, int recebex4, int recebey4, int recebevelocidade, color recebecor) {  
  x1 = recebex1;  // "recebe" means receives
  y1= recebey1;
  x2 = recebex2;
  y2 = recebey2;
  x3 = recebex3;
  y3 = recebey3;
  x4 = recebex4;
  y4 = recebey4;
  velocidade = recebevelocidade;
  cor = recebecor;
 
}

void movimenta () {  // "movimenta" means moves
 
  y1 = y1 + velocidade;
  y2 = y2 + velocidade;
  y3 = y3 + velocidade;
  y4 = y4 + velocidade;
if (y1 > height) {
    y1=0;
  }
    if (y2  > height) {
    y2=0; 
  }
  if (y3  > height){
    y3=0;
  }
  if (y4  > height){
    y4 = 0;
  }
 
  x1 = x1 + velocidade;
  x2 = x2 + velocidade;
  x3 = x3 + velocidade;
  x4 = x4 + velocidade;
if (x1 > width) {
    x1=0;
  }
    if (x2 > width) {
    x2=0; 
  }
  if (x3 > width){
    x3=0;
  }
  if (x4 > width){
    x4 = 0;
  }
 
  }
 

void desenha () {  // "desenha" means draw 
   
  fill (255,255,255,20);
  quad(x1,y1,x2,y2,x3,y3,x4,y4);
 
}
}

int numeroMaximocristais = 1000;  // "numeroMaximocristais" is the number of elements in the class
classecristal [ ] listacristais = new classecristal [numeroMaximocristais];  // "listacristais" are all elements thet will be drawn
 
void setup() {
  size(1300,700);
 
  background (0,0,0);
 
  for (int i=0; i < numeroMaximocristais; i++) {
   
    listacristais [i] = new classecristal (i*20, 10, i*20 + 6, 30, i*20, 50, i*20-6, 30, int(random(1,3)), color(255,255,255,100));
 
}
   
}
 
void draw () {
 

for (int i=0; i < numeroMaximocristais; i++) {
 
 listacristais [i].movimenta();
 listacristais [i].desenha();
 
 
 if (mousePressed == true) {
 
fill (255,255,255,20);
 

ellipse (mouseX,mouseY,100,100);

 }
 
}
}
 
 
Kind regards,
Ana Costa