i have a sketch with images bouncing around the screen. In the original sketch it was balls(ellipse) bouncing around, thats why my sketch have a numBalls variable, and not a numImages variable(i was too lazy to rename),
i can create as many images as i want.
If i create 10 images bouncing around, they will all have the same image, what i want is for them to have a randomly picked image. so that maybe 2 of them have a picture of a basketball, and 3 a golfball and so forth.
In my current code i am trying to make the array pick any of the 5 images i have in the array. What it does is it loops all the images from the array when i hit play. I know it is because i have it in the draw function, so it updates the imagearray all the time. How can i get the array to pick one image, hold on to that image and then choose another one?
The array is in the void display() function. Also this is not the full code, but the rest of it doesn't matter i think.
Thanks for any help :)
import cosm.*;
int numBalls = 100; // Max number of images
float spring = 0.05;
float gravity = 0.03;
float friction = -0.9;
PImage images;
Ball[] balls = new Ball[numBalls];
PImage[] myImageArray = new PImage[5];
void setup() {
size(800, 500);
noStroke();
for (int i = 0; i < numBalls; i++) {
balls[i] = new Ball(random(width), 20, random(30, 70), i, balls);
}
for (int i=0; i<myImageArray.length; i++) {
myImageArray[i] = loadImage( "sopa" + i + ".jpg");
}
}
void draw() {
}
background(0);
for (int i = 0; i < numBalls; i++) {
balls[i].collide();
balls[i].move();
balls[i].display();
}
void display() {
fill(255, 204);
image(myImageArray[(int)random(5)], x, y, diameter, diameter); // Changing the images randomly (not working as it should)
I have been trying to get a processingsketch to run on a website. What i have is a working processing sketch with cosm library. The sketch changes according to the value i manually put in on cosm website.
Now, what i am trying to do is to get this sketch to run on a website which i have on a server. Iv'e been searching around for this, and all i found is that processing.js don't work with libraries on a website. So my question is, is this possible to achive?
I do know that you can get values from cosm to your website using a script in the html code. Does it work to re-write the processingsketch in javascript(currently in java) and then have it in the htmlcode with the cosmscript inside of the sketch? if that makes any sense.