Skip to content

Instantly share code, notes, and snippets.

@bit101
Created October 21, 2017 18:58
Show Gist options
  • Save bit101/45e821585e333a67fa0058aa536c20a4 to your computer and use it in GitHub Desktop.
Save bit101/45e821585e333a67fa0058aa536c20a4 to your computer and use it in GitHub Desktop.
flow fields, iteration 3
var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"),
width = canvas.width = window.innerWidth,
height = canvas.height = window.innerHeight;
var count = 20000;
for(var i = 0; i < count; i++) {
var x = Math.random() * width,
y = Math.random() * height;
var value = getValue(x, y);
context.save();
context.translate(x, y);
render(value);
context.restore();
}
function getValue(x, y) {
return (x + y) * 0.001 * Math.PI * 2;
}
function render(value) {
context.rotate(value);
context.beginPath();
context.moveTo(0, 0);
context.lineTo(20, 1);
context.stroke();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment