Desperately need to find out how to create images out of an array when mouse is clicked.
in
Programming Questions
•
2 years ago
i'm fairly new to processing and i really need to be able to create these four images from the string in my class Idea. but is there a way to make it so that the images will appear only once the mouse is clicked? at the moment i can only get them to be all created at the same time.
Idea[] ideas=new Idea[4];
String[] files = {"arch.jpg","arch1.jpg","arch2.jpg","arch3.jpg"};
PImage world;
PImage[] images = new PImage[files.length];
int maxIdeas = 4;
int imageIndex =0;
int fade=255;
void setup() {
size(800, 800);
imageMode (CENTER);
//img = loadImage("arch.jpg");
frameRate(30);
smooth();
for (int i = 0; i < images.length; i ++ ) {
images[i] = loadImage( files[i] );
}
for (int create=0;create<4;create++)
{
ideas[create]=new Idea(width/2, height/2,100,0.8);
}
}
// ------------------------------------------------------------------------------ Main methods
void draw() {
background(0);
fill(0, fade);
world= loadImage ("world.png");
image(world,width/2,height/2);
//ellipse (width/2, height/2, 400, 400);
for (int display=0;display<4;display++)
{
ideas[display].drawIdea();
ideas[display].move();
}
}
class Idea
{
float ideax;
float ideay;
float change = 1;
int imageIndex=0;
int r;
int[] changeimage = {1,2,3,4};
float movex=random(1, 4);
float movey=random(1, 4);
Idea(float x, float y, float speed, float _diameter)
{
ideax=x;
ideay=y;
}
void drawIdea()
{
pushMatrix();
translate(ideax, ideay);//controls the position
image(images[imageIndex],20,20);
//image(img, 20, 20);
//fill (colour);
//quad(10,20, 70,50, 60,80, 20,80);
//ellipse(0, 0, 80, 80);
popMatrix();
}
void move()
{
ideax+=movex;
ideay+=movey;
if (ideax+70 > width) {//right
ideax = width-70;
movex*=-1;
}
else if (ideax-30<0) //left
{
ideax = 30;
movex *= -1;
}
if (ideay+70>height)//bottem
{
ideay=height-70;
movey*=-1;
}
else if (ideay-30<0)//top
{
ideay=30;
movey*=-1;
}
}
}
Idea[] ideas=new Idea[4];
String[] files = {"arch.jpg","arch1.jpg","arch2.jpg","arch3.jpg"};
PImage world;
PImage[] images = new PImage[files.length];
int maxIdeas = 4;
int imageIndex =0;
int fade=255;
void setup() {
size(800, 800);
imageMode (CENTER);
//img = loadImage("arch.jpg");
frameRate(30);
smooth();
for (int i = 0; i < images.length; i ++ ) {
images[i] = loadImage( files[i] );
}
for (int create=0;create<4;create++)
{
ideas[create]=new Idea(width/2, height/2,100,0.8);
}
}
// ------------------------------------------------------------------------------ Main methods
void draw() {
background(0);
fill(0, fade);
world= loadImage ("world.png");
image(world,width/2,height/2);
//ellipse (width/2, height/2, 400, 400);
for (int display=0;display<4;display++)
{
ideas[display].drawIdea();
ideas[display].move();
}
}
class Idea
{
float ideax;
float ideay;
float change = 1;
int imageIndex=0;
int r;
int[] changeimage = {1,2,3,4};
float movex=random(1, 4);
float movey=random(1, 4);
Idea(float x, float y, float speed, float _diameter)
{
ideax=x;
ideay=y;
}
void drawIdea()
{
pushMatrix();
translate(ideax, ideay);//controls the position
image(images[imageIndex],20,20);
//image(img, 20, 20);
//fill (colour);
//quad(10,20, 70,50, 60,80, 20,80);
//ellipse(0, 0, 80, 80);
popMatrix();
}
void move()
{
ideax+=movex;
ideay+=movey;
if (ideax+70 > width) {//right
ideax = width-70;
movex*=-1;
}
else if (ideax-30<0) //left
{
ideax = 30;
movex *= -1;
}
if (ideay+70>height)//bottem
{
ideay=height-70;
movey*=-1;
}
else if (ideay-30<0)//top
{
ideay=30;
movey*=-1;
}
}
}
2