xxxxxxxxxx
67
let H = [];
let size = 60;
function crossHair() {
strokeWeight(1);
stroke(255, 20);
line(cx ,0, cx, height);
line(0, cy, width, cy);
}
function initHeart() {
// Define pixels of the heart
h = [
[0, 1, 1, 0, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 0, 0],
[, 0, 0, 1, 0, 0, 0]
];
// Define center point of heart
chx = (h[0].length - 1) / 2;
chy = (h.length -1 ) / 2;
// Define center of canvas
cx = width / 2;
cy = height / 2;
// Populate heart array with objects
for (y = 0; y < h.length; y++) {
for (x = 0; x < h[0].length; x++) {
if(h[y][x] === 1) {
H.push(createVector(x, y));
}
}
}
}
function drawPoints() {
stroke(10);
noStroke()
textSize(24)
textAlign(CENTER, CENTER)
for (y = 0; y < h.length; y++) {
for (x = 0; x < h[0].length; x++) {
if(h[y][x] === 1) {
text(
"+",
cx - (chx * size) + (x * size),
cy - (chy * size) + (y * size)
) // text
} // if
} // for x
} //for y
} // drawPoints()
function drawHeart() {
for (p of H) {
posX = (cx - p.x * size) + (chx * size)
posY = (cy + p.y * size) - (chy * size)
rectMode(CENTER)
rect(posX, posY, size)
}
}