mousePressed help
in
Programming Questions
•
8 months ago
I want to have a picture of a wheres wally image, and i want it all to be black apart from where the mouse is. The mouse acts as a spotlight and wherever it is on the image, that part of the image can be viewed.
Then, when wally is found, i want to be able to click on him, and when you do, a new image comes up saying 'correct'. I dont know what is going on here.
Before i started putting in the mouse pressed stuff the spotlight thing worked, its only when i wanted to introduce a new image that its gone apeshit.
Then, when wally is found, i want to be able to click on him, and when you do, a new image comes up saying 'correct'. I dont know what is going on here.
Before i started putting in the mouse pressed stuff the spotlight thing worked, its only when i wanted to introduce a new image that its gone apeshit.
The error that comes up is "unexpected token: void" and it highlights mousePressed at the bottom. Help!:
float x = 160;
float y = 140;
float w = 200;
float h = 200;
PImage img;
PImage img2;
void setup() {
size(1024, 768);
frameRate(50);
img = loadImage("hello.jpg");
img2 = loadImage("correct.png");
img.loadPixels();
// Only need to load the pixels[] array once, because we're only
// manipulating pixels[] inside draw(), not drawing shapes.
loadPixels();
}
void draw() {
rect(x,y,w,h);
for (int x = 0; x < img.width; x++) {
for (int y = 0; y < img.height; y++ ) {
// Calculate the 1D location from a 2D grid
int loc = x + y*img.width;
// Get the R,G,B values from image
float r,g,b;
r = red (img.pixels[loc]);
g = green (img.pixels[loc]);
b = blue (img.pixels[loc]);
// Calculate an amount to change brightness based on proximity to the mouse
float maxdist = 50;//dist(0,0,width,height);
float d = dist(x, y, mouseX, mouseY);
float adjustbrightness = 200*(maxdist-d)/maxdist;
r += adjustbrightness;
g += adjustbrightness;
b += adjustbrightness;
// Constrain RGB to make sure they are within 0-255 color range
r = constrain(r, 0, 255);
g = constrain(g, 0, 255);
b = constrain(b, 0, 255);
// Make a new color and set pixel in the window
color c = color(r, g, b);
//color c = color(r);
pixels[y*width + x] = c;
}
void mousePressed() {
if(mouseX>x && mouseX <x+w && mouseY <y+h)
{
loadPixels();
img.loadPixels();
for (int y=0; y<height; y++) {
for (int x=0; x<width; x++) {
int loc=x+y*width;
float r = red (img.pixels[loc]);
float g = green(img.pixels[loc]);
float b = blue(img.pixels[loc]);
pixels[loc] = color(r+31,g-10,b-100);
}
updatePixels();
}
}
}
}
}
float x = 160;
float y = 140;
float w = 200;
float h = 200;
PImage img;
PImage img2;
void setup() {
size(1024, 768);
frameRate(50);
img = loadImage("hello.jpg");
img2 = loadImage("correct.png");
img.loadPixels();
// Only need to load the pixels[] array once, because we're only
// manipulating pixels[] inside draw(), not drawing shapes.
loadPixels();
}
void draw() {
rect(x,y,w,h);
for (int x = 0; x < img.width; x++) {
for (int y = 0; y < img.height; y++ ) {
// Calculate the 1D location from a 2D grid
int loc = x + y*img.width;
// Get the R,G,B values from image
float r,g,b;
r = red (img.pixels[loc]);
g = green (img.pixels[loc]);
b = blue (img.pixels[loc]);
// Calculate an amount to change brightness based on proximity to the mouse
float maxdist = 50;//dist(0,0,width,height);
float d = dist(x, y, mouseX, mouseY);
float adjustbrightness = 200*(maxdist-d)/maxdist;
r += adjustbrightness;
g += adjustbrightness;
b += adjustbrightness;
// Constrain RGB to make sure they are within 0-255 color range
r = constrain(r, 0, 255);
g = constrain(g, 0, 255);
b = constrain(b, 0, 255);
// Make a new color and set pixel in the window
color c = color(r, g, b);
//color c = color(r);
pixels[y*width + x] = c;
}
void mousePressed() {
if(mouseX>x && mouseX <x+w && mouseY <y+h)
{
loadPixels();
img.loadPixels();
for (int y=0; y<height; y++) {
for (int x=0; x<width; x++) {
int loc=x+y*width;
float r = red (img.pixels[loc]);
float g = green(img.pixels[loc]);
float b = blue(img.pixels[loc]);
pixels[loc] = color(r+31,g-10,b-100);
}
updatePixels();
}
}
}
}
}
1