Advertisement
Guest User

Untitled

a guest
May 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. let data = [];
  2. let maxData;
  3. let table;
  4.  
  5. function preload() {
  6. table = loadTable('assets/data.csv', 'csv', 'noHeader');
  7. openSans = loadFont('assets/OpenSans-Regular.ttf');
  8. playfairDisplay = loadFont('assets/PlayfairDisplay-Regular.ttf');
  9. lineChicken = loadImage('assets/lineChicken.png');
  10. }
  11.  
  12. function setup() {
  13. createCanvas(800, 800);
  14. angleMode(DEGREES);
  15. rectMode(BOTTOM);
  16.  
  17. for (var r = 0; r < table.getRowCount(); r++) {
  18. let row = table.getRow(r);
  19. let time = row.getString(0);
  20. let light = row.getNum(1);
  21. let temp = row.getNum(2);
  22. let sound = row.getNum(3);
  23.  
  24. sound = map(sound, 0, 100, 0, 450);
  25. temp = map(temp, 0, 1, 0, 255);
  26. light = map(light, 0, 1, 0, 255);
  27.  
  28. // Using an array of objects instead of a bunch of different arrays that correspond
  29. data.push({
  30. time: time,
  31. sound: sound,
  32. temp: temp,
  33. light: light
  34. });
  35. }
  36. maxData = max(data.map(({sound}) => sound));
  37. }
  38.  
  39. function draw() {
  40. background(43, 53, 63);
  41. fill(139, 171, 203);
  42.  
  43. var angleSeparation = 360 / data.length;
  44. var padding = 10;
  45.  
  46. if (frameCount <= 400) {
  47. maxValue = constrain(frameCount * 2, 0, 400);
  48. } else {
  49. maxValue = 400;
  50. }
  51. let offset = 200;
  52. let dataMultiplier = (height / 2 - offset - padding) / maxData;
  53.  
  54. for (let i = 0; i < data.length; i++) {
  55. push();
  56. let currentSound = data[i].sound;
  57. let currentTemp = data[i].temp;
  58. let currentLight = data[i].light;
  59.  
  60. let finalHeight = currentSound * dataMultiplier;
  61. let animatedHeight = map(maxValue, 0, 400, 0, finalHeight);
  62.  
  63. translate(width / 2, height / 2);
  64. rotate(180 + (angleSeparation * i));
  65.  
  66. stroke(currentTemp, 0, 255 - currentTemp);
  67. rect(0, offset, angleSeparation * 2, animatedHeight);
  68. stroke (255, 207, 50, currentLight);
  69. rect(0, offset, angleSeparation * 2, -animatedHeight);
  70.  
  71. rotate(-(180 + (angleSeparation * i)));
  72. let multiplier = finalHeight === 0 ? 0 : animatedHeight / finalHeight;
  73. timestamp(data[i].time, map(multiplier, 0, 1, 0, 120));
  74.  
  75. pop();
  76. }
  77. stroke (150);
  78. fill (150);
  79. ellipse(400,400,120,120);
  80. image (lineChicken,360,360,80,80);
  81. }
  82.  
  83. function timestamp(timeData, multiplier) {
  84. fill(255);
  85. stroke(255);
  86. textAlign (CENTER, CENTER);
  87. textFont (playfairDisplay);
  88. textSize (16);
  89. let date = new Date(timeData);
  90. if (date.getMinutes() === 0) {
  91. text(date.getHours(),((200-multiplier)*cos(90-(15*date.getHours()))),(-3)-((200-multiplier)*sin(90-(15*date.getHours()))));
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement