xxxxxxxxxx
106
/*
I got the inspiration for the Maurer Rose part in this assignment from:
Shiffman, D. (2019). Maurer Rose. Coding in the Cabana Challenge. https://natureofcode.com/book/chapter-7-cellular-automata/
*/
let c = 0;
function preload() {
//load the image
img = loadImage("image/1.png");
img2 = loadImage("image/2.png");
img3 = loadImage("image/3.png");
img4 = loadImage("image/4.png");
img5 = loadImage("image/5.png");
myfont3 = loadFont("assets/myfont3.ttf");
myfont1 = loadFont("assets/myfont1.ttf");
}
function setup() {
createCanvas(440, 600);
}
var d = 8;
var n = 5;
function draw() {
//Setting up the group of colors that have a nice contrast with the red stroke
let t = [
color(255, 195, 0),
color(107, 203, 119),
color(84, 99, 255),
color(68, 68, 68),
];
let rancol = int(random(4));
background(236, 236, 236);
//Composition and typography
fill(t[rancol]);
textAlign(RIGHT);
textSize(15);
textFont(myfont3);
text("flower garden", width - 25, 560);
textSize(25);
textFont(myfont1);
text("GENERATIVE PATTERN", width - 30, 540);
stroke(t[rancol]);
strokeWeight(3);
line(25, 445, width - 25, 445);
//Drawing the pattern
translate((width - 400) / 2, 30);
for (var x = 0; x < 400; x = x + 400 * 0.2) {
for (var y = 0; y < 400; y = y + 400 * 0.2) {
push();
translate(x, y);
scale(0.2);
tint(t[rancol]);
drawBg();
tint(t[rancol]);
drawBg();
tint(t[rancol]);
drawBg();
drawRose(random(0, 150));
drawRose(random(0, 150));
pop();
}
}
}
function mousePressed() {
saveCanvas("frame_" + millis(), "png");
}
function drawRose(c) {
n = round(random(1, 8));
d = round(random(1, 8));
var k = n / d;
//var k = round(random(1,8));
push();
translate(200, 200);
if (k != 1 && k != 1 / 3) {
beginShape();
stroke(255, 24, 24);
//noFill();
fill(255, 24, 24, c);
strokeWeight(4);
for (var a = 0; a < TWO_PI * d; a += 0.01) {
var r = 200 * cos(k * a);
var x = r * cos(a);
var y = r * sin(a);
vertex(x, y);
}
endShape(CLOSE);
}
pop();
noLoop();
}
function drawBg() {
imageMode(CENTER);
let bg = [img, img2, img5];
let r = int(random(3));
image(bg[r], 200, 200, 400, 400);
}