We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I posted this in "Programing Questions" and I think it's wrong, but I can't move it or delete, so I'm posting in the right place.
Here's my question: I have the following code to overlap random images. In this case, I only have 2 images, but it will work with more kind of images.
// DECLARE YOUR GLOBAL VARIABLES HERE.
PImage backgroundimage; //IMAGE VARIABLE
PImage foregroundimage; //IMAGE VARIABLE
int rand; //RANDOM NUMBER VARIABLE
int rand2; //RANDOM NUMBER VARIABLE
void setup() {
size(800, 600);
rand = int(random(0,4)); //NUMBER OF RANDOM IMAGES
rand2 = int(random(0,4)); //NUMBER OF RANDOM IMAGES
randomimage_background("bg_" + nf(rand, 3) + ".jpg"); //IMAGES MUST CALL "bg_XXX.jpg"
randomimage_foreground("fore_" + nf(rand2, 3) + ".jpg"); //IMAGES MUST CALL "fore_XXX.jpg"
}
// FUNCTION TO LOAD BACKGROUND
void randomimage_background(String fn) {
backgroundimage = loadImage(fn); //LOAD RANDOM IMAGE
tint(255, 127); //IMAGE TRANSPARENCY
image(backgroundimage,0,0);//DISPLAY RANDOM IMAGE
}
// FUNCTION TO LOAD FOREGROUND
void randomimage_foreground(String fn) {
foregroundimage = loadImage(fn); //LOAD RANDOM IMAGE
tint(255, 127); //IMAGE TRANSPARENCY
image(foregroundimage,0,0); //DISPLAY RANDOM IMAGE
}
It is working perfect for what I want, but now I'm trying to make a panel with checkboxes to decide if it will load a certain class of images or not. It's like a checkbox for the "backgroundimage" and one for the "foregroundimage" and it only display the ones that are checked on the list.
I read a little about a library called ControlP5, but I really didn't understood how it works. Anyone knows how I can do it?
Another question: it could run on web too using processing.js?
Thanks :)
Answers
If you use ControlP5, or any other library, it automatically becomes bound to Java Mode.
In order to cross-work w/ JS Mode (Pjs), a Java library needs to be written in JS too, w/ matching APIs.
And you know if there is any way to do this without ControlP5 on Processing?
Or if it is impossible to make that runs on web, you know how I could make this using ControlP5 or other library?
If you wish for your sketch to be cross-mode compatible, you need to stick w/ Processing API:
Either you program your own checkbox using Processing API only or...
Use a Java library for the Java Mode and re-write the whole sketch to use a JS library for the JS Mode.
And there is anyway to program these checkboxes using only Processing API?
Sorry, I'm really new to coding, Processing and Java, so I don't know what could be the best solution.
Thank you :)
Well, a checkbox is merely a small rect() w/ some text() on its right side:
Oh, that's pretty obvious hahaha I didn't tought about it!
Now I've done something like what I desired, here's the code:
But I still don't know how to hide the random image displayed when the button is pressed and show another random image when it's pressed again.
I've found this link but I really didn't understand how to implement this to my code. Is it possible?
int
variables in order to track down current index for your 2 arrays.It totally worked! Took some time to understand a little more about arrays, but now everything is working!
Thank you very much, GoToLoop!
Here is the code, if someone is looking for that: PImage[] backgroundimage; PImage[] foregroundimage; int rand_background; int rand_foreground; int value = 0; boolean should_draw = true;
Nice job! As a bonus, a simplification for loading all of those images: :-bd