Advertisement
Guest User

Fourier Transform | p5js

a guest
Jan 20th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let v = 0;
  2. let k = 100;
  3.  
  4. let points = [];
  5.  
  6. function setup() {
  7.   createCanvas(700, 400);
  8.   noFill();
  9. }
  10.  
  11. function draw() {
  12.   background(255);
  13.   circle1 = [cos(v), sin(v)];
  14.   circle2 = [cos(3 * v) / 3, sin(3 * v) / 3];
  15.   circle3 = [cos(5 * v) / 5, sin(5 * v) / 5];
  16.   circle4 = [cos(7 * v) / 7, sin(7 * v) / 7];
  17.   circle5 = [cos(9 * v) / 9, sin(9 * v) / 9];
  18.   circle6 = [cos(11 * v) / 11, sin(11 * v) / 11];
  19.  
  20.   pos1 = [height / 2 + k * circle1[0], height / 2 + k * circle1[1]];
  21.   pos2 = [pos1[0] + k * circle2[0], pos1[1] + k * circle2[1]];
  22.   pos3 = [pos2[0] + k * circle3[0], pos2[1] + k * circle3[1]];
  23.   pos4 = [pos3[0] + k * circle4[0], pos3[1] + k * circle4[1]];
  24.   pos5 = [pos4[0] + k * circle5[0], pos4[1] + k * circle5[1]];
  25.   pos6 = [pos5[0] + k * circle6[0], pos5[1] + k * circle6[1]];
  26.  
  27.  
  28.   points.splice(0, 0, pos6[1]);
  29.   if (points.length > 120) points.splice(119, 120);
  30.  
  31.   // Draws Circles
  32.   strokeWeight(1);
  33.   let d = 2*k
  34.   circle(height/2, height/2, d);
  35.   circle(pos1[0], pos1[1], d/3);
  36.   circle(pos2[0], pos2[1], d/5);
  37.   circle(pos3[0], pos3[1], d/7);
  38.   circle(pos4[0], pos4[1], d/9);
  39.   circle(pos5[0], pos5[1], d/11);
  40.  
  41.   // Draws Graph
  42.   for (i = 0; i < points.length-1; i++)
  43.     line(400+2*(i-1), points[i], 400+2*(i), points[i+1]);
  44.  
  45.   // Draws line from circle to graph
  46.   line(pos6[0], pos6[1], 400, pos6[1]);
  47.  
  48.   // Draws all dots
  49.   strokeWeight(4);
  50.   point(pos1[0], pos1[1]);
  51.   point(pos2[0], pos2[1]);
  52.   point(pos3[0], pos3[1]);
  53.   point(pos4[0], pos4[1]);
  54.   point(pos5[0], pos5[1]);
  55.   point(pos6[0], pos6[1]);
  56.  
  57.   v -= 0.05;
  58.   if (v < TAU) v += TAU;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement