Help in Visualization of Data

I want the images to scale slowly, given an array of values I have, when I click. I also want the text in the corner to change at the same time. What do I need to change in both my logic of this as well as the code to make this work?

//Project in Visualization

void setup()
{
  size(700,700);
  smooth();
  USA = loadImage("map.png");
  bfly = loadImage("bfly.jpg");
}

void draw()
{
  background(255);
  image(USA,-160,-50,1000,880);
  for (int i = 0; i < 4; i++)
  {
    if(mousePressed)
    {
      i++;
    //florida
    image(bfly,450,460,F[i],F[i]);
    //New England
    image(bfly,460,360,NE[i],NE[i]);
    //mexico
    image(bfly,280,540,M[i],M[i]);
    //north dakocta
    image(bfly,290,280,ND[i],ND[i]);
    }
  }
}

void mousePressed()
 {
   textSize(60);
   fill(0); 
   text("2000", 30, 600);
   noLoop();
 }

PImage USA;
PImage bfly;

Comments

  • edited April 2015

    1.

    put global vars at the start of the sketch, not the end

    PImage USA;
    PImage bfly;
    

    2.

    when you want to increase the images when the mouse is clicked and the images stay bigger when you let go of the mouse:

    void mousePressed()
     {
              i++;
     }
    

    The line noLoop() is a bad idea when you want something to happen on the screen

  • don't have this in draw()

    if(mousePressed)
        {
          i++;
    
  • @chrisir I have added the text I wanted (four different texts to correspond with the four different sizes of images) into an array. Could you then use i++ in a way to change all of theses?

  • sure! show your code...

    textsForFlorida = { "A....", "B....", "C...." };
    
    i++;
    
    text (textsForFlorida[i], 111,111);
    
  • edited April 2015

    @chrisir Ok so what I have now is this, I do get the numbers and the images to scale properly. The only thing that it isn't doing well is slowly changing to the size instead of abruptly going from one size to the next as well as going back to 0 once you click 4 times (when you click 4 times the project errors out).

    //Project in Visualization
    PImage USA;
    PImage bfly;
      int i=0;
    
    void setup()
    {
      size(700,700);
      smooth();
      USA = loadImage("map.png");
      bfly = loadImage("bfly.jpg");
    }
    
    void draw()
    {
      background(255);
      image(USA,-160,-50,1000,880);
      frameRate(3);
      //florida
      image(bfly,450,460,F[i],F[i]);
      //New England
      image(bfly,460,360,NE[i],NE[i]);
      //mexico
      image(bfly,280,540,M[i],M[i]);
      //north dakocta
      image(bfly,290,280,ND[i],ND[i]);
       textSize(60);
       fill(0); 
       text(years[i], 30, 600);
    }
    
    void mousePressed()
     {
        i++;
     }
    
  • edited April 2015

    @chrisir for changing slowly the only way I have found is to add some fraction (like .5) to the length and width. But I am unsure how to do that with the array, specifically because I only want it to change after you click the mouse.

  • for the

    going back to 0 once you click 4 times (when you click 4 times the project errors out).

    void mousePressed()
     {
        i++;
        if (i>=4) 
           i=0;
     }
    
  • edited April 2015

    slowly changing to the size instead of abruptly going from one size to the next

    pls look at lerp()

    this allows you to go from one value in e.g. 10 steps

    ;-)

Sign In or Register to comment.