Hey everyone, I've been having a problem with my code. I'm trying to make a slideshow for a school project. The only problem is that I keep getting the NullPointerException error. If someone could take a look that would be greatly appreciated. Thank you.
**EDIT** I'm trying to have the background change while the slideshow pictures are coming up on the screen.
import processing.opengl.*;
// Declare a photo array
Photo[] photoarray;
//Background image that needs to be large pixel wise
PImage backgroundImage;
String[] files;
int timer;
int nextBgImage;
// Set the number of photos in my slideshow
int numofphotos = 15;
int index = 0;
int posindex = 0;
//The x and y positions that the camera will focus on.. (400,300), (400,600), etc.
int[] xpos= {
400, 400, 800, 800
};
int[] ypos= {
300, 600, 600, 300
};
//starttime is a timer
int starttime;
//camera x and y positions
float camerax;
float cameray;
// intervals are the number of milliseconds to show an image
int tempinterval = 5000;
int interval = 5000;
boolean drawnext = false;
//Watch time is the time for the camera to stay in 1 position (3 pictures)
int watchtime = (interval*3)-1;
void setup() {
//Use OPENGL
size(640, 480, OPENGL);
files=new String[3];
files[0]="b1.jpg";
files[1]="b2.jpg";
files[2]="b3.jpg";
nextBgImage=(nextBgImage+1)%files.length;
backgroundImage=loadImage(files[nextBgImage]);
timer=0;
// Load all of the images, random rotation, resized to fit
photoarray = new Photo[numofphotos];
for (int i =0; i< numofphotos; i++) {
photoarray[i] = new Photo(i+".jpg", random(-30, 30));
photoarray[i].resizePhoto();
}
//Set the starttime, and camera positions
starttime = millis();
camerax = float(xpos[0]);
cameray = float(ypos[0]);
smooth();
}
void draw() {
if(timer==0)
{
background(0);
image(backgroundImage,0,0,width,height);
}
else if(timer==1)
{
backgroundImage=loadImage(files[nextBgImage]);
nextBgImage=(nextBgImage+1)%files.length;
delay(1000);
}
timer=(timer+1)%2;
}
{
if (millis() <= starttime+watchtime) {
if (millis() > starttime + tempinterval) {
//every tempinterval(5seconds) update the index, tell tempinterval to wait 5 seconds more
index++;
tempinterval = tempinterval + interval;
//Check if we finished all the photos, if so, loop around back to 0
if (index >= numofphotos) {
index = 0;
for (int i=0; i< numofphotos;i++) {
photoarray[i].drawn = false;
photoarray[i].tintval = 0;
}
}
}
}
else if (millis() > starttime+watchtime && millis() < starttime+watchtime+interval) {
//Tranisiton to the next camera x,y position
if (drawnext == false) {
//Update the next photo, update the next camera position
index++;
posindex++;
//Loop the camera positions
if (posindex >= 4)
{
posindex = 0;
}
//Loop the photos
if (index >= numofphotos) {
index = 0;
for (int i=0; i< numofphotos;i++) {
photoarray[i].drawn = false;
photoarray[i].tintval = 0;
}
}
drawnext = true;
}
//Gradually change the cameras x and y position to the next set position
float x2 = xpos[posindex];
float y2 = ypos[posindex];
float difx = (x2-camerax)/50;
float dify = (y2-cameray)/50;
camerax = difx+camerax;
cameray = dify+cameray;
}
else {
//Reset the counter when moving to the next camera position
starttime = millis();
tempinterval = 0;
watchtime = (interval*2)-1;
drawnext = false;
}
//Draw all of the photos that you have drawn so far, plus the new one and add a random x,y offset to it
I'm looking to make a slideshow. I have 15 pictures that I have on my slideshow so far, but what I really want to do is have the background change as every 5th picture pops up. Here is what I have so far.
import processing.opengl.*;
// Declare a photo array
Photo[] photoarray;
//Background image that needs to be large pixel wise
PImage backgroundImage;
// Set the number of photos in my slideshow
int numofphotos = 15;
int index = 0;
int posindex = 0;
//The x and y positions that the camera will focus on.. (400,300), (400,600), etc.
int[] xpos= {
400, 400, 800, 800
};
int[] ypos= {
300, 600, 600, 300
};
//starttime is a timer
int starttime;
//camera x and y positions
float camerax;
float cameray;
// intervals are the number of milliseconds to show an image
int tempinterval = 5000;
int interval = 5000;
boolean drawnext = false;
//Watch time is the time for the camera to stay in 1 position (3 pictures)
int watchtime = (interval*3)-1;
void setup() {
//Use OPENGL
size(640, 480, OPENGL);
backgroundImage = loadImage("b1.jpg");
// Load all of the images, random rotation, resized to fit
photoarray = new Photo[numofphotos];
for (int i =0; i< numofphotos; i++) {
photoarray[i] = new Photo(i+".jpg", random(-30, 30));
photoarray[i].resizePhoto();
}
//Set the starttime, and camera positions
starttime = millis();
camerax = float(xpos[0]);
cameray = float(ypos[0]);
smooth();
}
void draw() {
imageMode(CORNER);
//Display the background image
image(backgroundImage, 0, 0);
if (millis() <= starttime+watchtime) {
if (millis() > starttime + tempinterval) {
//every tempinterval(5seconds) update the index, tell tempinterval to wait 5 seconds more
index++;
tempinterval = tempinterval + interval;
//Check if we finished all the photos, if so, loop around back to 0
if (index >= numofphotos) {
index = 0;
for (int i=0; i< numofphotos;i++) {
photoarray[i].drawn = false;
photoarray[i].tintval = 0;
}
}
}
}
else if (millis() > starttime+watchtime && millis() < starttime+watchtime+interval) {
//Tranisiton to the next camera x,y position
if (drawnext == false) {
//Update the next photo, update the next camera position
index++;
posindex++;
//Loop the camera positions
if (posindex >= 4)
{
posindex = 0;
}
//Loop the photos
if (index >= numofphotos) {
index = 0;
for (int i=0; i< numofphotos;i++) {
photoarray[i].drawn = false;
photoarray[i].tintval = 0;
}
}
drawnext = true;
}
//Gradually change the cameras x and y position to the next set position
float x2 = xpos[posindex];
float y2 = ypos[posindex];
float difx = (x2-camerax)/50;
float dify = (y2-cameray)/50;
camerax = difx+camerax;
cameray = dify+cameray;
}
else {
//Reset the counter when moving to the next camera position
starttime = millis();
tempinterval = 0;
watchtime = (interval*2)-1;
drawnext = false;
}
//Draw all of the photos that you have drawn so far, plus the new one and add a random x,y offset to it