xxxxxxxxxx
let time = 0; // Variable to control animation timing
let col_r = 100;
let col_g = 200;
let col_b = 50;
function setup() {
createCanvas(500, 700);
}
function draw() {
//Background and lava tube
push();
strokeWeight(3);
translate(-150, -80);
background(40);
lavaTube();
pop();
//Shape
push();
noStroke();
translate(width / 2, height / 2); // Translate the origin to the center of the canvas
for (let j = 0; j < 3; j++) { // Loop to create three sets of shapes
beginShape();
fill(col_r, col_g, col_b,75);
for (let i = 0; i < TWO_PI; i += TWO_PI / 200) { // Loop around a full circle
let r = 0.3333; // Set initial radius
let x = r * cos(i);
let y = r * sin(i);
let deform = map(noise(x + 100 + time, y + 200), 0, 1, -100, 100) * 0.5; // Apply Perlin noise for deformation
r = 35; // Update radius
let newX = (r + deform - j * 0.5) * cos(i);
let newY = (r + deform - j * 0.5) * sin(i);
vertex(newX, newY);
}
endShape();
}
pop();
//Shape 2
push();
noStroke();
translate(width / 2, (height / 2) - 100); // Translate the origin to the center of the canvas with a vertical offset
for (let j = 0; j < 3; j++) { // Loop to create three sets of shapes
beginShape();
fill(col_r - 30, col_g - 30, col_b - 30,75);
for (let i = 0; i < TWO_PI; i += TWO_PI / 200) { // Loop around a full circle
let r = 0.222; // Set initial radius
let x = r * cos(i);
let y = r * sin(i);
let deform = map(noise(x + 100 + time, y + 200), 0, 1, -65, 80) * 0.5; // Apply Perlin noise for deformation
r = 30; // Update radius
let newX = (r + deform - j * 0.5) * cos(i);
let newY = (r + deform - j * 0.5) * sin(i);
vertex(newX, newY);
}
endShape();
}
pop();
time += 0.003; // Increment time for animation
}
// Function to draw the lava tube
function lavaTube() {
fill(col_r, col_b, col_g, 60);
quad(360, 200, 440, 200, 490, 500, 310, 500);
fill(129, 133, 137);
quad(490, 500, 310, 500, 360, 650, 440, 650);
quad(360, 650, 440, 650, 490, 755, 310, 755);
quad(360, 200, 440, 200, 420, 100, 380, 100);
}
// Function to handle key presses
function keyPressed() {
if (key == "p") {
col_r = random(20, 255);
col_g = random(20, 255);
col_b = random(20, 255);
}
}