xxxxxxxxxx
50
let evo;
let img;
let shouldImprove = true;
let rectShapesJson;
let triShapesJson;
function preload() {
img = loadImage('profil.png');
rectShapesJson = loadJSON('https://gist.githubusercontent.com/mikakruschel/369d06f945a76264abbf93a290edde6a/raw/rectShapes.json');
triShapesJson = loadJSON('https://gist.githubusercontent.com/mikakruschel/369d06f945a76264abbf93a290edde6a/raw/triShapes.json');
}
function setup() {
createCanvas(img.width, img.height);
evo = new Evolution(img, Triangle, 100, 0.05, 0.05);
evo.shapes = Object.values(triShapesJson).map(e => new Triangle(e.p1,e.p2,e.p3,e.opacity,e.whiteScale))
/*evo = new Evolution(img, Rectangle, 100, 0.05, 0.05);
evo.shapes = Object.values(rectShapesJson).map(e => new Rectangle(e.x, e.y, e.w, e.h, e.opacity, e.whiteScale));*/
evo.numOfElements = evo.shapes.length;
//evo.generateRandomShapes();
//evo.generateRandomGoodShapes();
pixelDensity(1);
}
function draw() {
if (shouldImprove && evo.shapes.length < evo.numOfElements) evo.add();
else if (shouldImprove) evo.update();
else {
background(0);
/*image(img, 0, 0);
fill(0, 0, 0, 100);
rect(0, 0, width, height);*/
evo.draw();
fill(255,0,255)
text(evo.curScore, 10, 10)
}
}
function keyPressed() {
shouldImprove = !shouldImprove;
}