xxxxxxxxxx
118
let myFont;
let e1, e2, e3;
let selectedLetter = null;
let letterPositions = [];
let lastColorChangeTime = 0;
let colorChangeInterval = 1000;
let mainLetterColor;
let is3D = false;
let noiseFactor = 0;
function preload() {
myFont = loadFont('fonts/Ralgan.otf'); // Ensure the font file path is correct
}
function setup() {
createCanvas(600, 400);
textSize(200);
textFont(myFont);
textStyle(BOLD);
textAlign(CENTER, CENTER);
e1 = createVector(200, height / 2);
e2 = createVector(300, height / 2);
e3 = createVector(400, height / 2);
mainLetterColor = color(255, 0, 0); // Starting color for the letters
noStroke();
}
function draw() {
background(0);
// Apply noise if noiseFactor is non-zero
if (selectedLetter && noiseFactor !== 0) {
selectedLetter.x += random(-noiseFactor, noiseFactor);
selectedLetter.y += random(-noiseFactor, noiseFactor);
}
// Draw the letters from previous frames (the trail)
for (let i = 0; i < letterPositions.length; i++) {
let pos = letterPositions[i];
fill(pos.color);
text(pos.letter, pos.x, pos.y);
}
// Update positions array for the trail effect before drawing the main letters
letterPositions.push({ letter: 'R', x: e1.x, y: e1.y, color: mainLetterColor });
letterPositions.push({ letter: 'A', x: e2.x, y: e2.y, color: mainLetterColor });
letterPositions.push({ letter: 'Y', x: e3.x, y: e3.y, color: mainLetterColor });
// Limit the trail length by removing the oldest positions
if (letterPositions.length > 100) {
letterPositions.shift();
}
if (selectedLetter) {
if (keyIsDown(LEFT_ARROW)) selectedLetter.x -= 5;
if (keyIsDown(RIGHT_ARROW)) selectedLetter.x += 5;
if (keyIsDown(UP_ARROW)) selectedLetter.y -= 5;
if (keyIsDown(DOWN_ARROW)) selectedLetter.y += 5;
}
RAY(); // Draw the main letters
}
function RAY() {
push();
fill(mainLetterColor);
if (is3D) {
let fauxDepth = 20;
for (let i = 0; i < fauxDepth; i++) {
stroke(1000);
fill(255 - i * (mainLetterColor / fauxDepth)); // Gradient effect for 3D
text('R', e1.x - i, e1.y - i);
text('A', e2.x - i, e2.y - i);
text('Y', e3.x - i, e3.y - i);
}
} else {
stroke(1000);
text('R', e1.x, e1.y);
text('A', e2.x, e2.y);
text('Y', e3.x, e3.y);
}
pop();
}
function mousePressed() {
if (dist(mouseX, mouseY, e1.x, e1.y) < 100) {
selectedLetter = e1;
} else if (dist(mouseX, mouseY, e2.x, e2.y) < 100) {
selectedLetter = e2;
} else if (dist(mouseX, mouseY, e3.x, e3.y) < 100) {
selectedLetter = e3;
} else {
selectedLetter = null;
}
}
function keyPressed() {
if (keyCode === 82) { // 'R' key
noiseFactor += 1; // Increase the noise factor
} else if (keyCode === 89) { // 'Y' key
is3D = !is3D;
} else if (keyCode === SHIFT) { // 'Shift' key
mainLetterColor = color(random(255), random(255), random(255));
}
// Arrow keys for movement
}
function mouseDragged() {
// If a letter is selected, allow it to be moved
if (selectedLetter) {
selectedLetter.x = mouseX;
selectedLetter.y = mouseY;
}
}