Sketch on web page : Image in data file not loaded

edited December 2014 in JavaScript Mode

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 !!

  • edited December 2014

    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? :-??

  • edited December 2014

    First Question

    I assume it works offline in the processing IDE?

    Next test

    ok, this line

    PImage my_imge = loadImage("http://"+"www.amaurytatibouet.com/MenuJava/data/“+i+".png"); // permet de donner une image différente à chaque objet.

    leads to

    http://www.amaurytatibouet.com/MenuJava/data/5.png

    these urls work.

    2nd Question

    why do you have this:

    rect(-5,-5,tailleW+10,tailleH+10);
    

    in line 100?

    Suggestion

    Also, try to tell loadImage that you mean png

      // Load image from a web server
      webImg = loadImage(url, "png");
    

    (I was trying to stay out of here, because I don't know so much)

    ;-)

  • Ok Chrisir you are my helper !!! the line

     rect(-5, -5, tailleW+10,tailleH+10); 

    is to get a more neat presentation. And I just try with your idea

     PImage my_imge  = loadImage(urls[i], "png"); 

    but nothing better. I've seen only one image in Internet explorer (strange). Nothing at all in Safari... :-/

  • edited December 2014

    like this

    PImage my_imge = loadImage("http://"+"www.amaurytatibouet.com/MenuJava/data/"+i+".png", 
    "png"); // permet de donner une image différente à chaque objet.
    
  • 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

    null
    The file "/data/url.txt" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
    The file "/data/0.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
    /data/0.png
    The file "/data/1.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
    /data/1.png
    The file "/data/2.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
    /data/2.png
    The file "/data/3.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
    /data/3.png
    The file "/data/4.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
    /data/4.png
    The file "/data/5.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
    /data/5.png
    
  •   PImage my_imge  = loadImage("/data/" 
          +trim(str(i))+
          ".png", "png" 
          ); // permet de donner une image différente à chaque objet.
    
  • edited December 2014

    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.

    PImage my_imge  = loadImage("/data/"+(i)+".png"); 

    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?

  • edited December 2014

    If the images are inside sketch's "/data/" subfolder already, I believe this is enough to load them:

    String[] links = loadStrings("url.txt");
    
    for (int i = 0; i != satellites.length; ++i)
      satellites[i] = new Satellite(
        links[i], loadImage(i + ".png"), 
        random(500), random(500), random(-20000, 15000),
        80, 80, random(.002, .02));
    

    Make sure "/data/" is indeed a subfolder of the running sketch! >-)

  • edited December 2014

    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

    
     int count=0;
     int F;
    int amount = 200;                      // amount of boids
    int canvasX = 800;                     // canvas size x-direction
    int canvasY = 600;                     // canvas size y-direction
    float inc = 0.003;                     // move increasement every loop
    float nX, nY;
     
    float[] ptsX = new float[amount];      // declare + create array X
    float[] ptsY = new float[amount];      // decalre + create array Y
     PImage[] img = new PImage[6];
     
    void setup() {
      size(canvasX, canvasY);
      smooth();
      strokeWeight(3);
      background(255);
      for (int i=0; i < img.length; i++){
        img[i] = loadImage("data/"+i+".png");
      }
      
      for (int i = 0; i < amount; i++) {
        ptsX[i] = random(0, canvasX);      // write random starting pts to array X
        ptsY[i] = random(0, canvasY);      // write random starting pts to array Y
      }
    }
     
    void draw() {
      
      F = frameCount;
      F%=101;
      if (F >= 100){
      count = count + 1; 
      }
        count%=6;
      image(img[count],0,0,width,height);
      fill(255, 200);
      rect(-2, -2, canvasX+4, canvasY+4);
      for (int i = 0; i < amount; i++) {
        nX = noise(ptsX[i]) * canvasX;     // add noise value to nX, based on array
        nY = noise(ptsY[i]) * canvasY;     // add noise value to nY, based on array
        point(nX, nY);                     // insert pt, based on noise value
        ptsX[i] = ptsX[i] + inc;           // increase X with inc
        ptsY[i] = ptsY[i] + inc;           // increase Y with inc
      }
    }
    
    

    Second (with class object) which do not works : It's here : http://www.amaurytatibouet.com/test.html

    
    boolean foundARectUnderMouse;
    
    Satelite[] satelites = new Satelite[6];
    PImage[] my_imge = new PImage[6];
    
    void setup() {
      size(972, 500, OPENGL);
    
      for (int i=0; i < my_imge.length; i++) {
        
        String[] links = loadStrings("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);
    
        my_imge[i]  = loadImage("data/"+i+".png");
    
        satelites[i] = new Satelite(links[i], my_imge[i] , 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;
        }
      }
    }
    
    
  • edited December 2014

    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 ?

    
    /* @pjs preload="data/0.png"; */
    /* @pjs preload="data/1.png"; */
    /* @pjs preload="data/2.png"; */
    /* @pjs preload="data/3.png"; */
    /* @pjs preload="data/4.png"; */
    /* @pjs preload="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("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(i + ".png");
        
        satelites[i] = new Satelite(links[i], my_imge, depart_X, depart_Y, depart_Z, taillew, tailleh, speed);
      }
    }
    
    
    • 1 of the things I've hinted about is dropping the "/data/" part! Processing already looks into there!
    • Worst offender is your String[] links = loadStrings("data/url.txt");!
    • Again pay attention where I've placed it in my example!
  • 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.

  • edited December 2014

    And what if I use the .java export of my sketch ?

  • when this works:

    String[] links = loadStrings("data/url.txt");

    then this should work too:

    PImage my_imge  = loadImage("data/"
        +trim(str(i))+
        ".png", "png"
        ); // permet de donner une image différente à chaque objet.
    
  • edited December 2014

    together with

                satelites[i] = new Satelite(links[i], 
                my_imge, 
                depart_X, depart_Y, depart_Z, 
                taillew, tailleh, speed);
    
  • edited December 2014

    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

  • edited December 2014

    It works on windows with Chrome and IE ! Nothing with safari on macbook.

  • edited December 2014

    /* @pjs

     preload = "data/0.png,data/1.png,data/2.png";
     preload = "data/3.png,data/4.png,data/5.png";
     pauseOnBlur = "true"; font = "";
     */
    
    /**
     * Satellite Menu (v2.0)
     * by  Amotto   (2014/Dec/16)
     * mod GoToLoop (2014/Dec/23)
     *
     * forum.processing.org/two/discussion/8688/
     * sketch-on-web-page-image-in-data-file-not-loaded
     *
     * www.AmauryTatibouet.com/test.html
     */
    
    static final color BG = 0350, FG = 0300<<030;
    static final int QTY = 6, FONT = 16, QUALITY = 8, FPS = 60;
    Satellite[] satellites = new Satellite[QTY];
    boolean foundARectUnderMouse;
    
    void setup() {
      size(972, 500, P3D);
      smooth(QUALITY);
      frameRate(FPS);
    
      fill(FG);
      noStroke();
    
      imageMode(CORNER);
      textSize(FONT);
    
      online = 1/2 == 1/2.0;
    
      String path = "data/"; // or "";
      if (!online && !dataFile("").exists())
        path = "http://" + "www.AmauryTatibouet.com/data/";
    
      String[] links = loadStrings(path + "url.txt");
    
      String[] names = {
        "Livre Sonore", "Infra Dream", "  Musique", 
        "      Live", "    Lutherie", "      Video"
      };
    
      for (int i = 0; i != QTY; ++i)
        satellites[i] = new Satellite(
        loadImage(path + i + ".png"), names[i], links[i], 
        random(height), random(height), random(-20000, 15000), 
        80, 80, random(.002, .02));
    }
    
    void draw() {
      background(BG);
      foundARectUnderMouse = false;
      for (Satellite s : satellites)  s.script();
    }
    
    final class Satellite {
      boolean isOver;
      float inc, spid;
      float dx, dy, dz;
      int tailleW, tailleH;
      int compteur = 0;
      PVector SatCoord;
      int imageIndex = 0;
      PImage img;
      String F;
      String linkz;     
    
      Satellite(PImage _img, String _f, String _linkz
        , float depart_x, float depart_y, float depart_z
        , int tW, int tH, float Speed) {
        linkz = _linkz;
        F = _f;
        img = _img;  
        dx = depart_x;
        dy = depart_y;
        dz = depart_z;
        tailleW = tW = 100;
        tailleH = tH = 100;
        spid = Speed;
        SatCoord = new PVector(dx, dy);
        isOver = false;
      }
    
      void script() {
        checkRect();
        bouger();
      }
    
      void bouger() {
        inc += spid;
        pushMatrix();
        // start at the middle of the screen
        translate(width/2.4, height/3, 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);
        }
        //stroke(155);
        //strokeWeight(2);
        //noFill();
        //rect(0,0,90,90);
        textSize(18);
        //fill(0, 0, 0, 20);
        text(F, CENTER, 114);
        tint(255, 255, 255, 255);
        img.resize(tailleW, tailleH);
        image(img, 0, 0, tailleW, tailleH);
    
        popMatrix();
      }
    
      void checkRect() {
        if (mouseX > SatCoord.x && mouseX < SatCoord.x + (tailleW)
          && mouseY > SatCoord.y && mouseY < SatCoord.y + (tailleH)
          && !foundARectUnderMouse) {
          isOver = true;
          foundARectUnderMouse = true;
          if (mousePressed == true) {
            link(linkz, "_self");
          }
        } else {
          isOver = false;
        }
      }
    }
    
  • 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...

  • ... is it the best way to catch object in movement with the mouse?

    Dunno, since I haven't modified your class. Just the top setup() & draw()! #-o

  • edited December 2014

    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! ;-)

  • edited December 2014

    (==true is not necessary since a bool in itself is already true)

    Both == true & == false are verboten in my book! >-)
    As said, didn't dive in his class that much! 8-|

  • thanks!

    ;-)

  • edited December 2014

    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...

    
    /* @pjs preload="data/0.png"; */
    /* @pjs preload="data/1.png"; */
    /* @pjs preload="data/2.png"; */
    /* @pjs preload="data/3.png"; */
    /* @pjs preload="data/4.png"; */
    /* @pjs preload="data/5.png"; */
    
    static final color BG = 0350, FG = 0300<<030;
    static final int QTY = 6, FONT = 16, QUALITY = 8, FPS = 60;
    Satellite[] satellites = new Satellite[QTY];
    boolean foundARectUnderMouse;
    
    void setup() {
      size(972, 500, P3D);
      smooth(QUALITY);
      frameRate(FPS);
    
      fill(FG);
      noStroke();
    
      imageMode(CORNER);
      textSize(FONT);
    
      online = 1/2 == 1/2.0;
    
      String path = "data/"; // or "";
      if (!online && !dataFile("").exists())
        path = "http://" + "www.AmauryTatibouet.com/data/";
    
      String[] links = loadStrings(path + "url.txt");
    
      String[] names = {
        " Livre Sonore", " Infra Dream", "   Musique", 
        "       Live", "     Lutherie", "       Video"
      };
    
      for (int i = 0; i != QTY; ++i)
        satellites[i] = new Satellite(
        loadImage(path + i + ".png"), names[i], links[i], 
        random(height), random(height), random(-20000, 15000), 
        20, 20, random(0.01, 0.035));
    }
    
    void draw() {
      background(BG);
      foundARectUnderMouse = false;
      for (Satellite s : satellites)  s.script();
    }
    
    //CLASS //////// //////// //////// //////// //////// //////// //////// //////// ////////
    
    final class Satellite {
      boolean isOver;
      float inc, spid;
      float dx, dy, dz;
      int tailleW, tailleH;
      int compteur = 0;
      PVector SatCoord;
      int imageIndex = 0;
      PImage img;
      String N;
      String linkz;
         
    
      Satellite(PImage _img, String _n, String _linkz, float depart_x, float depart_y, float depart_z, int tW, int tH, float Speed) {
        linkz = _linkz;
        N = _n;
        img = _img; 
        dx = depart_x;
        dy = depart_y;
        dz = depart_z;
        tailleW = tW = 110;
        tailleH = tH = 110;
        spid = Speed;
        SatCoord = new PVector(dx, dy);
        isOver = false;
      }
    
      void script() {
        checkRect();
        bouger();
    
      }
    
      void bouger() {
    
        inc += spid;
        pushMatrix();
        // start at the middle of the screen
        translate(width/2.4, height/2.6, -20);    
        // some random rotation to make things interesting
        rotateX(dz); //zrot);
        rotateY(dy); //yrot);
        // rotate in X a little more each frame
        rotateZ(inc);
        // offset from center
        translate(90, 50, 90);
    
        // 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 && foundARectUnderMouse) {
          Points();
          spid = 0;
        }   
        else if(!isOver){
          spid = random(0.01, 0.03);
          
        }
        
        fill(0);
        textSize(18);
        text(N, CENTER, 126);
        tint(255, 255);
        img.resize(tailleW, tailleH);
        image(img, 0, 0, tailleW, tailleH);
    
        popMatrix();
      }
    
      void checkRect() {
        if (mouseX > SatCoord.x && mouseX < SatCoord.x + (tailleW)
          && mouseY > SatCoord.y && mouseY < SatCoord.y + (tailleH)
          && !foundARectUnderMouse) {
          isOver = true;
          foundARectUnderMouse = true;
          if (mousePressed) {
            link(linkz, "_self");
          }
        } 
        else {
          isOver = false;
        }
      }
      void Points(){
        fill(255, 0, 0, 200);
        ellipse(-5, -5, 10, 10);
        ellipse(tailleW+5, -5, 10, 10);
        ellipse(-5, tailleH+5, 10, 10);
        ellipse(tailleW+5, tailleH+5, 10, 10);
       }
    }
    
    
  • 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).

Sign In or Register to comment.