Skip to content

Instantly share code, notes, and snippets.

@moritzebeling
Created February 16, 2020 13:56
Show Gist options
  • Save moritzebeling/52c6315537a5cb3535d7c44cce81c98e to your computer and use it in GitHub Desktop.
Save moritzebeling/52c6315537a5cb3535d7c44cce81c98e to your computer and use it in GitHub Desktop.
Place random line on cnavas
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