ball grids and class setup questions
in
Programming Questions
•
2 years ago
guys im new to processing..so i need ur help!! :)
what i intend to do is to create a grid with ball class, i manage to get it to draw an ellipse, however when i did it with my ball class it does not seem to work.
moreover after the grid by the ball is done, thinking of moving the ball on Z-axis, but i dont know where is that applied, does it have to be included in the ball class? or do i have to do something else
thanks heres my code
- import peasy.*;
- PeasyCam cam;
- // decade class ball is myBall
- Ball[] balls;
- //int ballAmount = 125;
- //int distance = 100;
- //int space = 30;
- ////int radius = 15;
- void setup (){
- size(600,600,P3D);
- noStroke ();
- ////// this is for the camera settings
- cam = new PeasyCam(this,450);
- cam.rotateX(PI*0.3);
- cam.rotateZ(PI*0.3);
- for (int i = 0; i < balls.length; i++) {
- balls[i] = new Ball(random(-1,1), random(-1,1));
- }
- }
- void draw (){
- background (0);
- int stepsize = 10;
- for (int i = stepsize; i <height; i+= stepsize){
- for (int j = stepsize; j <width; j+= stepsize){
- balls[i]. display();
- //what i want to draw /add class ball in
- }
- }
- }
-
class Ball {float xpos;float ypos;float zpos;float speed;Ball(float tempYpos, float tempZpos) {//// preping info about the circle ready to be drawnxpos = int(random(0, 899));//// x coordinate of the center of the circle randoming number between 0 to the width of screenypos = int(random(0, 899));//// y coordinate of the center of the circlezpos = int(random(0, 899));
}
void display() {//// setup for the sketch. ie colors and draw the circlefill(255);ellipse(xpos, ypos, 5, 5);PVector linep = new PVector (xpos,ypos,zpos);// point(linep.x, linep.y, linep.z);stroke(255);strokeWeight(4);//// drawing the circles up each time the script runs}}
1