Last active
August 29, 2015 14:08
-
-
Save internetsadboy/7febc5c6aa968cb05f62 to your computer and use it in GitHub Desktop.
690 Midterm: derive display parameters for centering an image in a display area.
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
| /* | |
| * CenterImage | |
| * | |
| * Derive display parameters for centering an image within an arbitrary display area | |
| * | |
| * @build Processing sketch app | |
| * @fileType .pde | |
| * @description no physical image used, the image is defined by its dimensions (w, h) and position (x, y) | |
| */ | |
| int winW, winH, displayAreaW, displayAreaH, displayAreaX, displayAreaY, imgW, imgH, imgX, imgY; | |
| void setup () | |
| { | |
| // window dimensions | |
| winW = 800; | |
| winH = 600; | |
| // draw window | |
| background(255); | |
| size(winW, winH); | |
| // displayArea dimensions | |
| displayAreaW = 600; | |
| displayAreaH = 450; | |
| // arbitrary displayArea position (x, y) | |
| displayAreaX = 40; // center displayArea => x = winW / 2 - displayAreaW / 2 | |
| displayAreaY = 40; // center displayArea => y = winH / 2 - displayAreaH / 2; | |
| // draw displayArea | |
| fill(220); | |
| stroke(220); | |
| rect(displayAreaX, displayAreaY, displayAreaW, displayAreaH); | |
| // image dimensions | |
| imgW = 400; | |
| imgH = 200; | |
| // centered image position (x, y) | |
| imgX = (displayAreaW / 2) - (imgW / 2) + displayAreaX; | |
| imgY = (displayAreaH / 2) - (imgH / 2) + displayAreaY; | |
| // draw image | |
| fill(100, 200, 200); | |
| stroke(100, 200, 200); | |
| rect(imgX, imgY, imgW, imgH); | |
| } | |
| void draw () | |
| { | |
| // stuff | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment