xxxxxxxxxx
const phrase = "blokade"; // The phrase to fill the heart
const fontSize = 16; // Font size for better visibility
const baseScaleFactor = 10; // Base scale factor of the heart
let heartASCII = [];
const pulseSpeed = 0.1; // Speed of the pulsing effect
const pulseAmount = 2; // Amount the heart pulses (larger value = less pulse)
const rows = 40; // Number of rows for grid
const cols = 60; // Number of columns for grid
function setup() {
createCanvas(800, 800); // Larger canvas for the heart
textFont("monospace");
textSize(fontSize);
}
function draw() {
background(30);
fill(255);
// Calculate scale factor for the pulsing effect
let scaleFactor = baseScaleFactor + sin(frameCount * pulseSpeed) * pulseAmount;
// Clear previous heart rendering
heartASCII = [];
// Generate heart shape with pulsing scale factor
generateHeartShape(scaleFactor);
// Render the heart shape on the canvas
renderHeart();
}
// Generate heart shape by determining where the characters will go
function generateHeartShape(scaleFactor) {
let phraseIndex = 0;
// Loop through each row and column to create the heart shape
for (let i = 0; i < rows; i++) {
let row = [];
for (let j = 0; j < cols; j++) {
// Transform grid coordinates into heart coordinates
let x = (j - cols / 2) / scaleFactor; // Center horizontally
let y = -(i - rows / 2) / scaleFactor; // Center vertically and flip y-axis
// Refined heart shape equation to generate the classic heart outline
let heartEq = Math.pow(x, 2) + Math.pow(y, 2) - 1;
let topHeart = Math.pow(x, 2) + Math.pow(y + 0.25, 2) - 1;
// Adjusted equation to create a smooth heart curve
if (heartEq <= 0 || topHeart <= 0) {
row.push(phrase[phraseIndex]); // Add character from phrase
phraseIndex = (phraseIndex + 1) % phrase.length; // Cycle through phrase
} else {
row.push(" "); // Add space for empty areas
}
}
heartASCII.push(row);
}
}
// Render the heart shape on the canvas
function renderHeart() {
for (let i = 0; i < heartASCII.length; i++) {
for (let j = 0; j < heartASCII[i].length; j++) {
let char = heartASCII[i][j];
if (char !== " ") {
text(char, j * fontSize, i * fontSize); // Display each character
}
}
}
}