Created
February 16, 2020 13:56
-
-
Save moritzebeling/52c6315537a5cb3535d7c44cce81c98e to your computer and use it in GitHub Desktop.
Place random line on cnavas
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
function randomPoint() { | |
return { | |
x: round(random(0, width / 20)) * 20, | |
y: round(random(0, height / 20)) * 20 | |
}; | |
} | |
let rule = { | |
lines: [], | |
reinvent: function() { | |
let n = random(1, 10); | |
this.lines = []; | |
for (let i = 0; i < 1; i++) { | |
let l = random(1, 10); | |
let x = []; | |
for (let j = 0; j < 6; j++) { | |
x.push(randomPoint()); | |
} | |
this.lines.push(x); | |
} | |
} | |
}; | |
function setup() { | |
createCanvas(400, 400); | |
frameRate(1); | |
stroke(255); | |
strokeWeight(5); | |
noFill(); | |
} | |
function draw() { | |
background(0); | |
rule.reinvent(); | |
for (let i = 0; i < rule.lines.length; i++) { | |
beginShape(); | |
for (let j = 0; j < rule.lines[i].length; j++) { | |
vertex(rule.lines[i][j].x,rule.lines[i][j].y); | |
} | |
endShape(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment