Commit 30b31965e1a181879eedd09254034d8251ebc216

trying out beatdetect
src/intro/Effu.java
(1 / 1)
  
1414 p = parent;
1515 }
1616
17 abstract void draw(float demotime);
17 abstract void draw(float demotime, boolean beat);
1818}
src/intro/Main.java
(23 / 8)
  
11package intro;
22import processing.core.*;
3import ddf.minim.*;
4import ddf.minim.analysis.*;
35
46@SuppressWarnings("serial")
57public class Main extends PApplet {
68
7 Effu text;
89 Effu ps;
10 TextEngine te;
11 Minim minim;
12 AudioPlayer song;
13 BeatDetect beat;
14
915
1016 public void setup(){
1117 size(1024, 768, P3D);
12 text = new Text(this, " HYPERION code: jypa music: King Thrill");
1318 ps = new ParticleSystem(this);
19 te = new TextEngine(this);
1420 frameRate(60);
1521 smooth();
16 strokeCap(ROUND);
22 minim = new Minim(this);
23 song = minim.loadFile("somnia_demo-mix.mp3", 2048);
24 song.play();
25 beat = new BeatDetect(song.bufferSize(), song.sampleRate());
26 //beat.setSensitivity(300);
1727 }
1828
1929 public void draw(){
2030 background(0);
21 ps.draw(millis());
22 //text.draw(millis());
23 stroke(52,51,52);
24 noFill();
25 rect(0,0,width-1,height-1);
31 beat.detect(song.mix);
32 beat.drawGraph(this);
33 ps.draw(millis(), beat.isRange(0,5,5));
34 //te.draw(millis());
35 }
36
37 public void stop(){
38 song.close();
39 minim.stop();
40 super.stop();
2641 }
2742
2843 /**
src/intro/Metaball.java
(1 / 2)
  
66 public float dx;
77 public float dy;
88 public int speed;
9 public int size;
10
9 public int size;
1110}
src/intro/Metaballs.java
(1 / 1)
  
2727 }
2828
2929 @Override
30 void draw(float demotime) {
30 void draw(float demotime, boolean beat) {
3131 for (Metaball ball : balls) {
3232 ball.x += ball.dx * ball.speed;
3333 ball.y += ball.dy * ball.speed;
src/intro/ParticleSystem.java
(40 / 28)
  
1212 PGraphics pg;
1313 PGraphics bg;
1414 int particleJitter = 5;
15 int cubeJitter = 50; //shake it baby
15 int cubeJitter = 2; //shake it baby
1616 float ry = 0;
1717 float rx = 0;
1818 float rz = 0;
2020 float rdx = 0.06f;
2121 float rdz = 0.008f;
2222
23 int parCap = 15000;
24 int parSum = 0;
25 int parIter = 1500;
26
2327 ParticleSystem(PApplet parent) {
2428 super(parent);
2529 r = new Random(1);
2630 pg = p.createGraphics(p.width, p.height, PConstants.P3D);
2731 particles = new ArrayList<Particle>();
28 Particle particle;
29 for (int i=0; i< 15000; i++){
30 particle = new Particle();
31 particle.x = r.nextInt(p.width);
32 particle.y = r.nextInt(p.height);
33 particle.dx = r.nextFloat(); if (r.nextBoolean()) particle.dx *= -1;
34 particle.dy = r.nextFloat(); if (r.nextBoolean()) particle.dy *= -1;
35 particle.xp = particle.yp = 0;
36 particle.r = (int) (r.nextFloat() * (88-62) + 62);
37 particle.g = (int) (r.nextFloat() * (107-81) + 81);
38 particle.b = (int) (r.nextFloat() * (166-140) + 140);
39 particle.rp = particle.gp = particle.bp = 0;
40 particle.size = r.nextFloat() * 20;
41 particle.speed = 5;
42 particles.add(particle);
43 }
4432 bg = p.createGraphics(p.width, p.height, PConstants.P3D);
4533 mBalls = new Metaballs(p);
4634 }
4735
4836 @Override
49 public void draw(float demotime) {
37 public void draw(float demotime, boolean beat) {
5038 update();
51 //drawCube();
52 drawMetaballs(demotime);
39 drawCube(beat);
40 //drawMetaballs(demotime, beat);
5341 int x, y, minus=0;
5442 pg.beginDraw();
5543 pg.background(0);
6060 }
6161
6262 private void update(){
63 addParticles();
6364 double distance;
6465 for (Particle particle: particles){
6566 particle.x += (int) (particle.dx * particle.speed);
8181
8282 }
8383
84 private void drawCube(){
84 private void addParticles(){
85 if (parSum < parCap){
86 parSum += parIter;
87 Particle particle;
88 for (int i=0; i< parIter; i++){
89 particle = new Particle();
90 particle.x = r.nextInt(p.width);
91 particle.y = r.nextInt(p.height);
92 particle.dx = r.nextFloat(); if (r.nextBoolean()) particle.dx *= -1;
93 particle.dy = r.nextFloat(); if (r.nextBoolean()) particle.dy *= -1;
94 particle.xp = particle.yp = 0;
95 particle.r = (int) (r.nextFloat() * (88-62) + 62);
96 particle.g = (int) (r.nextFloat() * (107-81) + 81);
97 particle.b = (int) (r.nextFloat() * (166-140) + 140);
98 particle.rp = particle.gp = particle.bp = 0;
99 particle.size = r.nextFloat() * 20;
100 particle.speed = 5;
101 particles.add(particle);
102 }
103 }
104 }
105
106 private void drawCube(boolean beat){
85107 bg.beginDraw();
86108
87109 // First light, so we wont rotate them
114114 bg.lightSpecular(200, 200, 200);
115115
116116 // Then translation and rotation
117 bg.translate(p.width/2 + r.nextInt(cubeJitter) - cubeJitter/2, p.height/2 + r.nextInt(cubeJitter) - cubeJitter/2, 0);
117 bg.translate(p.width/2 + r.nextInt(cubeJitter) - cubeJitter/2, p.height/2 + r.nextInt(cubeJitter) - cubeJitter/2, r.nextInt(cubeJitter));
118118 bg.rotateY(ry);
119119 bg.rotateX(rx);
120120 bg.rotateZ(rz);
125125 bg.fill(50,50,50);
126126 bg.strokeWeight(20);
127127 bg.stroke(20,20,0);
128 bg.box(350);
129 //bg.noStroke();
130 //bg.sphere(300);
128 int size = 200;
129 if (beat) {
130 size = 350;
131 }
132 bg.box(size);
131133 bg.endDraw();
132134 bg.loadPixels();
133135
134136 }
135137
136 private void drawMetaballs(float demotime){
137 mBalls.draw(demotime);
138 private void drawMetaballs(float demotime, boolean beat){
139 mBalls.draw(demotime, beat);
138140 bg.beginDraw();
139 bg.background(0);
140141 bg.image(mBalls.pg,0,0,bg.width,bg.height);
141142 bg.endDraw();
142143 }
src/intro/Text.java
(10 / 4)
  
99 PGraphics right;
1010 PFont font;
1111 int x = 0;
12 int speed = 35;
1213
1314
1415 public Text(PApplet parent, String text){
1516 super(parent);
1617 msg = text;
17 font = p.createFont("hyperion.ttf", 200, true);
18 font = p.createFont("hyperion.ttf", 160, true);
1819 pg = p.createGraphics(p.width, p.height, PConstants.P3D);
1920 left = p.createGraphics(p.width/2, p.height, PConstants.P3D);
2021 right = p.createGraphics(p.width/2, p.height, PConstants.P3D);
2122 }
2223
23 public void draw(float demotime){
24 public Text(PApplet parent, String text, int speed){
25 this(parent, text);
26 this.speed = speed;
27 }
28
29 public void draw(float demotime, boolean beat){
2430 pg.beginDraw();
2531 pg.background(0,0);
2632 pg.textFont(font);
27 pg.fill(170, 159, 127);
33 pg.fill(140, 140, 145);
2834 pg.text(msg, x, 600);
29 x-= 30;
35 x-= speed;
3036 pg.endDraw();
3137 splitImage();
3238 p.rotateY(-0.5f);
src/intro/TextEngine.java
(26 / 0)
  
1package intro;
2
3import processing.core.PApplet;
4
5public class TextEngine extends Effu{
6
7 Text credits;
8 Text title;
9 Text source;
10 Text greets;
11
12
13 TextEngine(PApplet parent) {
14 super(parent);
15 title = new Text(p, " HYPERION", 20);
16 credits = new Text(p, " code : jypa music : King Thrill");
17 source = new Text(p, " source : http://yousource.it.jyu.fi/hyperion");
18 greets = new Text(p, " we greet : Hot Lamda Lovin' Tekotuotanto Cubicle zipola everyone @ INSTANSSI ");
19 }
20
21 @Override
22 void draw(float demotime, boolean beat) {
23 credits.draw(demotime, beat);
24 }
25
26}