Aktionen

Benutzer

Benutzer:Seo

Aus exmediawiki

Version vom 3. März 2026, 13:13 Uhr von Seo (Diskussion | Beiträge)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)

_Coding Drawings


_p5 code

https://editor.p5js.org/yandam1126/full/XoNfyPHN9


let mic; let threshold = 0.005; // 소리 감지 임계값 let circles = []; // 원 객체 배열

function setup() {

 createCanvas(400, 400);
 mic = new p5.AudioIn();
 mic.start();

}

function draw() {

 background(255, 255, 255);
 let vol = mic.getLevel(); // 마이크에서 소리 크기 감지
 // 소리 크기 출력 (디버깅용)
 print(vol);
 // 소리가 임계값을 넘으면 원 생성
 if (vol > threshold) {
   circles.push(new GrowingCircle(vol)); // 소리 크기 기반으로 원 생성
 }
 // 원 애니메이션
 for (let i = circles.length - 1; i >= 0; i--) {
   circles[i].grow(); // 원 크기 변화
   circles[i].show(); // 원 그리기
   if (circles[i].alpha <= 0) {
     circles.splice(i, 1); // 수명이 다한 원 제거
   }
 }

}

class GrowingCircle {

 constructor(vol) {
   this.x = random(width); // 원의 X 위치
   this.y = random(height); // 원의 Y 위치
   this.size = random(10, 100); // 초기 원의 크기 (랜덤)
   this.speed = random(0.5, 2); // 원의 크기 변화 속도
   this.alpha = 255; // 원의 투명도
   this.maxSize = map(vol, 0, 1, 50, 300); // 소리 크기에 따라 최대 크기 설정
   this.growthRate = random(0.1, 0.5); // 크기 성장 속도 (랜덤)
   this.angle = random(TWO_PI); // 원의 초기 방향 각도
   this.eccentricity = random(0.5, 1.5); // 타원의 비율 (1보다 크면 타원 형태)
 }
 grow() {
   // 원 크기 증가
   this.size += this.growthRate;
   // 원의 크기가 최대 크기를 넘지 않도록 제한
   if (this.size > this.maxSize) {
     this.size = this.maxSize;
   }


   // 원의 투명도가 0이 되면 사라지도록 설정
   if (this.alpha <= 0) {
     this.alpha = 0;
   }
 }
 show() {
   // 원의 외곽선 색상 및 투명도 설정
   noFill(); // 내부를 채우지 않음
   stroke(0, 0, 255, this.alpha); // 파란색, 투명도 적용
   strokeWeight(0.1); // 선 두께
   // 이클립스(타원) 형태로 그리기
   let w = this.size * this.eccentricity; // 타원의 너비
   let h = this.size; // 타원의 높이
   ellipse(this.x, this.y, w, h); // 타원 그리기
 }

}


function keyPressed() {

 if (key == 's') {
   save("mySVG.svg");
 }

}



_Laser cut Print



_Installation & Stamp