SHARE
TWEET

Untitled

a guest Jul 16th, 2014 356 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int graphBaseY = 500;
  2. int graphWidth = 1200;
  3. int graphHeight = 240;
  4. int stepX = graphWidth / 48;
  5. int stepY = graphHeight / 8;
  6. int screenMargin = 60;
  7. PFont f;
  8.  
  9. void setup()
  10. {
  11.   size(graphWidth + (screenMargin*2), 600);
  12.   //f = createFont("Arial",8,true);
  13. }
  14.  
  15. void drawGraph() {
  16.   //graph lines
  17.   stroke(0);
  18.   strokeWeight(1);
  19.   line(0, graphBaseY, graphWidth, graphBaseY);
  20.   //period lines
  21.   line(0, graphBaseY - 340, 0, graphBaseY + 40);
  22.   line(300, graphBaseY - 340, 300, graphBaseY + 40);
  23.   line(600, graphBaseY - 340, 600, graphBaseY + 40);
  24.   line(900, graphBaseY - 340, 900, graphBaseY + 40);
  25.   line(1200, graphBaseY - 340, 1200, graphBaseY + 40);
  26.  
  27.   //30 minute tick lines
  28.   for(int i=0; i<48; ++i) {
  29.     line(i * stepX, graphBaseY + 15, i * stepX, graphBaseY + 20);
  30.   }
  31.  
  32.   //graph labels
  33.   //textFont(f,16);
  34.   //fill(0);
  35.   //text("Hello Strings!",10,100);
  36. }
  37.  
  38.  
  39.  
  40. void mouseClicked() {
  41.   redraw();
  42. }
  43.  
  44. void draw() {
  45.   translate(screenMargin, 0);
  46.   background(255);
  47.   drawGraph();
  48.   int totalVisitors = 40;
  49.   for (int i=0; i <= totalVisitors; ++i) {
  50.     fakeVisitPath(i, false);
  51.   }
  52.   fakeVisitPath(0, true);
  53.   noLoop();
  54. }
  55.  
  56. void fakeVisitPath(int index, boolean primary) {
  57.  
  58.   int totalVisits;
  59.  
  60.    if(primary) {
  61.      totalVisits = 3 + int(random(7));
  62.      stroke(#2A36B1, 204);
  63.      strokeWeight(8);
  64.    } else {
  65.      totalVisits = 1 + int(random(10));
  66.      color pathColor = color(150,160,210); //color(random(225),random(225),random(225));
  67.      stroke(pathColor);
  68.      strokeWeight(.25);
  69.    }
  70.    
  71.   int[] visits = new int[totalVisits];
  72.   int[] visitLengths = new int[totalVisits];
  73.  
  74.   //generate fake visits
  75.   for (int i=0; i < visits.length; ++i) {
  76.     visits[i] = int(random(48));
  77.   }
  78.   visits = sort(visits);
  79.  
  80.   //animate visits
  81.   for (int i=0; i < (visits.length - 1); ++i) {
  82.     if(primary) {
  83.       //strokeWeight(i * 2);
  84.       //println(i*2);
  85.     }
  86.     int page_view_height = int(random(20)) * stepY;
  87.     int arc_x = visits[i] * stepX;
  88.     int next_arc_x;
  89.     if(i < (visits.length - 2)) {
  90.       next_arc_x = visits[i+1] * stepX;
  91.     } else {
  92.       next_arc_x = 1200;
  93.     }
  94.     int arc_width = int(random(1,3)) * stepX;
  95.     int max_arc_width = (next_arc_x - arc_x);
  96.     if (arc_width > max_arc_width)
  97.       arc_width = max_arc_width;
  98.     drawVisit(arc_x, arc_width, page_view_height);
  99.     if(i < (visits.length - 2)) {
  100.       connectVisit(arc_x + arc_width, next_arc_x);
  101.     }
  102.   }
  103. }
  104.  
  105. void drawTopArc(float x, float width, float height) {
  106.   x += (width * 0.5);
  107.   arc(x, graphBaseY, width, height, -PI, 0);
  108.   noFill();
  109. }
  110.  
  111. void drawBottomArc(float x, float width) {
  112.   x += (width * 0.5);
  113.   arc(x, graphBaseY, width, 10, 0, PI);
  114.   noFill();
  115. }
  116.  
  117. void drawVisit(float x, float width, float height) {
  118.   drawTopArc(x, width, height);
  119. }
  120.  
  121. void connectVisit(float x, float x2) {
  122.   drawBottomArc(x, (x2-x));
  123. }
  124.  
  125. void delay(int delay)
  126. {
  127.   int time = millis();
  128.   while(millis() - time <= delay);
  129. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top