Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : Visualise Real time long CSV datatype

$
0
0


no, I think map() wasn't right for you

here is a sketch with sinus (I am simulating incomingValues[1] here)


  1. //
  2. ArrayList<Ball> balls;
  3. final int ballWidth = 1;
  4. int myAttentionValue=0;
  5. float angle;
  6. //
  7. // ---------------------------------------------------------------
  8. //
  9. void setup()
  10. {
  11.   // init
  12.   size(800, 600);
  13.   // frameRate(3);
  14.   // Create an empty ArrayList
  15.   balls = new  ArrayList();
  16.   for (int i=0; i < 122; i++) {
  17.     balls.add(new Ball(mouseX, 300, ballWidth,
  18.     color ( 255, 0, 0)));
  19.   }
  20. } // func
  21. //
  22. //
  23. void draw()
  24. {
  25.   background(255);
  26.   //  Ball ball;
  27.   //  for (int i=0; i < balls.size(); i++) {
  28.   //    ball = balls.get(i);
  29.   //    ball.move();
  30.   //    ball.display();
  31.   //  }
  32.   //  for (int i=0; i < balls.size(); i++) {
  33.   //    ball = balls.get(i);
  34.   //    if (ball.finished()) {
  35.   //      balls.remove(i);
  36.   //    }
  37.   //  }
  38.   // wwww
  39.   Ball ball;
  40.   // balls.add(new Ball(0, map(myAttentionValue, 0, 100, 200, 400), ballWidth, color ( 255, 0, 0)));
  41.   balls.add(new Ball(0, 300+myAttentionValue*sin(radians(angle)), ballWidth, color ( 255, 0, 0)));
  42.   for (int i=0; i < balls.size(); i++) {
  43.     ball = balls.get(i);
  44.     ball.display(200+i);
  45.   }
  46.   if (balls.size()>0)
  47.     balls.remove(0);
  48.   if (frameCount % 11 == 0 ) {
  49.     myAttentionValue++;
  50.   }
  51.   if (myAttentionValue>=100)
  52.     exit();
  53.   angle+=7;
  54.   println ("myAttentionValue  "+ myAttentionValue);
  55. } // func
  56. //
  57. // =====================================================================
  58. void mouseReleased() {
  59.   // A new ball object is added to the ArrayList (by default to the end)
  60.   balls.add(new Ball(mouseX, mouseY, ballWidth,
  61.   color (random(0, 255), random(0, 255), random(0, 255))));
  62. }
  63. // =====================================================================
  64. // Simple bouncing ball class
  65. class Ball {
  66.   float x;
  67.   float y;
  68.   color myColor;
  69.   float speed;
  70.   float gravity;
  71.   float w;
  72.   float life = 255;
  73.   Ball(float tempX, float tempY, float tempW, color tempmyColor1) {
  74.     x = tempX;
  75.     y = tempY;
  76.     w = tempW;
  77.     myColor=tempmyColor1;
  78.     speed = 0;
  79.     gravity = 0.1;
  80.   }
  81.   void move() {
  82.     // Add gravity to speed
  83.     speed = speed + gravity;
  84.     // Add speed to y location
  85.     y = y + speed;
  86.     // If ball reaches the bottom
  87.     // Reverse speed
  88.     if (y >= height-19) {
  89.       // Dampening
  90.       speed = speed * -0.8;
  91.       y = height-19;
  92.     }
  93.   }
  94.   boolean finished() {
  95.     // Balls fade out
  96.     life--;
  97.     if (life < 0) {
  98.       return true;
  99.     }
  100.     else {
  101.       return false;
  102.     }
  103.   }
  104.   //
  105.   void display(float i) {
  106.     // Display the ball
  107.     fill(myColor);
  108.     stroke(myColor);
  109.     ellipse(i, y, w, w);
  110.     point(i, y);
  111.   } // method
  112.   //
  113. } // class  
  114. // =====================================================================


Viewing all articles
Browse latest Browse all 1768

Trending Articles