-
-
Save kylebradshaw/8336476cc6584bfacb80f98f4ebbfe25 to your computer and use it in GitHub Desktop.
Revisions
-
gkhays revised this gist
Mar 4, 2019 . 2 changed files with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,8 @@ ### To Do - [ ] Add links to JSFiddle - [x] [Visualize with bl.ocks.org](https://bl.ocks.org/gkhays/c58a109172d543ee095e57f0eb3606f2). - [x] [Vistualize with GistRun](https://gist.run/?id=c58a109172d543ee095e57f0eb3606f2&sha=20a424503f420914e14d299d123ebcc4a0d3229c). I am revisiting the [Fourier transform](https://en.wikipedia.org/wiki/Fourier_transform) so I thought it might be nice to come up with some visualizations. My first stop was to plot a sine wave in JavaScript, then to animate it. I am using the `window.requestAnimationFrame()` method. I've documented the steps in reverse order. LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
gjtorikian revised this gist
Jul 14, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # Draw a Sine Wave in JavaScript ### To Do - [ ] Add links to JSFiddle - [x] [Visualize](https://bl.ocks.org/gkhays/c58a109172d543ee095e57f0eb3606f2) with bl.ocks.org. I am revisiting the [Fourier transform](https://en.wikipedia.org/wiki/Fourier_transform) so I thought it might be nice to come up with some visualizations. My first stop was to plot a sine wave in JavaScript, then to animate it. I am using the `window.requestAnimationFrame()` method. I've documented the steps in reverse order. -
gjtorikian revised this gist
Jul 14, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # Draw a Sine Wave in JavaScript ### To Do - [x] Add links to JSFiddle - [x] [Visualize](https://bl.ocks.org/gkhays/c58a109172d543ee095e57f0eb3606f2) with bl.ocks.org. I am revisiting the [Fourier transform](https://en.wikipedia.org/wiki/Fourier_transform) so I thought it might be nice to come up with some visualizations. My first stop was to plot a sine wave in JavaScript, then to animate it. I am using the `window.requestAnimationFrame()` method. I've documented the steps in reverse order. -
gjtorikian revised this gist
Jul 14, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # Draw a Sine Wave in JavaScript ### To Do - [ ] Add links to JSFiddle - [x] [Visualize](https://bl.ocks.org/gkhays/c58a109172d543ee095e57f0eb3606f2) with bl.ocks.org. I am revisiting the [Fourier transform](https://en.wikipedia.org/wiki/Fourier_transform) so I thought it might be nice to come up with some visualizations. My first stop was to plot a sine wave in JavaScript, then to animate it. I am using the `window.requestAnimationFrame()` method. I've documented the steps in reverse order. -
gjtorikian revised this gist
Jul 14, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # Draw a Sine Wave in JavaScript ### To Do - [x] Add links to JSFiddle - [x] [Visualize](https://bl.ocks.org/gkhays/c58a109172d543ee095e57f0eb3606f2) with bl.ocks.org. I am revisiting the [Fourier transform](https://en.wikipedia.org/wiki/Fourier_transform) so I thought it might be nice to come up with some visualizations. My first stop was to plot a sine wave in JavaScript, then to animate it. I am using the `window.requestAnimationFrame()` method. I've documented the steps in reverse order. -
gkhays revised this gist
Jan 24, 2018 . 2 changed files with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ ### To Do - [ ] Add links to JSFiddle - [x] [Visualize](https://bl.ocks.org/gkhays/c58a109172d543ee095e57f0eb3606f2) with bl.ocks.org. I am revisiting the [Fourier transform](https://en.wikipedia.org/wiki/Fourier_transform) so I thought it might be nice to come up with some visualizations. My first stop was to plot a sine wave in JavaScript, then to animate it. I am using the `window.requestAnimationFrame()` method. I've documented the steps in reverse order. @@ -11,7 +12,7 @@ The end result is an oscillating sine wave. Nothing ground-breaking but it looks  The JavaScript function to plot the sine wave uses the `Math.sin()` function, which is called repeatedly given a different starting point on the y-axis. See the simple plot below. In this case, the `draw()` function makes the repeat calls via `window.requestAnimationFrame(draw)`. ```js function draw() { LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
gkhays revised this gist
Oct 28, 2016 . 2 changed files with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,7 +34,7 @@ function draw() { ## Superimposed Sine Waves After I learned to plot a sine wave, I visualized how to draw multiple sine waves in order to achieve the oscillation effect in the animation. It looked pretty cool, so I kept it around. It reminds me of [Spirograph](https://en.wikipedia.org/wiki/Spirograph). :smile:  LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
gkhays revised this gist
Sep 16, 2016 . 2 changed files with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -100,4 +100,10 @@ I found this animated gif in Reddit. See [This should be the first thing shown in any Trigonometry class](https://www.reddit.com/r/pics/comments/bnzgx/this_should_be_the_first_thing_shown_in_any/). From the Fourier series definition in Wikipedia.  [Approximation of a square wave](https://en.wikipedia.org/wiki/Fourier_series#Definition). * [What You Can Do With Gists on Github?](http://www.labnol.org/internet/github-gist-tutorial/28499/) LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
gkhays revised this gist
Sep 16, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,7 @@ function draw() { } ``` **Note**: The astute observer may observe the animation above isn't actually JavaScript but is instead an animated gif. I did this since it is currently not possible to run JavaScript from a gist although it is possible using `bl.ocks.org`. ## Superimposed Sine Waves -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,6 +30,8 @@ function draw() { } ``` Note: The astute observer may note the animation above isn't actually JavaScript but is instead an animated gif. I did this since it is currently not possible to run JavaScript from a gist although it is possible using `bl.ocks.org`. ## Superimposed Sine Waves After I learned to plot a sine wave, I visualized how to draw multiple sine waves in order to achieve the oscillation effect in the animation. It looked pretty cool, so I get it around. It reminds me of [Spirograph](https://en.wikipedia.org/wiki/Spirograph). :smile: @@ -97,3 +99,5 @@ I found this animated gif in Reddit.  See [This should be the first thing shown in any Trigonometry class](https://www.reddit.com/r/pics/comments/bnzgx/this_should_be_the_first_thing_shown_in_any/). * [What You Can Do With Gists on Github?](http://www.labnol.org/internet/github-gist-tutorial/28499/) -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ I am revisiting the [Fourier transform](https://en.wikipedia.org/wiki/Fourier_tr ## Simple Animation The end result is an oscillating sine wave. Nothing ground-breaking but it looks pretty cool to me.  -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -91,3 +91,9 @@ Interesting tidbit: If we uncomment `ctx.moveTo(x, y)` just before the loop we g * [Basic animations](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations) * [window.requestAnimationFrame()](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame) * [WindowTimers.setInterval()](https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval) I found this animated gif in Reddit.  See [This should be the first thing shown in any Trigonometry class](https://www.reddit.com/r/pics/comments/bnzgx/this_should_be_the_first_thing_shown_in_any/). -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
gkhays revised this gist
Sep 14, 2016 . No changes.There are no files selected for viewing
-
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -51,6 +51,13 @@ My initial attempt to draw a sine wave on an `HTML5` canvas.  ```html <body onload="init()"> <h3>Oscillating Sine Wave</h3> <canvas id="canvas" width="500" height="100"></canvas> </body> ``` ```js function plotSine(ctx) { var width = ctx.canvas.width; -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 17 additions and 26 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,43 +7,32 @@ I am revisiting the [Fourier transform](https://en.wikipedia.org/wiki/Fourier_tr ## Simple Animation I'm fairly happy with the animation.  The JavaScript funtion to plot the sine wave uses the `Math.sin()` function, which is called repeatedly given a different starting point on the y-axis. See the simple plot below. In this case, the `draw()` function makes the repeat calls via `window.requestAnimationFrame(draw)`. ```js function draw() { var canvas = document.getElementById("canvas"); var context = canvas.getContext("2d"); context.clearRect(0, 0, 500, 500); showAxes(context); context.save(); plotSine(context, step, 50); context.restore(); step += 4; window.requestAnimationFrame(draw); } ``` ## Superimposed Sine Waves After I learned to plot a sine wave, I visualized how to draw multiple sine waves in order to achieve the oscillation effect in the animation. It looked pretty cool, so I get it around. It reminds me of [Spirograph](https://en.wikipedia.org/wiki/Spirograph). :smile:  @@ -58,6 +47,8 @@ for (var i = -4; i < canvas.height; i += step) { ## Simple Plot My initial attempt to draw a sine wave on an `HTML5` canvas.  ```js @@ -84,7 +75,7 @@ function plotSine(ctx) { } ``` Interesting tidbit: If we uncomment `ctx.moveTo(x, y)` just before the loop we get a vertical line.  -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
Binary file not shown. -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 11 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,8 +43,19 @@ function plotSine(ctx, xOffset, yOffset) { ## Superimposed Sine Waves After I learned to plot a sine wave, I visualized how to draw multiple sine waves in order to achieve the oscillation effect in the animation. It looked pretty cool, so I get it around. It reminds me of [Spirograph](https://en.wikipedia.org/wiki/Spirograph) :smile:  The `step` advances the starting point along the y-axis. ```js var step = 4; for (var i = -4; i < canvas.height; i += step) { plotSine(context, i, 54 + i); } ``` ## Simple Plot  @@ -68,7 +79,6 @@ function plotSine(ctx) { y = height/2 + amplitude * Math.sin(x/frequency); ctx.lineTo(x, y); x = x + 1; } ctx.stroke(); } -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,12 +3,14 @@ ### To Do - [ ] Add links to JSFiddle I am revisiting the [Fourier transform](https://en.wikipedia.org/wiki/Fourier_transform) so I thought it might be nice to come up with some visualizations. My first stop was to plot a sine wave in JavaScript, then to animate it. I am using the `window.requestAnimationFrame()` method. I've documented the steps in reverse order. ## Simple Animation  The JavaScript funtion to plot the sine wave uses the `Math.sin()` function, which is called repeatedly given a different starting point on the y-axis. ```js function plotSine(ctx, xOffset, yOffset) { var width = ctx.canvas.width; -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,6 +41,7 @@ function plotSine(ctx, xOffset, yOffset) { ## Superimposed Sine Waves  ## Simple Plot -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,6 +39,9 @@ function plotSine(ctx, xOffset, yOffset) { } ``` ## Superimposed Sine Waves ## Simple Plot  -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,12 @@ # Draw a Sine Wave in JavaScript ### To Do - [ ] Add links to JSFiddle I am revisiting the [Fourier transform](https://en.wikipedia.org/wiki/Fourier_transform) so I thought it might be nice to come up with some visualizations. My first stop was to plot a sine wave in JavaScript, then to animate it. I am using the `window.requestAnimationFrame()` method. ## Simple Animation  ```js @@ -37,6 +39,8 @@ function plotSine(ctx, xOffset, yOffset) { } ``` ## Simple Plot  ```js -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Draw a Sine Wave in JavaScript **To Do** - [ ] Add links to JSFiddle I am revisiting the [Fourier transform](https://en.wikipedia.org/wiki/Fourier_transform) so I thought it might be nice to come up with some visualizations. My first stop was to plot a sine wave in JavaScript, then to animate it. I am using the `window.requestAnimationFrame()` method. -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # Draw a Sine Wave in JavaScript *To Do* - [ ] Add links to JSFiddle I am revisiting the [Fourier transform](https://en.wikipedia.org/wiki/Fourier_transform) so I thought it might be nice to come up with some visualizations. My first stop was to plot a sine wave in JavaScript, then to animate it. I am using the `window.requestAnimationFrame()` method. -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 41 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,42 @@ # Draw a Sine Wave in JavaScript *To Do* [] Add links to JSFiddle I am revisiting the [Fourier transform](https://en.wikipedia.org/wiki/Fourier_transform) so I thought it might be nice to come up with some visualizations. My first stop was to plot a sine wave in JavaScript, then to animate it. I am using the `window.requestAnimationFrame()` method.  ```js function plotSine(ctx, xOffset, yOffset) { var width = ctx.canvas.width; var height = ctx.canvas.height; var scale = 20; ctx.beginPath(); ctx.lineWidth = 2; ctx.strokeStyle = "rgb(66,44,255)"; var x = 4; var y = 0; var amplitude = 40; var frequency = 20; ctx.moveTo(x, 50); while (x < width) { y = height/2 + amplitude * Math.sin((x+xOffset)/frequency); ctx.lineTo(x, y); x++; } ctx.stroke(); ctx.save(); drawPoint(ctx, y); ctx.stroke(); ctx.restore(); } ```  ```js @@ -32,3 +67,9 @@ function plotSine(ctx) { If we uncomment `ctx.moveTo(x, y)` just before the loop we get a vertical line.  ## References * [Basic animations](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations) * [window.requestAnimationFrame()](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame) * [WindowTimers.setInterval()](https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval) -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Draw a Sine Wave in JavaScript   -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ # Draw a Sine Wave in JavaScript   ```js -
gkhays revised this gist
Sep 14, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed.
NewerOlder