Page 1 of 1

CSC 545 Computer Speech, Music, and Images Test 2 Add your name in a comment at the top of Test2.pde and complete Test2.

Posted: Sat May 14, 2022 6:59 pm
by answerhappygod
CSC 545 Computer Speech, Music, and Images
Test 2
Add your name in a comment at the top of Test2.pde and complete
Test2.pde to enable a user to magnify part of an image. Test2.pde
provides the constants and global variables needed for a magnifier
program. Your job is to display the base image and implement the
magnification and size control. The magnified section should be
centered on the mouse position. As the mouse moves around the
screen, the section of the image around the mouse is magnified. You
may assume the magnified section will always be square (regionSize
x regionSize). Up arrow increases the region size by a constant
(REGIONDELTA); max region size is determined by another constant
(MAXREGION). Down arrow decreases the region size by REGIONDELTA,
with a minimum size of MINREGION. Allow the user to control the
level of magnification using the mouse wheel—moving the wheel
forward (away from the user) one click increases the magnification
level by MAGDELTA; moving the wheel backward (toward the user)
decreases the magnification level by MAGDELTA. You should be aware
that, because the magnification factor changes, the size of the
magnified box will change when you modify magFactor. The regionSize
does not change, though – it’s still the same number of pixels
inside the region. ‘r’ resets the region size and magnification
level to default values (REGIONDEFAULT, MAGDEFAULT).
Hint: There are a number of ways to solve this problem
but most of them are hard to get just right. The easiest way is to
display the base image, then use the get() method to copy a
regionSize x regionSize section centered on the mouse position,
resize the new (copied) image according to magFactor, and display
it centered on the mouse position (there’s an image mode that lets
you position an image by its center, rather than its upper left
corner).
The test will be graded according to the following criteria:
Set canvas size to image size………………………………………………………..20%
Load and display base image………………………………………………………. 30%
Create magnified
image…….………........................................................................
10%
Center magnified image on mouse
position………………………………………...
10%
Mouse wheel control of magnification level (MAGMIN to
MAGMAX)………….10%
Arrow control of magnification region size (MINREGION to
MAXREGION )….. 10%
Reset default values on ‘r’ key………………………………………………...……..5%
Magnification to image edges (no unprocessed
border)…………...………............. ..5%
Submit Test2 on Blackboard. Be sure your name is in a comment at
the top of the program.
I need the rest of the proccesing code finished below. all the
todo's
/* Test 2: Magnify a section of an image
Control magnification level using the mouse
wheel
Control magnified region size using up and down
arrows
*/
PImage img;
int regionSize = 200;
final int REGIONDEFAULT = 200;
final int REGIONDELTA = 10; //Increment for changing
regionSize
final int MINREGION = 50, MAXREGION = 300;
float magFactor = 2.0;
final float MAGDEFAULT = 2.0;
final float MAGDELTA = 0.1; //Modification factor for changing
magFactor
final float MAGMIN = 1.5, MAGMAX = 5.0; //Range for
magFactor
String[] fnames = {"us_texas-1839_small.jpg",
"maps_future_small.jpg"};
void setup() {
}
void draw() {
}
/*Test 2: Magnify a section of an image
Control magnification level using the mouse wheel
Control magnified region size using up and down arrows
*/
PImage baseImage;
void setup() {
size(600, 400);
baseImage = loadImage("sample.jpg");
}
void draw() {
background(0);
image(baseImage, 0, 0);
//TODO: implement magnification
}
void keyPressed() {
if (key == '?') {
//TODO: reset default values
}
}