PaTI 2016 welcome particle

From MideumWiki

Jump to: navigation, search


Contents

개요

2016년 PaTI 신입생 환영회를 위해 만들었던 작업이다.

동작 환경

processing 3.0.2

필요한 라이브러리

minim for sound input

이미지

코드

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;

PGraphics pg;
Particle[] spots = new Particle[1500];
color PGRAPHICS_COLOR = color(255);
color BACKGROUND_COLOR = color(0);

Minim minim;
AudioInput in;

float volume;
float[] volumes = new float[6];
float totalVolume;
float realVolume;
int index;

void setup()
{ 
 noCursor();
 size(displayWidth, displayHeight, P2D);
 pg = createGraphics(width, height, JAVA2D);
 pg.beginDraw();
 pg.textSize(330);
 pg.textAlign(CENTER, CENTER);
 pg.fill(PGRAPHICS_COLOR);
 pg.text("PaTI", pg.width/2, pg.height/2 - 170);
 pg.textSize(270);
 pg.text("2016", pg.width/2, pg.height/2 + 130);
 pg.endDraw();
 background(BACKGROUND_COLOR);

 for (int i = 0; i < spots.length; i++) {
   spots[i] = new Particle(255, 255, 255);
 }

 minim = new Minim(this);
 in = minim.getLineIn();

 for (int i = 0; i < volumes.length; i++) {
   volumes[i] = 0;
 }
}

void draw()
{
 volume = in.left.get(0);
 totalVolume = totalVolume - volumes[index];
 if (volume >= 0) {
   volumes[index] = volume*4000;
 }
 totalVolume = totalVolume + volumes[index];
 index = index + 1;
 if (index >= volumes.length) {
   index = 0;
 }
 realVolume = totalVolume / volumes.length;
 realVolume = constrain(realVolume, 0, 255);

 if (realVolume > 25) {
   for (int i = 0; i < spots.length; i++) {
     spots[i].rePosition();
   }
 }

 background(0);

 for (int i = 0; i < spots.length; i++) {
   spots[i].moveTrembling();
   spots[i].display();
 }
 //textSize(100);
 //textAlign(CENTER, CENTER);
 //text("2016", width/2, height/2 + 300);

 println("realVolume = " + realVolume);
}

class Particle 
{
 int posX;
 int posY;
 int colorR;
 int colorG;
 int colorB;
 int sizeX;
 int sizeY;
 float angle;

 Particle(int forColorR, int forColorG, int forColorB) {
   if (posX == 0 || posY == 0) {
     while (pg.get(posX, posY) != PGRAPHICS_COLOR) {
       posX = (int)random(0, width);
       posY = (int)random(0, height);
     }
   }
   colorR = forColorR;
   colorG = forColorG;
   colorB = forColorB;
   sizeX = 5;
   sizeY = 5;
 }

 void rePosition() {
   while (pg.get(posX, posY) != PGRAPHICS_COLOR) {
     posX = (int)random(0, width);
     posY = (int)random(0, height);
   }
 }

 void moveAngle() {
   angle = angle + 0.01;
   posX = posX + int(sin(angle)*2);
   posY = posY + int(cos(angle)*2);
 }
 
void moveTrembling() {
   posX = (int)random(posX - 4, posX + 5);
   posY = (int)random(posY - 4, posY + 5);
 }

 void display() {
   noStroke();
   //stroke(255, 100);
   fill(255, 100);
   ellipse(posX, posY, sizeX, sizeY);
 }
}
Personal tools