Created
February 26, 2016 19:49
-
-
Save runemadsen/84c5d0a8cc71e8a64cbe to your computer and use it in GitHub Desktop.
This file contains hidden or 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 r = new Rune({ | |
container: "#canvas", | |
width: 800, | |
height: 600 | |
}); | |
// Create a polygon of your letter. This will be closing, but don't | |
// worry about that. | |
var n = r.polygon(200, 200) | |
.lineTo(0, 0) | |
.lineTo(0, -100) | |
.lineTo(75, 0) | |
.lineTo(75, -100); | |
// Loop through each of the vectors in the polygon. This is basically | |
// the x,y positions where the lines end | |
for(var i = 1; i < n.vars.vectors.length; i++) { | |
// to get the actual change between this and the last point, | |
// subtract the last point from the current point. | |
var thisVector = n.vars.vectors[i]; | |
var prevVector = n.vars.vectors[i-1]; | |
var direction = thisVector.sub(prevVector); | |
// loop 40 times | |
for(var j = 0; j < 40; j++) { | |
// find a random position on this vector | |
var newDir = direction.multiply(Rune.random(1)); | |
// add this random position back to the original x | |
var x = prevVector.x + newDir.x + n.vars.x; | |
var y = prevVector.y + newDir.y + n.vars.y; | |
// draw something on that x,y | |
r.line(x, y, x + Rune.random(-10, 10), y + Rune.random(-10, 10)) | |
} | |
} | |
n.removeParent(); | |
r.draw(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment