Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How to make the Slider control the motion

$
0
0

i am beginner and just trying to figure out to connect the slider with the motion of the balls is it possible

thank you

import controlP5.*;
ControlP5 controlP5;

int rectHeight  = 100;
int rectWidth   = 20;

int gotBallsCounter = 0;

final int NUM_OF_BALLS = 30;
final int BALL_SIZE = 25;

float ball_x[] = new float[NUM_OF_BALLS];
float ball_y[] = new float[NUM_OF_BALLS];
float ball_dx[] = new float[NUM_OF_BALLS];
float ball_dy[] = new float[NUM_OF_BALLS];


int actualTimer[] = new int[NUM_OF_BALLS];

void setup() {


  controlP5 = new ControlP5(this);

   controlP5.addKnob("Speed",0,360,10,600,30,70);


  fullScreen();
  fill(0, 255, 0);


  for (int i = 0; i < NUM_OF_BALLS; i ++) {
    ball_x[i] = random(0, rectHeight);
    ball_y[i] = random(0, rectHeight);
    ball_dx[i] = random(-5, 4);
    ball_dy[i] = random(-5, 4);
    if (ball_dx[i] < 2 && ball_dx[i] >= 0 ) ball_dx[i] = 2;
    if (ball_dx[i] == -1) ball_dx[i] = -2;
    if (ball_dy[i] < 2 && ball_dy[i] >= 0 ) ball_dy[i] = 2;
    if (ball_dy[i] == -1) ball_dy[i] = -2;


  }


}

void draw() {



  fill( random(255), random(255), random(255), random(255));
  background(0);

  for (int i = 0; i < NUM_OF_BALLS; i ++) {
    ellipse(ball_x[i], ball_y[i], BALL_SIZE, BALL_SIZE);
    ball_x[i] += ball_dx[i];
    ball_y[i] += ball_dy[i];


    if (ball_x[i] >= width-BALL_SIZE/2) ball_dx[i] = -ball_dx[i];

    if (ball_y[i] >= height-BALL_SIZE/2) ball_dy[i] = -ball_dy[i];

    if (ball_x[i] <= BALL_SIZE/2) ball_dx[i] = -ball_dx[i];

    if (ball_y[i] <= BALL_SIZE/2) ball_dy[i] = -ball_dy[i];


    rect(width-rectWidth, mouseY-rectHeight/2, rectWidth, rectHeight);


    if ( ball_x[i] >= width-rectWidth-BALL_SIZE/2 && ball_y[i] > mouseY-rectHeight/2 && ball_y[i] < mouseY+rectHeight/2 ) {
      ball_dx[i] = -ball_dx[i];


      int timer = millis();
      if (timer-actualTimer[i] >= 5000)
      {
        gotBallsCounter++;
        actualTimer[i] = timer;
      }
    }

    textSize(32);
    text(gotBallsCounter, 10, 30);
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles