xxxxxxxxxx
182
let turntable;
let discs = [];
let lightBeam;
let neopixels;
let room;
function setup() {
createCanvas(800, 800, WEBGL);
colorMode(HSB);
turntable = new Turntable(0, 100, 0, 300);
let discColors = [color(0, 100, 100), color(60, 100, 100), color(120, 100, 100), color(180, 100, 100), color(240, 100, 100)];
for (let i = 0; i < 5; i++) {
discs.push(new Disc(0, 90 - i * 5, 0, 280 - i * 20, random(0.001, 0.005), discColors[i]));
}
lightBeam = new LightBeam(300);
neopixels = new Neopixels(300, 30);
room = new Room(1000, 1000, 500);
}
function draw() {
background(0);
camera(500, -500, 500, 0, 0, 0, 0, 1, 0);
ambientLight(20);
neopixels.display();
lightBeam.display();
turntable.display();
turntable.rotate();
for (let disc of discs) {
disc.display();
disc.rotate();
}
room.display();
drawLightParticles();
}
class Turntable {
constructor(x, y, z, radius) {
this.pos = createVector(x, y, z);
this.radius = radius;
this.rotation = 0;
}
display() {
push();
translate(this.pos.x, this.pos.y, this.pos.z);
rotateY(this.rotation);
fill(255, 50); // 반투명한 흰색
cylinder(this.radius, 20);
pop();
}
rotate() {
this.rotation += 0.01;
}
}
class Disc {
constructor(x, y, z, radius, speed, discColor) {
this.pos = createVector(x, y, z);
this.radius = radius;
this.speed = speed;
this.rotation = 0;
this.color = discColor;
this.segment = floor(random(8));
}
display() {
push();
translate(this.pos.x, this.pos.y, this.pos.z);
rotateY(this.rotation);
fill(this.color);
beginShape();
vertex(0, 0, 0);
for (let j = 0; j <= 10; j++) {
let angle = (this.segment + j / 10) * TWO_PI / 8;
let x = this.radius * cos(angle);
let z = this.radius * sin(angle);
vertex(x, 0, z);
}
endShape(CLOSE);
pop();
}
rotate() {
this.rotation += this.speed;
}
}
class LightBeam {
constructor(radius) {
this.radius = radius;
}
display() {
push();
translate(0, 110, 0);
stroke(255);
strokeWeight(3);
line(0, 0, 0, this.radius, 0, 0);
pop();
}
}
class Neopixels {
constructor(radius, ledCount) {
this.radius = radius;
this.ledCount = ledCount;
this.leds = [];
for (let i = 0; i < ledCount; i++) {
this.leds.push(color(random(360), 100, 100));
}
}
display() {
push();
translate(0, 110, 0);
for (let i = 0; i < this.ledCount; i++) {
let x = map(i, 0, this.ledCount - 1, 0, this.radius);
push();
translate(x, 0, 0);
fill(this.leds[i]);
noStroke();
sphere(5);
pop();
}
pop();
}
}
class Room {
constructor(width, length, height) {
this.width = width;
this.length = length;
this.height = height;
}
display() {
push();
noFill();
stroke(100);
box(this.width, this.height, this.length);
pop();
}
}
function drawLightParticles() {
push();
translate(0, -200, 0);
rotateX(PI/2);
for (let disc of discs) {
let discAngle = disc.rotation + disc.segment * TWO_PI / 8;
let intersectionAngle = (discAngle + PI/16) % TWO_PI;
if (intersectionAngle < PI/8) {
for (let i = 0; i < 50; i++) {
let r = random(disc.radius * 0.7, disc.radius);
let theta = random(discAngle, discAngle + PI/8);
let x = r * cos(theta);
let y = r * sin(theta);
let z = random(-50, 50);
let neopixelIndex = floor(map(r, 0, disc.radius, 0, neopixels.ledCount - 1));
let neopixelColor = neopixels.leds[neopixelIndex];
let particleColor = lerpColor(disc.color, neopixelColor, 0.5);
stroke(particleColor);
point(x, y, z);
}
}
}
pop();
}