Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. void setup ()
  2. {
  3.   size(620,470); // screen
  4.   background(100);
  5.   rect(50,20,550,400); // graph space
  6.   //x(begin),y(begin),delta(x),delta(y)
  7.   //Font assignment
  8.     PFont font = loadFont("TrebuchetMS-13.vlw");
  9.     textFont(font,13);
  10.   fill(0); // set filling color
  11.   text("Some Random Graph",260,15);
  12.   // X-axis
  13.   text("Number of samples ago",260,455);
  14.   for(int i= 550; i>=0; i -=50)
  15.   {
  16.     text(i,600-i,430);
  17.   }
  18.   //Y-axis
  19.   text("PWM",5,185);
  20.   text("%",15,205);
  21.   for(int j=0; j<= 100; j+=10)
  22.   {
  23.     text(j,35,420-4*j);
  24.   }
  25. }
  26.  
  27. void draw()
  28. {
  29.   color black = color(0);
  30.   color white = color(255);
  31.   int y = (int)random(400);
  32.   int[] values = new int[550];
  33.       for(int p=548; p>=0;p--) { // move all elements
  34.     values[p] = (int)random(100)+100
  35.     }
  36.   while(true)
  37.   {
  38.     if (y => 400) {
  39.         y = 399;
  40.     } else if (y <= 1) {
  41.         y = 2;
  42.     } else {
  43.         y += (round(random(1))*2)-1;
  44.     }  
  45.       for(int p=548; p>=0;p--) // move all elements
  46.       {
  47.         values[p+1]=values[p];
  48.       }
  49.       values[0]=y;             // add new element
  50.       for(int q=0, foo; q<550;q++) // print pixels
  51.       {
  52.         set(600-q,values[q],color(0)); //set(x,y,color)
  53.         /*if (q == 100)
  54.         {
  55.           delay(10000);
  56.         }*/
  57.       }
  58.       delay(10);
  59.       rect(50,20,550,400) // paste a clean sheet over the points
  60.   }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement