Last active
July 9, 2018 20:49
-
-
Save gregberger/2ed59a6eb4315539fa450e5b84fe7c18 to your computer and use it in GitHub Desktop.
Selecting images from an array with a slider (ControlP5 + Processing3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import controlP5.*; | |
ControlP5 cp5; | |
PImage[] images = new PImage[12]; | |
int imageIndex = 0; | |
void setup(){ | |
size(800,800); | |
for(int i = 0; i < 12; i++){ | |
images[i] = loadImage(i+".gif"); | |
} | |
// instanciate the control p5 object | |
cp5 = new ControlP5(this); | |
// define the slider with the imageIndex variable bound | |
cp5.addSlider("imageIndex") | |
// set the range of the slider between 0 and the images array length -1 | |
.setRange(0,images.length-1) | |
.setValue(0) | |
.setPosition(100,400); | |
} | |
void draw(){ | |
// display the image by doing sth like: | |
image(images[imageIndex],0,0); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment