let lie = 5;
let ha = 6;
let ge = 100;
function setup() {
createCanvas(500, 600);
noLoop();
}
function draw() {
background(244);
stroke(20);
//strokeCap(ROUND);
//noFill();
moveface();
drawface();
}
function moveface(lie,ha,ge){
for (let ha1 = 0; ha1 < ha; ha1++) {
for (let lie1 = 0; lie1 < lie; lie1++) {
// Face point
let cx = lie1 * ge + ge / 2;
let cy = ha1 * ge + ge / 2;
}
function drawface(cx,cy) {
// Face
strokeWeight(4);
ellipse(cx, cy, 70, 70);
// eyes
strokeWeight(5);
for (let side = -1; side <= 1; side =side + 2) { //left or right eyes
let ex = cx + side * 14;
if (random() < 0.5) {
point(ex, cy - 8); // one point
} else {
arc(ex, cy - 8, 12, 8, 0, PI); // close eyes
}
}
}
}
}
function mousePressed() {
redraw();
}
I was attempting to integrate my code, but I found that it would not run. Upon inspection, I discovered two issues: 1. No parameters were passed when calling moveface(). The parameter names in moveface(lie, ha, ge) are the same as those of the global variables. The function uses these parameters internally, but in the draw() function, moveface() is called without passing any values, so lie, ha and ge are all undefined. ha1 < undefined will always evaluate to false, so the loop will never execute even once, leaving the screen blank. 2. cx and cy are not passed to drawface. cx and cy are local variables defined within the moveface loop; when drawface() is called separately within draw(), these values cannot be accessed and no parameters are passed. The correct approach is to calculate cx and cy within the loop and then call drawface(cx, cy) directly.
let lie = 5;
let ha = 6;
let ge = 100;
function setup() {
createCanvas(500, 600);
noLoop();
}
function draw() {
background(244);
stroke(20);
moveface(lie, ha, ge);
}
function moveface(lie, ha, ge) {
for (let ha1 = 0; ha1 < ha; ha1++) {
for (let lie1 = 0; lie1 < lie; lie1++) {
// Face point
let cx = lie1 * ge + ge / 2;
let cy = ha1 * ge + ge / 2;
drawface(cx, cy);
}
}
}
function drawface(cx, cy) {
// Face
strokeWeight(4);
ellipse(cx, cy, 70, 70);
// eyes
strokeWeight(5);
for (let side = -1; side <= 1; side = side + 2) { // left or right eyes
let ex = cx + side * 14;
if (random() < 0.5) {
point(ex, cy - 8); // one point
} else {
arc(ex, cy - 8, 12, 8, 0, PI); // close eyes
}
}
}
function mousePressed() {
redraw();
}