Hi
I have tried to take something I created in Mobile Processing over to Processing, in order to try and embed in a page. I think I have the syntax right for the sound events in the data file, but I cannot seem to create the right syntax for an array for all the 9 images. Can anyone help point out where I am going wrong?
Code:
import pitaru.sonia_v2_9.*;
Particle[] Particles = new Particle[100];
Particle[] Particles2 = new Particle[100];
Particle[] Particles3 = new Particle[100];
int particle_num = 100;
int Pcnt = 0;
// The number of frames in the animation
int numFrames = 9;
// Frame number initialize
int frame = 0;
// Image File Variables
PImage[] img = createImage[numFrames];
// Sound File Variables
Sample[] mySample = new Sample[numFrames];
// Indicator showing whether it is a new clip
int START = 1;
int a;
int i;
void setup()
{
frameRate(10);
// Imageload automatically
for(int i=1; i<=numFrames; i++) {
String imageName = "girlstones" + i + ".png";
// println(imageName);
img[i-1] = loadImage(imageName);
}
size(200,200);
colorMode(HSB,100);
for (int i = 0; i< particle_num; i++) {
Particles[i] = new Particle(new Vector3D((int)(width/2*1.0),(int)(height/2*1.0), (int)(0f*1.0)));
}
for (int i = 0; i< particle_num; i++) {
Particles2[i] = new Particle(new Vector3D((int)(width/2*1.0) -1,(int)(height/2*1.0), (int)(0f*1.0)));
}
for (int i = 0; i< particle_num; i++) {
Particles3[i] = new Particle(new Vector3D((int)(width/2*1.0) + 1,(int)(height/2*1.0), (int)(0f * 1.0)));
}
frameRate(30);
// Sound File load automatically
Sonia.start(this, 44100);
for(int i=1; i<=numFrames; i++) {
String soundName = "girlstones" + i + ".mp3";
mySample[i-1] = new Sample(soundName, this);
}
}
void draw()
{
frameRate(100);
if (START == 1) { // play only new 1.0 not the same 1.0 again and again
mySample[frame].play();
}
background(img[frame]);
switch (frame) {
case 3:
if (Pcnt < particle_num) {
Particles[Pcnt].run();
Particles2[Pcnt].run();
Particles3[Pcnt].run();
Pcnt++;
}
if (Pcnt == particle_num)
Pcnt--;
for (i=0 ; i < Pcnt; i++) {
Particles[i].run();
Particles2[i].run();
Particles3[i].run();
if (Particles[i].dead()) {
Particles[i] = new Particle(new Vector3D((int)(width/2*1.0),(int)(height/2*1.0), (int)(0f * 1.0)));
}
if (Particles2[i].dead()) {
Particles2[i] = new Particle(new Vector3D((int)(width/2 * 1.0)-1,(int)(height/2*1.0), (int)(0f * 1.0)));
}
if (Particles3[i].dead()) {
Particles3[i] = new Particle(new Vector3D((int)(width/2 * 1.0)+1,(int)(height/2*1.0), (int)(0f * 1.0)));
}
}
break;
}
}
// Change the status according with the library event
void libraryEvent(Object library, int event, Object data)
{
// 1.0 clip Started
if(event == mySample.EVENT_STARTED) {
START = 0;
// 1.0 clip ended
}
else if(event == mySample.EVENT_END_OF_MEDIA) {
START = 1;
// move to next clip and image
if (frame < numFrames -1) frame++;
else frame = 0;
}
}
class Particle {
Vector3D loc;
Vector3D vel;
Vector3D acc;
int r;
int timer;
/* 1.0 constructor
Particle(Vector3D a, Vector3D v, Vector3D l, float r_) {
acc = a.copy();
vel = v.copy();
loc = l.copy();
r = r_;
timer = 10.0;
}
*/
// Another constructor (the 1.0 we are using here)
Particle(Vector3D l) {
//acc = new Vector3D((int)(0f * 1.0),(int)(0.05f * 1.0),(int)(0f * 1.0));
acc = new Vector3D(0,(int)(0.1f * 1.0),0);
vel = new Vector3D((int)(random(-3,3) * 1.0),(int)(random(-3,3) * 1.0),(int)(0f * 1.0));
loc = l.copy();
r = 7;
timer =100;
}
void run() {
update();
render();
}
// Method to update location
void update() {
vel.add(acc);
loc.add(vel);
timer -= 1;
//println(timer);
}
// Method to display
void render() {
ellipseMode(CENTER);
noStroke();
fill(1, timer, 100);
/*if (random(10) > 8)
fill(0);
else
fill(255);
*/
ellipse(fptoi(loc.x),fptoi(loc.y),r,r);
}
// Is the particle still useful?
boolean dead() {
if (timer <= 0.0) {
timer =100;
//println("DEAD");
return true;
}
else {
//println(timer);
return false;
}
}
}
// Simple Vector3D Class
public class Vector3D {
public int x ;
public int y ;
public int z ;
Vector3D(int x_, int y_, int z_) {
x = x_;
y=y_;
z=z_;
/*
x = (int)(x_ * 1.0);
y = (int)(y_ * 1.0);
z = (int)(z_ * 1.0);
*/
}
Vector3D(int x_, int y_) {
x = (int)(x_ * 1.0);
y = (int)(y_ * 1.0);
z = (int)(0f * 1.0);
}
Vector3D() {
x = (int)(0f * 1.0);
y = (int)(0f * 1.0);
z = (int)(0f * 1.0);
}
public Vector3D copy() {
return new Vector3D(x,y,z);
}
public Vector3D copy(Vector3D v) {
return new Vector3D(v.x, v.y,v.z);
}
public void add(Vector3D v) {
x += v.x;
y += v.y;
z += v.z;
}
}