Created
October 22, 2017 16:10
-
-
Save bit101/a9b2e15bd9849adea8bc344e9b16109a to your computer and use it in GitHub Desktop.
flow fields, iteration 4
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 canvas = document.getElementById("canvas"), | |
context = canvas.getContext("2d"), | |
width = canvas.width = window.innerWidth, | |
height = canvas.height = window.innerHeight; | |
var count = 50000; | |
context.lineWidth = 0.25; | |
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 (Math.sin(x * 0.01) + Math.sin(y * 0.01)) * Math.PI * 2; | |
} | |
function render(value) { | |
context.rotate(value); | |
context.beginPath(); | |
context.moveTo(0, 0); | |
context.lineTo(Math.random() * 30 + 30, 1); | |
context.stroke(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment