no, I think map() wasn't right for you
here is a sketch with sinus (I am simulating incomingValues[1] here)
- //
- ArrayList<Ball> balls;
- final int ballWidth = 1;
- int myAttentionValue=0;
- float angle;
- //
- // ---------------------------------------------------------------
- //
- void setup()
- {
- // init
- size(800, 600);
- // frameRate(3);
- // Create an empty ArrayList
- balls = new ArrayList();
- for (int i=0; i < 122; i++) {
- balls.add(new Ball(mouseX, 300, ballWidth,
- color ( 255, 0, 0)));
- }
- } // func
- //
- //
- void draw()
- {
- background(255);
- // Ball ball;
- // for (int i=0; i < balls.size(); i++) {
- // ball = balls.get(i);
- // ball.move();
- // ball.display();
- // }
- // for (int i=0; i < balls.size(); i++) {
- // ball = balls.get(i);
- // if (ball.finished()) {
- // balls.remove(i);
- // }
- // }
- // wwww
- Ball ball;
- // balls.add(new Ball(0, map(myAttentionValue, 0, 100, 200, 400), ballWidth, color ( 255, 0, 0)));
- balls.add(new Ball(0, 300+myAttentionValue*sin(radians(angle)), ballWidth, color ( 255, 0, 0)));
- for (int i=0; i < balls.size(); i++) {
- ball = balls.get(i);
- ball.display(200+i);
- }
- if (balls.size()>0)
- balls.remove(0);
- if (frameCount % 11 == 0 ) {
- myAttentionValue++;
- }
- if (myAttentionValue>=100)
- exit();
- angle+=7;
- println ("myAttentionValue "+ myAttentionValue);
- } // func
- //
- // =====================================================================
- void mouseReleased() {
- // A new ball object is added to the ArrayList (by default to the end)
- balls.add(new Ball(mouseX, mouseY, ballWidth,
- color (random(0, 255), random(0, 255), random(0, 255))));
- }
- // =====================================================================
- // Simple bouncing ball class
- class Ball {
- float x;
- float y;
- color myColor;
- float speed;
- float gravity;
- float w;
- float life = 255;
- Ball(float tempX, float tempY, float tempW, color tempmyColor1) {
- x = tempX;
- y = tempY;
- w = tempW;
- myColor=tempmyColor1;
- speed = 0;
- gravity = 0.1;
- }
- void move() {
- // Add gravity to speed
- speed = speed + gravity;
- // Add speed to y location
- y = y + speed;
- // If ball reaches the bottom
- // Reverse speed
- if (y >= height-19) {
- // Dampening
- speed = speed * -0.8;
- y = height-19;
- }
- }
- boolean finished() {
- // Balls fade out
- life--;
- if (life < 0) {
- return true;
- }
- else {
- return false;
- }
- }
- //
- void display(float i) {
- // Display the ball
- fill(myColor);
- stroke(myColor);
- ellipse(i, y, w, w);
- point(i, y);
- } // method
- //
- } // class
- // =====================================================================