Last active
December 28, 2021 12:52
-
-
Save philippbosch/5367712 to your computer and use it in GitHub Desktop.
Sine in JS and in Processing
This file contains 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 characters
var sprintf = require('sprintf').sprintf; // only needed for formatting the console output | |
var counter = 0; | |
var increase = Math.PI * 2 / 50; | |
var i=0; | |
setInterval(function() { | |
var val = Math.sin(counter-Math.PI/2)/2+0.5; | |
counter += increase; | |
console.log(sprintf("%.3f %" + Math.round(val*60) + "s", val, ".")); | |
}, 20); |
This file contains 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 characters
% node sin.js | |
0.000 . | |
0.004 . | |
0.016 . | |
0.035 . | |
0.062 . | |
0.095 . | |
0.136 . | |
0.181 . | |
0.232 . | |
0.287 . | |
0.345 . | |
0.406 . | |
0.469 . | |
0.531 . | |
0.594 . | |
0.655 . | |
0.713 . | |
0.768 . | |
0.819 . | |
0.864 . | |
0.905 . | |
0.938 . | |
0.965 . | |
0.984 . | |
0.996 . | |
1.000 . | |
0.996 . | |
0.984 . | |
0.965 . | |
0.938 . | |
0.905 . | |
0.864 . | |
0.819 . | |
0.768 . | |
0.713 . | |
0.655 . | |
0.594 . | |
0.531 . | |
0.469 . | |
0.406 . | |
0.345 . | |
0.287 . | |
0.232 . | |
0.181 . | |
0.136 . | |
0.095 . | |
0.062 . | |
0.035 . | |
0.016 . | |
0.004 . | |
0.000 . | |
0.004 . | |
0.016 . | |
0.035 . | |
0.062 . | |
0.095 . | |
0.136 . | |
0.181 . | |
0.232 . | |
0.287 . | |
0.345 . | |
0.406 . | |
0.469 . | |
0.531 . | |
0.594 . | |
0.655 . | |
0.713 . | |
0.768 . | |
0.819 . | |
0.864 . | |
0.905 . | |
0.938 . | |
0.965 . | |
0.984 . | |
0.996 . | |
1.000 . | |
0.996 . | |
0.984 . | |
0.965 . | |
0.938 . | |
0.905 . | |
0.864 . | |
0.819 . | |
0.768 . | |
0.713 . | |
0.655 . | |
0.594 . | |
0.531 . | |
0.469 . | |
0.406 . | |
0.345 . | |
0.287 . | |
0.232 . | |
0.181 . | |
0.136 . | |
0.095 . | |
0.062 . | |
0.035 . | |
0.016 . | |
0.004 . | |
0.000 . | |
0.004 . | |
0.016 . | |
0.035 . | |
0.062 . | |
0.095 . | |
0.136 . | |
0.181 . | |
0.232 . | |
0.287 . | |
0.345 . | |
0.406 . | |
0.469 . | |
0.531 . | |
0.594 . | |
0.655 . | |
0.713 . | |
0.768 . | |
0.819 . | |
0.864 . | |
0.905 . | |
0.938 . | |
0.965 . | |
0.984 . | |
0.996 . | |
1.000 . | |
0.996 . | |
0.984 . | |
0.965 . | |
0.938 . | |
0.905 . | |
0.864 . | |
0.819 . | |
0.768 . | |
0.713 . | |
0.655 . | |
0.594 . | |
0.531 . | |
0.469 . | |
0.406 . | |
0.345 . | |
0.287 . | |
0.232 . | |
0.181 . | |
0.136 . | |
0.095 . | |
0.062 . | |
0.035 . | |
0.016 . | |
0.004 . | |
0.000 . | |
0.004 . | |
0.016 . | |
0.035 . | |
0.062 . | |
0.095 . | |
0.136 . | |
0.181 . | |
0.232 . | |
0.287 . | |
0.345 . | |
0.406 . | |
0.469 . | |
0.531 . | |
0.594 . | |
0.655 . | |
^C% |
This file contains 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 characters
float counter = 0; | |
float increase = PI * 2 / 200; | |
int i = 0; | |
void draw() { | |
float value = (sin(counter-PI/2)/2+0.5); | |
counter += increase; | |
background(255*value); | |
println(value); | |
i += 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment