ParticleSystem ps;
import ddf.minim.*;
AudioPlayer player;
Minim minim;
public PVector Bvel;
public float AvgN1;
public boolean needadd=false;
float tempLevel,AvgN,AvgP;
public float[] AvgLevel =new float[104];
//float[] AvgEx =new float[104];
void setup() {
frameRate(70);
size(640,360);
AvgLevel[0] = 0;
smooth();
minim = new Minim(this);
player = minim.loadFile("music.mp3", 1024);
player.play();
ps = new ParticleSystem(new PVector(width/2,50));
AvgN = 0;
}
void draw() {
background(120);
AvgP = AvgN;
AvgN = 0;
AvgN1 = 0;
tempLevel = player.right.level();
for (int i =1 ; i<=103 ; i++){
AvgLevel[i]=AvgLevel[i-1];
}
AvgLevel[103] = tempLevel;
for (int j =0 ; j<=103 ; j++){
AvgN += AvgLevel[j];
if(j>87){
AvgN1 += AvgLevel[j];
}
}
float v0y = height*sqrt(sq(player.right.level()))/4;
cauAvg();
if (v0y>30){
v0y = v0y/1.2;
}
ps.addParticle(width*0.6,300-v0y-morehigh);
ps.update();
ps.display();
aspan-=1;
if (morehigh<40){
needadd = true;
}else{
needadd = false;
}
text(aspannum,20,20);
text(morehigh,20,30);
if (morehigh>0){
morehigh -=0.01;
if (morehigh>25){
morehigh -=0.03;
}
}
}
public float AvgD;
void cauAvg(){
AvgD = AvgN-AvgP;
Bvel = new PVector(random(-2,-3),AvgD);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
标签(particle)
public PVector vy;
public int aspannum = 0;
public float morehigh;
public float aspan=0;
class Particle {
PVector location;
PVector velocity;
PVector acceleration;
PVector velocity0;
PVector vy0,v1,y0,y1;
PVector damp = new PVector(0,-0.01);
PVector v0 = new PVector(Bvel.x,random(-0.1,0.1));
float c = random(.1,.2);
int dampspan = 70,toy1 = 35;
float lifespan;
float r = random(2,3);
boolean hady1 = true;
Particle(float x, float y) {
acceleration = new PVector(0.5+Bvel.y,0);
if (Bvel.y>1.5){
v1 = new PVector(0,Bvel.y*7);
}else{
v1 = new PVector(0,Bvel.y*10);
}
if (y>0.6*height){
if (AvgN1>0.2){
if(needadd){
morehigh += c;
aspan+=1.2;
aspannum+=1;
}
}
}
location = new PVector(x, y);
vy = new PVector (0,0);
y0 = new PVector (0,-1);
y1 = new PVector (0,-10);
velocity = new PVector(Bvel.x, random(-0.1, 0.1));
location = new PVector(x, y);
lifespan = 560.0;
if (AvgLevel[103]>0.5){
vy.add(y0);
}
vy0 = new PVector(vy.x,vy.y);
if (AvgD >0.3){
location.add(y1);
}
}
void run() {
update();
display();
}
void applyForce(PVector f) {
acceleration.add(f);
}
void update() {
if (hady1 & toy1<=0){
velocity.add(v1);
hady1 = false;
}
if (dampspan<=0 ){
if( velocity.y>0.3){
needdamp();
}
}
accy0();
location.add(vy0);
velocity.add(acceleration);
location.add(velocity);
acceleration.mult(0);
if(accspan){
location.sub(acc0);
}
lifespan -= 2.0;
dampspan -= 1;
toy1 -= 1;
}
void display() {
noStroke();
strokeWeight(2);
float ki = map(lifespan,0,560,0,255);
fill(0,0,0,ki);
ellipse(location.x, location.y, r*2, r*2);
}
boolean accspan = false;
PVector acc0;
void accy0(){
if (velocity.y<-0.03){
accspan = true;
//lifespan+=30;
}else{
accspan =false;
}
acc0 = new PVector (0,velocity.y*-random(0.5,1));
}
boolean isDead() {
if (lifespan < 0.0) {
return true;
}
else {
return false;
}
}
void needdamp(){
velocity.add(damp);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
标签(particleSystem)
class ParticleSystem {
ArrayList<Particle> particles;
ParticleSystem(PVector location) {
particles = new ArrayList<Particle>();
}
void addParticle(float x, float y) {
particles.add(new Particle(x, y));
}
void display() {
for (Particle p : particles) {
p.display();
}
}
void update() {
for (int i = particles.size()-1; i >= 0; i--) {
Particle p = particles.get(i);
p.update();
if (p.isDead()) {
particles.remove(i);
}
}
}
}
记得新建 标签 更新了 如果有很多的更新 我会马上发 但是参数我不一定调试 如果参数调试了 有谁愿意分享 我会非常感谢的
待会儿发出修改了变量名称的源文件 因为可能过两天我都会不记得了
虽然只是简单的PVector的建模 但是很久没用了 所以很慢
2016年05月05日 08点05分
8