Created
October 20, 2014 12:38
-
-
Save andrew-dash/38823fd7a9be768550a8 to your computer and use it in GitHub Desktop.
load images into an array then draw them according to key presses
This file contains hidden or 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
| // use this way of definining size to establish your array globally | |
| #define NUM_IMAGES 4 | |
| // create an array of images | |
| ofImage question[NUM_IMAGES]; | |
| int imgCounter; | |
| int imgAlteration; | |
| void setup() { | |
| // put your setup code here, to run once: | |
| ofSetWindowShape(800,600); | |
| imgAlteration = 120; | |
| // load the images into the array | |
| // file names should be numbers so the images should be named: "1.jpg" "2.jpg" "3.jpg" etc. | |
| for(int i = 0; i < NUM_IMAGES; i++) { | |
| string curImg = ofToString(i); | |
| curImg += ".jpg"; | |
| question[i].loadImage(curImg); | |
| } | |
| } | |
| void draw() { | |
| // put your main code here, to run once each frame: | |
| ofSetColor(imgAlteration); | |
| question[imgCounter].draw(0, 0, ofGetWindowWidth(), ofGetWindowHeight()); | |
| } | |
| void keyPressed(int key) | |
| { | |
| if('y' == key) | |
| { | |
| // conditional to loop back around to the first image | |
| if(imgCounter == (NUM_IMAGES-1) ){ | |
| imgCounter = 0; | |
| } else { | |
| imgCounter++; | |
| } | |
| if (imgAlteration < 255){ | |
| // add 5 each time the y key is pressed | |
| imgAlteration +=5; | |
| } | |
| } | |
| if('n' == key) | |
| { | |
| if(imgCounter == (NUM_IMAGES-1) ){ | |
| imgCounter = 0; | |
| } else { | |
| imgCounter++; | |
| } | |
| if (imgAlteration > 0){ | |
| // subtract 5 each time the n key is pressed | |
| imgAlteration -=5; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment