need help please
in
Programming Questions
•
1 year ago
i try to create class, so i can have 5 floating shapes. but it doesnt work. please help, thanks
edit:
in my code i'm having "Component.x is not visible" error. i can create only one floating shape but when i want to have 5, i should use class, right? i read some examples and tried to create Bubble class. my bubble has 3 different options: movement(bouncing around the walls) , display(bubble's size and color etc) and segg(how many segments bubble has).
i have coded for only one bubble without segments and movement. and it was moving only on y position. i have to learn it :) sorry for my unclearly message
- Bubble b1;
- Bubble b2;
- Bubble b3;
- Bubble b4;
- Bubble b5;
- float ci_x = noise(10)*0.5;
- float ci_y = noise(10)*0.5;
- float move_x = noise(1);
- float move_y = noise(1);
- float currentx;
- float currenty;
- float num = 2;
- void setup(){
- size(600,600);
- frameRate(320);
- b1 = new Bubble(50,100,100,40,10);
- b2 = new Bubble(50,100,100,60,30);
- b3 = new Bubble(50,100,100,10,50);
- b4 = new Bubble(50,100,100,80,70);
- b5 = new Bubble(50,100,100,6,100);
- }
- void draw(){
- background(0);
- b1.move();
- b1.display();
- b1.segg();
- b2.move();
- b2.display();
- b2.segg();
- b3.move();
- b3.display();
- b3.segg();
- b4.move();
- b4.display();
- b4.segg();
- b5.move();
- b5.display();
- b5.segg();
- }
- class Bubble {
- color c;
- float pozX;
- float pozY;
- int Segments;
- int ssize;
- Bubble(color b_color, float xpoz, float ypoz, int seg, int sizee){
- c = b_color;
- pozX = xpoz;
- pozY = ypoz;
- Segments = seg;
- ssize = sizee;
- for (int i=0; i<Segments; i++) {
- float angle = float(i) / float(Segments) * TWO_PI+220;
- float distance = ssize + 15 * noise(i, frameCount/60.0);
- }
- }
- void display(){
- smooth();
- strokeWeight(4);
- stroke(c);
- beginShape();
- fill(#D3E2E5);
- for (int i=0; i<Segments; i++) {
- curveVertex(x[i % Segments], y[i % Segments]);
- }
- endShape();
- }
- void move(){
- if(ci_x > width){
- ci_x = width;
- move_x = -move_x;
- }
- if(ci_y > height){
- ci_y = height;
- move_y = -move_y;
- }
- if(ci_x < 0){
- ci_x = 0;
- move_x = -move_x;
- }
- if(ci_y < 0){
- ci_y = 0;
- move_y = -move_y;
- }
- // x[i] = pozX + sin(angle) * distance;
- // y[i] = pozY + cos(angle) * distance;
- }
- void segg(){
- translate(width * noise(num+200), height * noise(num+2000));
- rotate(10 * noise(num+10));
- num = num + 0.001;
- float x[] = new float[Segments];
- float y[] = new float[Segments];
- }
- }
1