Skip to content

Instantly share code, notes, and snippets.

@bit101
Last active October 27, 2017 01:48
Show Gist options
  • Save bit101/29b7fcda8b02cd4044c8b61c3e808e67 to your computer and use it in GitHub Desktop.
Save bit101/29b7fcda8b02cd4044c8b61c3e808e67 to your computer and use it in GitHub Desktop.
flow fields 2, iteration 1
var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"),
width = canvas.width = window.innerWidth,
height = canvas.height = window.innerHeight;
noise.seed(Math.random());
render();
function render() {
var res = 10;
for(var x = 0; x < width; x += res) {
for(var y = 0; y < height; y += res) {
var value = getValue(x, y);
context.save();
context.translate(x, y);
context.rotate(value);
context.beginPath();
context.moveTo(0, 0);
context.lineTo(res * 1.5, 0);
context.stroke();
context.restore();
}
}
}
function getValue(x, y) {
var scale = 0.008;
return noise.perlin2(x * scale, y * scale) * Math.PI * 2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment