Help please!?
in
Programming Questions
•
1 year ago
I am new to processing and keep getting errors which I am unable to fix.
I am trying to make a wrap around image with 2 buttons which enable the speed of the picture to change.
The error is 'java.lang.NullPointerException'
Any help would be very much appreciated thank you!!
Here is the code:
PImage panorama, image2;
int dimension,loc1, loc2;
int speed;
//defining x,y,w and h of - box
float x = (panorama.width/2-100);
float y = (panorama.height+50);
float w = 75;
float h = 75;
void setup() {
panorama = loadImage ("Panorama.jpg");
dimension = (panorama.width*panorama.height);
size (panorama.width,panorama.height+200);
image (panorama,0,0);
image2 = createImage (panorama.width, panorama.height,RGB);
}
void draw() {{
speed= 1;
background (255);
}
panorama.loadPixels();
image2.loadPixels();
for (int y=0; y < panorama.height; y++) {
for (int x = 0; x < panorama.width; x++) {
//define the locations (1 pixel shift)
loc1 = x + y*panorama.width;
loc2 = (x-speed) +y*panorama.width;
//if loc2 is inside the range (0-dim), go on!
if ((loc2 > 0)&(loc2 < dimension)){
//copy panorama to image 2, moved over one pixel
image2.pixels[loc2]=panorama.pixels[loc1];
}
//else skip this line
else{
}
//end of for loop
}
}
panorama.updatePixels();
image2.updatePixels();
panorama= image2;
image (panorama, 0, 0);
rectMode(CENTER);
//draw two squares
//make the squares go black when pressed
if(mousePressed){
if(mouseX>x && mouseX <x+w && mouseY>y && mouseY <y+h){
println("The mouse is pressed and over the button");
fill(0);
rect(panorama.width/2-100, panorama.height+50, 75, 75);
rect(panorama.width/2+100, panorama.height+50, 75, 75);
//minus sign
fill(0);
rect(panorama.width/2-100, panorama.height+50, 50, 10);
rect(panorama.width/2+100, panorama.height+50, 50, 10);
rect(panorama.width/2+100, panorama.height+50, 10, 50);
}
}
}
1