Advertisement
xeromino

Rectangle wave

Oct 12th, 2013
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. color bg = #ECD078;
  2. color cs =#D95B43, cm = #C02942, cl=#542437 ;
  3. float div_m, div_s, div_l;
  4. myRect[] s_rects = {
  5. };
  6. myRect[] m_rects = {
  7. };
  8. myRect[] l_rects = {
  9. };
  10.  
  11. void setup() {
  12.   size(500, 400);
  13.   background(bg);
  14.   stroke(0);
  15.   rectMode(CENTER);
  16.  
  17.   float sz;
  18.   float theta = 0;
  19.   div_s = 16;
  20.   div_m = 11;
  21.   div_l = 6;
  22.  
  23.   for (int i=1; i < div_s; i++) {
  24.     sz = width/div_s;
  25.     myRect s_rect = new myRect(float(i), sz, theta, cs);
  26.     s_rects = (myRect[])append(s_rects, s_rect);
  27.     theta += TAU/div_s;
  28.   }
  29.   for (int i=1; i < div_m; i++) {
  30.     sz = width/div_m;
  31.     myRect m_rect = new myRect(float(i), sz, theta, cm);
  32.     m_rects = (myRect[])append(m_rects, m_rect);
  33.     theta += TAU/div_m;
  34.   }
  35.   for (int i=1; i < div_l; i++) {
  36.     sz = width/div_l;
  37.     myRect l_rect = new myRect(float(i), sz, theta, cl);
  38.     l_rects = (myRect[])append(l_rects, l_rect);
  39.     theta += TAU/div_l;
  40.   }
  41. }
  42.  
  43. void draw() {
  44.   background(bg);
  45.   for (int i=0; i < l_rects.length; i++) {
  46.     l_rects[i].display();
  47.   }
  48.   for (int i=0; i < m_rects.length; i++) {
  49.     m_rects[i].display();
  50.   }
  51.   for (int i=0; i < s_rects.length; i++) {
  52.     s_rects[i].display();
  53.   }
  54.  }
  55.  
  56. class myRect {
  57.   float sz_x, sz_y, x, y;
  58.   float i, theta;
  59.   color col;
  60.  
  61.   myRect(float _i, float _sz, float _theta, color _col) {
  62.     y = height/2;
  63.     sz_x = _sz;
  64.     i = _i;
  65.     theta = _theta;
  66.     col = _col;
  67.   }
  68.  
  69.   void display() {
  70.     fill(col);
  71.     strokeWeight(2);
  72.     stroke(#ffffff);
  73.     x = i * sz_x;
  74.     sz_y = map(sin(theta), -1, 1, sz_x, sz_x*1.7);
  75.     rect(x, y, sz_x, sz_y);
  76.     theta -= 0.07;
  77.   }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement