Skip to content

Commit

Permalink
Added Fourier Series
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav6670 authored and OtacilioN committed Oct 6, 2019
1 parent dd82d40 commit 46126fe
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Fourier Series/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.8.0/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.8.0/addons/p5.dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.8.0/addons/p5.sound.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8" />

</head>
<body>
<script src="sketch.js"></script>
</body>
</html>

61 changes: 61 additions & 0 deletions Fourier Series/sketch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
let time = 0;
let wave = [];
let path = [];

let slider;
let slider1;

function setup(){
createCanvas(650, 400);
slider = createSlider(1, 30, 1, 1);
slider1 = createSlider(50, 80, 50,5);
}

function draw() {
background(255);
translate(210, 200);

let x = 0;
let y = 0;

for (let i = 0; i < slider.value(); i++) {
let prevx = x;
let prevy = y;

let val = slider1.value();

let n = i * 2 + 1;
let radius = val * (4 / (n * PI));
x += radius * cos(n * time);
y += radius * sin(n * time);

var color = map(slider.value(), 0, 50, 0, 255);

noFill();
stroke(55, color, 254);
ellipse(prevx, prevy, radius * 2);

stroke('blue');
line(prevx, prevy, x, y);
}
wave.unshift(y);

translate(250, 0);
stroke(255, 0, 0);
line(x - 250, y, 0, wave[0]);
beginShape();
noFill();
for (let i = 0; i < wave.length; i++) {
vertex(i, wave[i]);
strokeWeight(1.5);
stroke('green');
}
endShape();

time += 0.05;

if (wave.length > 250) {
wave.pop();
}
}

8 changes: 8 additions & 0 deletions Fourier Series/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
html, body {
margin: 0;
padding: 0;
}
canvas {
display: block;
}

0 comments on commit 46126fe

Please sign in to comment.