about outofmemory and picture change
in
Programming Questions
•
8 months ago
I'm new in processing and for my code I wanna display a picture after the mouse released and the picture can't be same for each time .can anyone help me to change the code.also there is a outofmemory error.
Need help!!!
import ddf.minim.*;
Minim minim;
//AudioPlayer player;
ParticleSystem ps;
PImage[] story = new PImage [23];
PImage a;
void setup() {
size(800 , 600) ;
minim = new Minim (this);
player = minim.loadFile ("music1.mp3");
player.loop();
ps = new ParticleSystem(1, new PVector(width/2,height/2,0));
}
void draw(){
// a=loadImage("a1.jpg");
// background(a);
int randomNum = (int) random(23);
story[randomNum]=loadImage(randomNum+".jpg");
if
if(mousePressed){
image(story[randomNum],0,0);
}
ps.run();
ps.addParticle(mouseX,mouseY);
}
class ParticleSystem {
ArrayList particles;
PVector origin;
ParticleSystem(int num, PVector v) {
particles = new ArrayList();
origin = v.get();
for (int i = 0; i < num; i++) {
particles.add(new Particle(origin));
}
}
void run() {
for (int i = particles.size()-1; i >= 0; i--) {
Particle p = (Particle) particles.get(i);
p.run();
if (p.dead()) {
particles.remove(i);
}
}
}
void addParticle() {
particles.add(new Particle(origin));
}
void addParticle(float x, float y) {
particles.add(new Particle(new PVector(x,y)));
}
void addParticle(Particle p) {
particles.add(p);
}
boolean dead() {
if (particles.isEmpty()) {
return true;
} else {
return false;
}
}
}
class Particle {
PVector loc;
PVector vel;
PVector acc;
float r;
float timer;
Particle(PVector l) {
acc = new PVector(0,0.05,0);
vel = new PVector(random(-1,1),random(-2,0),0);
loc = l.get();
r=15;
timer = 100.0;
}
void run() {
update();
render();
}
void update() {
vel.add(acc);
loc.add(vel);
timer -= 1.0;
}
void render() {
ellipseMode(CENTER);
stroke(255,timer);
fill(100,timer);
ellipse(loc.x,loc.y,r,r);
}
boolean dead() {
if (timer <= 0.0) {
return true;
} else {
return false;
}
}
}
Need help!!!
import ddf.minim.*;
Minim minim;
//AudioPlayer player;
ParticleSystem ps;
PImage[] story = new PImage [23];
PImage a;
void setup() {
size(800 , 600) ;
minim = new Minim (this);
player = minim.loadFile ("music1.mp3");
player.loop();
ps = new ParticleSystem(1, new PVector(width/2,height/2,0));
}
void draw(){
// a=loadImage("a1.jpg");
// background(a);
int randomNum = (int) random(23);
story[randomNum]=loadImage(randomNum+".jpg");
if
if(mousePressed){
image(story[randomNum],0,0);
}
ps.run();
ps.addParticle(mouseX,mouseY);
}
class ParticleSystem {
ArrayList particles;
PVector origin;
ParticleSystem(int num, PVector v) {
particles = new ArrayList();
origin = v.get();
for (int i = 0; i < num; i++) {
particles.add(new Particle(origin));
}
}
void run() {
for (int i = particles.size()-1; i >= 0; i--) {
Particle p = (Particle) particles.get(i);
p.run();
if (p.dead()) {
particles.remove(i);
}
}
}
void addParticle() {
particles.add(new Particle(origin));
}
void addParticle(float x, float y) {
particles.add(new Particle(new PVector(x,y)));
}
void addParticle(Particle p) {
particles.add(p);
}
boolean dead() {
if (particles.isEmpty()) {
return true;
} else {
return false;
}
}
}
class Particle {
PVector loc;
PVector vel;
PVector acc;
float r;
float timer;
Particle(PVector l) {
acc = new PVector(0,0.05,0);
vel = new PVector(random(-1,1),random(-2,0),0);
loc = l.get();
r=15;
timer = 100.0;
}
void run() {
update();
render();
}
void update() {
vel.add(acc);
loc.add(vel);
timer -= 1.0;
}
void render() {
ellipseMode(CENTER);
stroke(255,timer);
fill(100,timer);
ellipse(loc.x,loc.y,r,r);
}
boolean dead() {
if (timer <= 0.0) {
return true;
} else {
return false;
}
}
}
1