Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int graphBaseY = 500;
- int graphWidth = 1200;
- int graphHeight = 240;
- int stepX = graphWidth / 48;
- int stepY = graphHeight / 8;
- int screenMargin = 60;
- PFont f;
- void setup()
- {
- size(graphWidth + (screenMargin*2), 600);
- //f = createFont("Arial",8,true);
- }
- void drawGraph() {
- //graph lines
- stroke(0);
- strokeWeight(1);
- line(0, graphBaseY, graphWidth, graphBaseY);
- //period lines
- line(0, graphBaseY - 340, 0, graphBaseY + 40);
- line(300, graphBaseY - 340, 300, graphBaseY + 40);
- line(600, graphBaseY - 340, 600, graphBaseY + 40);
- line(900, graphBaseY - 340, 900, graphBaseY + 40);
- line(1200, graphBaseY - 340, 1200, graphBaseY + 40);
- //30 minute tick lines
- for(int i=0; i<48; ++i) {
- line(i * stepX, graphBaseY + 15, i * stepX, graphBaseY + 20);
- }
- //graph labels
- //textFont(f,16);
- //fill(0);
- //text("Hello Strings!",10,100);
- }
- void mouseClicked() {
- redraw();
- }
- void draw() {
- translate(screenMargin, 0);
- background(255);
- drawGraph();
- int totalVisitors = 40;
- for (int i=0; i <= totalVisitors; ++i) {
- fakeVisitPath(i, false);
- }
- fakeVisitPath(0, true);
- noLoop();
- }
- void fakeVisitPath(int index, boolean primary) {
- int totalVisits;
- if(primary) {
- totalVisits = 3 + int(random(7));
- stroke(#2A36B1, 204);
- strokeWeight(8);
- } else {
- totalVisits = 1 + int(random(10));
- color pathColor = color(150,160,210); //color(random(225),random(225),random(225));
- stroke(pathColor);
- strokeWeight(.25);
- }
- int[] visits = new int[totalVisits];
- int[] visitLengths = new int[totalVisits];
- //generate fake visits
- for (int i=0; i < visits.length; ++i) {
- visits[i] = int(random(48));
- }
- visits = sort(visits);
- //animate visits
- for (int i=0; i < (visits.length - 1); ++i) {
- if(primary) {
- //strokeWeight(i * 2);
- //println(i*2);
- }
- int page_view_height = int(random(20)) * stepY;
- int arc_x = visits[i] * stepX;
- int next_arc_x;
- if(i < (visits.length - 2)) {
- next_arc_x = visits[i+1] * stepX;
- } else {
- next_arc_x = 1200;
- }
- int arc_width = int(random(1,3)) * stepX;
- int max_arc_width = (next_arc_x - arc_x);
- if (arc_width > max_arc_width)
- arc_width = max_arc_width;
- drawVisit(arc_x, arc_width, page_view_height);
- if(i < (visits.length - 2)) {
- connectVisit(arc_x + arc_width, next_arc_x);
- }
- }
- }
- void drawTopArc(float x, float width, float height) {
- x += (width * 0.5);
- arc(x, graphBaseY, width, height, -PI, 0);
- noFill();
- }
- void drawBottomArc(float x, float width) {
- x += (width * 0.5);
- arc(x, graphBaseY, width, 10, 0, PI);
- noFill();
- }
- void drawVisit(float x, float width, float height) {
- drawTopArc(x, width, height);
- }
- void connectVisit(float x, float x2) {
- drawBottomArc(x, (x2-x));
- }
- void delay(int delay)
- {
- int time = millis();
- while(millis() - time <= delay);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement