Last active
December 20, 2016 02:27
-
-
Save fogleman/269b1d9320b7877cfa7591ade4f08bb7 to your computer and use it in GitHub Desktop.
p5.js on bl.ocks.org
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<style> | |
body { | |
padding: 0; | |
margin: 0; | |
} | |
</style> | |
</head> | |
<body> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.5/p5.min.js"></script> | |
<script> | |
function setup() { | |
createCanvas(windowWidth, windowHeight); | |
} | |
function windowResized() { | |
resizeCanvas(windowWidth, windowHeight); | |
} | |
function wave(offset) { | |
var t = millis() / 1000; | |
var cx = width / 2; | |
var cy = height / 2; | |
var radius = min(width, height) * 0.4; | |
beginShape(); | |
for (var i = 0; i <= 360; i++) { | |
var a = radians(i); | |
var amplitude = pow((1 + cos(a - t)) / 2, 3); | |
var r = radius + cos(a * 8 - offset + t) * amplitude * 32; | |
var x = cx + cos(a) * r; | |
var y = cy + sin(a) * r; | |
vertex(x, y); | |
} | |
endShape(); | |
} | |
function draw() { | |
blendMode(BLEND); | |
background(0); | |
blendMode(ADD); | |
noFill(); | |
strokeWeight(min(width, height) * 0.02); | |
strokeJoin(ROUND); | |
stroke(255, 0, 0); | |
wave(0); | |
stroke(0, 255, 0); | |
wave(PI / 2); | |
stroke(0, 0, 255); | |
wave(PI / 1); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment