We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Creating fade between photos with hyperlinks
Page Index Toggle Pages: 1
Creating fade between photos with hyperlinks (Read 1059 times)
Creating fade between photos with hyperlinks
Jan 29th, 2010, 1:02am
 
Hi,

I am creating a banner for my website which will fade between a number of photos, each with a different hyperlink attached to them. I can get the fade to work but the links don't enable, and I am a bit stuck now.

Also, can the .java code which is exported be copied into the html code?

Any help is much appreciated
Chris

// Fade between photos and embeded hyperlinks

// prepare the images to be loaded
PImage img1, img2;
float fade = 0;
float fadeSpeed = 1;
int rate = 90;
// pause time for the photos in m/s
int pause = 2000;
// booleans for creating links
boolean link1 = false;
boolean link2 = false;

void setup() {
 size(730, 547);
 img1 = loadImage("IMG_2296.JPG");
 img2 = loadImage("IMG_1965.JPG");
 frameRate(rate);
}

void draw() {
 background(img1);
 // adjust the transparency
 fade = fade + fadeSpeed;
 tint(255, 255, 255, fade);
 if ((fade == 255) || (fade == 0)) {
   fadeSpeed = fadeSpeed * -1;
 }
 // delay the program when fade reaches either end
 if ((fade == 255) || (fade == 0)) {
   delay(pause);
 }
 image(img2, 0, 0);
 stroke(0, 0);
 fill(255, 0);
 rect(0, 0, width, height);
}

void mousePressed() {
 if (link1) {
   // link for photo 2
   link("*a_link1*");
 } else if (link2) {
   // link for photo 1
   link("*a_link2*");
 }
}

void fadeStop() {
 if (fade > 150) {
   link1 = true;
 } else if (fade < 100) {
   link2 = true;
 } else {
   link1 = link2 = false;
 }
}
Re: Creating fade between photos with hyperlinks
Reply #1 - Jan 29th, 2010, 2:29am
 
"a number of photos" calls for arrays.
If you don't want to use classes, just make an array with image names, one with links, one with PImages.
You fade between image n and image n+1, when clicking, use links[n] (or n+1).

"can the .java code which is exported be copied into the html code?"
Use File > Export, and copy the content of the generated HTML file. You use the generated .jar file.
Re: Creating fade between photos with hyperlinks
Reply #2 - Jan 29th, 2010, 3:35am
 
Chris Tarren wrote on Jan 29th, 2010, 1:02am:
Hi,

I am creating a banner for my website which will fade between a number of photos, each with a different hyperlink attached to them. I can get the fade to work but the links don't enable, and I am a bit stuck now. ......


Hi, excuse me if I reply saying that using an Applet 'just to fade' images will make your website looking ugly and slow. Also I don't want to appear a 'webdesign teacher' at all.

Guys don't blame me, i love Processing and it is taking all of my free time and thoughts, i am constantly thinking at how to make things in 3D but i think you'll agree this is not what Processing (and an Applet in general) is made for.

What you need is something like this:
http://www.na3.it (yes I did it, but it's much like what you need).
There you'll find on the header a set of links that make the images in the banner to fade.

It is made with a JS framework called jQuery (google for it) and a plugin for it called jquery.cycle.

It is easier to implement with just few lines of HTML, will work on EVERY client with any OS and it's lightweight.

Using an Applet you will force users to download the Java runtime nvirorment, or wait for the 'beast' to build up just to fade some images.

Sorry for that reply I hope you don't mind.

Re: Creating fade between photos with hyperlinks
Reply #3 - Jan 29th, 2010, 4:19am
 
I'd tend to agree with GianCarlo.

There's a time and place for Applets and this doesn't sound like one of them, unless you're going to incorporate something that can only be done in Processing...
Re: Creating fade between photos with hyperlinks
Reply #4 - Jan 29th, 2010, 5:10am
 
blindfish wrote on Jan 29th, 2010, 4:19am:
....unless you're going to incorporate something that can only be done in Processing...


like for example find a solution to avoid loading all the images before the Applet starts. An ideal solution for saving bandwidth should be loading the next image while you're showing the current. But again, there are plenty of Ajax solutions and techniques for that. Look in http://plugins.jquery.com/ this pages to find one.
Lips Sealed

Ok, now back to Processing.
Re: Creating fade between photos with hyperlinks
Reply #5 - Jan 29th, 2010, 6:24am
 
Well, you have this nice shiny, big golden hammer.
And this pin is so tempting... Tongue
Page Index Toggle Pages: 1