[SOLVED] Centering image
in
Programming Questions
•
9 months ago
I serached the forum but I couldn't find an answer to this.
I'm a newbie and I'm trying to load some random images at the center of the screen in full screen mode.
I got it working with some math but there's some method I can use to make the sketch cleaner?
I mean something like imageMode (CENTER)...
Here's my code...
I'm a newbie and I'm trying to load some random images at the center of the screen in full screen mode.
I got it working with some math but there's some method I can use to make the sketch cleaner?
I mean something like imageMode (CENTER)...
Here's my code...
- PImage img;
- boolean sketchFullScreen() {
- return true;
- }
- void setup () {
- size (displayWidth, displayHeight);
- }
- void draw () {
- frameRate (25);
- if (mousePressed) {
- int i = int (random (1, 10));
- String imageName = (i + ".jpg");
- img = loadImage (imageName);
- // display the image to the center of the screen
- int x, y;
- x = img.width;
- y = img.height;
- int sx, sy;
- sx = displayWidth;
- sy = displayHeight;
- int centerX = (sx - x) / 2;
- int centerY = (sy - y) / 2;
- image (img, centerX, centerY);
- }
- else {
- background (255, 0, 0);
- }
- }
1