let angleX = 0; let angleY = 0; let dragging = false; let lastMouseX, lastMouseY; let leftArmAngle = 10; let rightArmAngle = -10; let leftLegAngle = 10; let rightLegAngle = -10; let imgFace, imgArmsLegs, imgBody; let leftEyeX = -20, leftEyeY = -135, leftEyeZ = 55; let rightEyeX = 20, rightEyeY = -135, rightEyeZ = 55; let pupilOffsetX = 0, pupilOffsetY = 0; let cigaretteX = 0; let cigaretteY = -81; let cigaretteZ = 79; let cigaretteAngleX = 20.1; let cigaretteAngleY = 0; let cigaretteAngleZ = 0; let smokeParticles = []; let leaves = []; function preload() { imgFace = loadImage('/content/05d6f742d2e5054bdd8f8c7240f696a05d3f483f245c992dac042de002e36c3di0'); imgArmsLegs = loadImage('/content/05d6f742d2e5054bdd8f8c7240f696a05d3f483f245c992dac042de002e36c3di0'); imgBody = loadImage('/content/05d6f742d2e5054bdd8f8c7240f696a05d3f483f245c992dac042de002e36c3di0'); } function setup() { createCanvas(windowWidth, windowHeight, WEBGL); for (let i = 0; i < 10; i++) { leaves.push(new MarijuanaLeaf(random(-width / 2, width / 2), random(-height, height), random(80, 150))); } } function windowResized() { resizeCanvas(windowWidth, windowHeight); } function draw() { background(0); push(); translate(0, 0, -500); for (let leaf of leaves) { leaf.update(); leaf.display(); } pop(); directionalLight(255, 255, 255, 0.5, 1, -0.5); ambientLight(150); if (dragging) { angleY += (mouseX - lastMouseX) * 0.5; angleX += (mouseY - lastMouseY) * 0.5; lastMouseX = mouseX; lastMouseY = mouseY; } rotateX(radians(angleX)); rotateY(radians(angleY)); push(); translate(0, -125, 0); texture(imgFace); box(100, 100, 100); pop(); push(); translate(0, 0, 0); texture(imgBody); box(60, 120, 30); pop(); push(); translate(-55, 0, 0); rotateZ(radians(leftArmAngle)); texture(imgArmsLegs); box(30, 120, 30); pop(); push(); translate(55, 0, 0); rotateZ(radians(rightArmAngle)); texture(imgArmsLegs); box(30, 120, 30); pop(); push(); translate(-20, 132, 0); rotateX(radians(leftLegAngle)); texture(imgArmsLegs); box(30, 120, 30); pop(); push(); translate(20, 132, 0); rotateX(radians(rightLegAngle)); texture(imgArmsLegs); box(30, 120, 30); pop(); drawEye(leftEyeX, leftEyeY, leftEyeZ); drawEye(rightEyeX, rightEyeY, rightEyeZ); drawMouth(0, -90, 51); drawCigarette(cigaretteX, cigaretteY, cigaretteZ, cigaretteAngleX, cigaretteAngleY, cigaretteAngleZ); updateSmoke(); } function drawEye(x, y, z) { push(); translate(x, y, z); fill(255); noStroke(); sphere(10); stroke(255, 0, 0); strokeWeight(1); for (let i = 0; i < 10; i++) { let angle = TWO_PI / 10 * i; let x1 = cos(angle) * 10; let y1 = sin(angle) * 10; let x2 = x1 + random(-5, 5); let y2 = y1 + random(-5, 5); line(x1, y1, x2, y2); } noStroke(); fill(0); translate(pupilOffsetX, pupilOffsetY, 10); sphere(2); pop(); } function drawMouth(x, y, z) { push(); translate(x, y, z); fill(255, 0, 0); noStroke(); ellipse(0, 0, 30, 15); pop(); } function drawCigarette(x, y, z, angleX, angleY, angleZ) { push(); translate(x, y, z); rotateX(angleX); rotateY(angleY); rotateZ(angleZ); fill(200, 200, 200); noStroke(); cylinder(5, 50); translate(0, 25, 0); fill(255, 100, 100); cylinder(5, 5); pop(); if (frameCount % 5 == 0) { smokeParticles.push(new SmokeParticle(x, y, z + 25)); } } class SmokeParticle { constructor(x, y, z) { this.position = createVector(x, y, z); this.lifespan = 255; } update() { this.position.y -= 1; this.lifespan -= 2; } display() { push(); translate(this.position.x, this.position.y, this.position.z); fill(255, this.lifespan); noStroke(); sphere(5); pop(); } isDead() { return this.lifespan < 0; } } function updateSmoke() { for (let i = smokeParticles.length - 1; i >= 0; i--) { smokeParticles[i].update(); smokeParticles[i].display(); if (smokeParticles[i].isDead()) { smokeParticles.splice(i, 1); } } } function mousePressed() { dragging = true; lastMouseX = mouseX; lastMouseY = mouseY; } function mouseReleased() { dragging = false; } function touchStarted() { dragging = true; lastMouseX = mouseX; lastMouseY = mouseX; return false; } function touchEnded() { dragging = false; return false; } function movePupils() { pupilOffsetX = sin(frameCount * 0.02) * 2; pupilOffsetY = cos(frameCount * 0.02) * 2; } setInterval(movePupils, 100); class MarijuanaLeaf { constructor(x, y, size) { this.x = x; this.y = y; this.size = size; } update() { this.y += 2; if (this.y > height / 2) { this.y = -height / 2; this.x = random(-width / 2, width / 2); } } display() { push(); translate(this.x, this.y, 0); drawMarijuanaLeaf(0, 0, this.size); pop(); } } function drawMarijuanaLeaf(x, y, size) { let leafColor = color(34, 139, 34); fill(leafColor); noStroke(); drawLeaflet(x, y, size, 0); for (let i = 1; i <= 3; i++) { let angle = PI / 6 * i; drawLeaflet(x, y, size * (1 - i * 0.15), angle); drawLeaflet(x, y, size * (1 - i * 0.15), -angle); } fill(leafColor); rect(x - size * 0.05, y, size * .1, size * .5); } function drawLeaflet(x, y, size, angle) { push(); translate(x, y); rotate(angle); beginShape(); vertex(0, 0); bezierVertex(size * 0.1, -size * 0.3, size * 0.3, -size * 0.7, 0, -size); bezierVertex(-size * 0.3, -size * 0.7, -size * 0.1, -size * 0.3, 0, 0); endShape(CLOSE); pop(); } // Your p5.js script goes here