Advertisement
xeromino

Bar graphs

Oct 19th, 2013
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. int howMany = 15;
  2. float step, edge;
  3. ExLine [] Elem = new ExLine[howMany];
  4.  
  5. void setup() {
  6.   size(500, 400);
  7.   background(#2C3E50);
  8.   noStroke();
  9.   float x = 0;
  10.   float theta = 0;
  11.   edge = width/10;
  12.   step = (width-2*edge)/howMany;
  13.   for (int i = 0; i < Elem.length; i++) {
  14.     x = i*step;
  15.     Elem[i]= new ExLine(x, theta);
  16.     theta += PI/howMany;
  17.   }
  18. }
  19.  
  20. void draw() {
  21.   background(#2C3E50);
  22.   for (int i = 0; i < Elem.length; i++) {
  23.     Elem[i].display();
  24.   }
  25. }
  26. class ExLine {
  27.   float x, x2, y, y2;
  28.   float rad, theta;
  29.  
  30.   ExLine(float _x, float _theta) {
  31.     x = _x;
  32.     y = height*.6;
  33.     rad = 70;
  34.     theta = _theta;
  35.   }
  36.  
  37.   void display() {
  38.     y2= map(sin(theta), -1, 1, -30, -120);
  39.     x2 = map(sin(theta), -1, 1, step*.4, step*.9);
  40.     rect(x+edge, y, x2, y2);
  41.     theta += .0523;
  42.   }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement