We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone !
I'm trying to put a sketch which import images on my web page. So, the program works but the images are not loaded. Any idea ?
Thank's
Here is the page : http://www.amaurytatibouet.com/test.html
Here is the code :
/* @pjs preload = "http://www.amaurytatibouet.com/MenuJava/data/0.png","http://www.amaurytatibouet.com/MenuJava/data/1.png","http://www.amaurytatibouet.com/MenuJava/data/2.png","http://www.amaurytatibouet.com/MenuJava/data/3.png","http://www.amaurytatibouet.com/MenuJava/data/4.png","http://www.amaurytatibouet.com/MenuJava/data/5.png"; */ boolean foundARectUnderMouse; Satelite[] satelites = new Satelite[6]; void setup() { size(972, 500, OPENGL); for (int i=0; i < satelites.length; i++) { String[] links = loadStrings("http://www.amaurytatibouet.com/MenuJava/data/url.txt"); float depart_X = random(0, 500); float depart_Y = random(0, 500); float depart_Z = random(-20000, 15000); int taillew = 80; int tailleh = 80; float speed = random(0.002, 0.02); PImage my_imge = loadImage("http://www.amaurytatibouet.com/MenuJava/data/"+i+".png"); // permet de donner une image différente à chaque objet. satelites[i] = new Satelite(links[i], my_imge, depart_X, depart_Y, depart_Z, taillew, tailleh, speed); } } void draw() { background(#ededed); foundARectUnderMouse=false; for (int i=0; i < satelites.length; i++) { satelites[i].draw(); } } // CLASS /////////// /////////// /////////// /////////// /////////// /////////// /////////// class Satelite { boolean isOver; float inc, spid; float dx, dy, dz; int tailleW, tailleH; int compteur = 0; PVector SatCoord; int imageIndex = 0; // Initial image to be displayed is the first PImage img; String linkz; Satelite(String _linkz, PImage _img, float depart_x, float depart_y, float depart_z, int tW, int tH, float Speed) { linkz = _linkz; img = _img; dx = depart_x; dy = depart_y; dz = depart_z; tailleW = tW = 90; tailleH = tH = 90; spid = Speed; SatCoord = new PVector(dx, dy); isOver = false; } void draw() { checkRect(); bouger(); } void bouger() { inc += spid; pushMatrix(); // start at the middle of the screen translate(width/2, height-290, 0); // some random rotation to make things interesting rotateY(dy); //yrot); rotateX(dz); //zrot); // rotate in X a little more each frame rotateZ(inc); // offset from center translate(50, 50, 50); // the box was drawn at (0, 0, 0), store that location float x = modelX(0, 0, 0); float y = modelY(0, 0, 0); float z = modelZ(0, 0, 0); // clear out all the transformations popMatrix(); pushMatrix(); SatCoord.x=x; // Initier SatCoord à x et y SatCoord.y=y; translate(x, y, z); if (isOver == true) { spid = 0; } else { spid = random(0.002, 0.04); } noStroke(); fill(155); rect(-5,-5,tailleW+10,tailleH+10); tint(255,255,255, 230); image(img, 0, 0, tailleW, tailleH); popMatrix(); } void checkRect() { if (mouseX > SatCoord.x && mouseX < SatCoord.x + (tailleW-20) && mouseY > SatCoord.y && mouseY < SatCoord.y + (tailleH-20) && !foundARectUnderMouse) { isOver = true; foundARectUnderMouse = true; if (mousePressed == true){ link(linkz, "_self"); } } else { isOver = false; } } }
Answers
No idea to help ?
K'mon my dear !!
If program works and image URL's are not broken, maybe your browser blocks image loading? Have you tried it on a different machine/browser? I can see images appearing in the link you've posted, or the problem is with specific images?
I only see gray rectangles rather than pics! Perhaps you should try relative paths (/data/) as URLs? :-??
First Question
I assume it works offline in the processing IDE?
Next test
ok, this line
leads to
http://www.amaurytatibouet.com/MenuJava/data/5.png
these urls work.
2nd Question
why do you have this:
in line 100?
Suggestion
Also, try to tell loadImage that you mean png
(I was trying to stay out of here, because I don't know so much)
;-)
Ok Chrisir you are my helper !!! the line
is to get a more neat presentation. And I just try with your idea
but nothing better. I've seen only one image in Internet explorer (strange). Nothing at all in Safari... :-/
like this
did you try gotoloops suggestion?
I tested it and I can't url.txt and not the images.
in the browser I can access those files.
Maybe it's the rights you have to give the folders or files on the server? Who may read them? You need to ask one of the gurus like PhiLho or gotoloop
here
I tried your last suggestion but same error message. I tried the GoToLoop solution but I'm not sure about the relative path story. If I'm right like this it doesn't work and I've got the same error message.
I've seen the rights of the data folder and thy are opened. I'm looking in server account if there is something... Than'k to try with me
does loading the url.txt work?
can you load one image?
does your sketch run or crash?
If the images are inside sketch's "/data/" subfolder already, I believe this is enough to load them:
Make sure "/data/" is indeed a subfolder of the running sketch! >-)
I'm getting really nut... 8-}
Could you pleeeeeeaaaaaase tell me the diffence between this two programs which load the same images from the same folder at the same place in the same way ????
Thank's !
First (without class object) which works : You can see here : http://www.amaurytatibouet.com/test1.html
Second (with class object) which do not works : It's here : http://www.amaurytatibouet.com/test.html
Have you really read my previous reply? Pay attention on how I did the instantiation loop within setup()!
Also use @pjs directives if you intend to have all images ready from the beginning:
http://processingjs.org/reference/pjs directive/
Yes I tried your code but it the same result. Or maybe I'm totaly wrong with the location of the data folder. The sketch and the data folder are at the root of my server...
the begining of the program is like this : that should work isn't it ?
String[] links = loadStrings("data/url.txt");
!That
rect(-5, -5, tailleW+10, tailleH+10);
seems the culprit for me! What is that for after all? :-/This is not working : String[] links = loadStrings("url.txt"); even before the loop for. This works : String[] links = loadStrings("data/url.txt"); ???
I deleted the grey rect(); and nothing better.
And what if I use the .java export of my sketch ?
try it...
when this works:
String[] links = loadStrings("data/url.txt");
then this should work too:
together with
Yiiiiiiiii HAaaaaaa !! You are the Boss Chrisir ! Thank you so much.
This is the solution to load this damn images. Just now they are loaded correctly but they take a wrong scale... Always something :-/
http://tinyurl.com/mf7p4dg
Why did I need this manner to load images in this case ? Is it the way to do it for Class/Object in web page ?
@GoToLoop : you were right, the rect(); was really a problem.
Thank to all of you for your ideas and your time. You are very helpful !! :D
copy your images on the hard drive
you can set the scale with a photo program like irfanview
you can set the size of an image with resize
Yes it's what I did. Can you see correctly the sketch ? If yes on which browser and OS ? I can see only on firefox on my mac. Not on safari nor on windows...
can't see it on iPad obviously (tried safari & chrome)
but afaik there is no Java on iPad in the 1st place
It works on windows with Chrome and IE ! Nothing with safari on macbook.
/* @pjs
It works on windows with Chrome and IE ! Nothing with safari on macbook.
Thank you very very much GoToLoop ! Your improvements in the code are very instructive for me. I learnt a lot with this program. One last question, is it the best way to catch object in movement with the mouse ? Because I'm not very convinced...
Dunno, since I haven't modified your class. Just the top setup() & draw()! #-o
imho checkRect is necessary for isover (which in turn is used for spid)
but do you want the change of spid really?
if not, you could call checkrect only from void mousePressed() outside the class (instead of script). much faster.
thus it would be called only when the mouse is pressed
@gotoloop what do you think?
(==true is not necessary since a bool in itself is already true)
happy xmas! ;-)
Both
== true
&== false
are verboten in my book! >-)As said, didn't dive in his class that much! 8-|
thanks!
;-)
I don't really understand. How do checkRec(); called outside of the class in a void moussePressed(){} can work if it takes values from the object of the class ? And checkRect(); is used to stop the object before to clic on it. How do it can work if it's called in void mousePressed(){} ?
And why this simple thing is not working line 143 ? The alpha neither...
for checkRect()
it depends whether you need it throughout or just when the mouse is pressed.
when only when the mouse is pressed, you can call it from mousePressed(). You need a for-loop in the function then over all satellites. Checkrect itself stays in the class therefore it works as it does now (to answer your question).