Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8373011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:34:25+00:00 2026-06-09T14:34:25+00:00

I’m new to Processing. Why don’t I see the first matrix drawn? I seem

  • 0

I’m new to Processing. Why don’t I see the first matrix drawn? I seem to only see the matrix after the delay, and not the one before. My ultimate goal is to watch how a matrix changes over time steps.

// Number of columns and rows in the grid 
int[][] myArray = {  {0, 1, 2, 3},
                     {3, 2, 1, 0},
                     {3, 5, 6, 1},
                     {3, 8, 3, 4}  };

void setup() {   
  size(200,200); 
}

void draw() {   
  background(204);   
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) { 
      rect(20+30*j,30+30*i,3,3);
    }   
  }

  delay(2500);
  background(204);

  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) { 
      rect(40+30*j,50+30*i,7,7);
    }   
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:34:26+00:00Added an answer on June 9, 2026 at 2:34 pm

    Your myArray variable is misleading, it doesn’t seem to be used anywhere.
    Basically you want to animate/interpolate between values.
    Your code does this in the draw loop:

    clear the background
    draw 16 squares
    wait 2500 ms
    clear the background
    draw 16 squares
    

    which you’ll tiny squares and after 2500 ms larger squares and that’s it.

    What want to do can be achieved in many ways, from the simpler to the more complex. Luckily Processing offers a lot of handy functions.

    You want to store a property (like x position of a box) in a variable which you’ll update over time and use the updated value to redraw on screen:

    int x = 20;
    int y = 30;
    int w = 3;
    int h = 3;
    
    void setup() {
      size(200,200);
    }
    
    void draw() {   
      //update
      if(x <= 40) x++;
      if(y <= 50) y++;
      if(w <= 7) w++;
      if(h <= 7) h++;
      //draw
      background(204);
      for (int i = 0; i < 4 ; i++) {
        for (int j = 0; j < 4; j++) { 
          rect(x+30*j,y+30*i,w,h);
        }   
      }
    }
    

    You could also map() your values to a variable changing over time:

    int x,y,s;
    int xmin = 20,xmax = 40;
    int ymin = 30,ymax = 50;
    int smin =  3,smax =  7;
    
    void setup() {
      size(200,200);
    }
    
    void draw() {   
      //update
      x = (int)map(mouseX,0,width,xmin,xmax);
      y = (int)map(mouseX,0,width,ymin,ymax);
      s = (int)map(mouseX,0,width,smin,smax);
      //draw
      background(204);
      for (int i = 0; i < 4 ; i++) {
        for (int j = 0; j < 4; j++) { 
          rect(x+30*j,y+30*i,s,s);
        }   
      }
    }
    

    Or use linear interpolation (already implemented as lerp()):

    int xmin = 20,xmax = 40;
    int ymin = 30,ymax = 50;
    int smin =  3,smax =  7;
    
    void setup() {
      size(200,200);
    }
    
    void draw() {   
      //update
      float t = (float)mouseX/width;
      //draw
      background(204);
      for (int i = 0; i < 4 ; i++) {
        for (int j = 0; j < 4; j++) { 
          rect(lerp(xmin,xmax,t)+30*j,
               lerp(ymin,ymax,t)+30*i,
               lerp(smin,smax,t)     ,
               lerp(smin,smax,t)     );
        }   
      }
    }
    

    and you could alter your interpolation amount based on any variable you like:

    int xmin = 20,xmax = 40;
    int ymin = 30,ymax = 50;
    int smin =  3,smax =  7;
    
    void setup() {
      size(200,200);
    }
    
    void draw() {   
      //update
      float t = abs(sin(frameCount * .01));
      //draw
      background(204);
      for (int i = 0; i < 4 ; i++) {
        for (int j = 0; j < 4; j++) { 
          rect(lerp(xmin,xmax,t)+30*j,
               lerp(ymin,ymax,t)+30*i,
               lerp(smin,smax,t)     , 
               lerp(smin,smax,t)     );
        }   
      }
    }
    

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I don't have much knowledge about the IPv6 protocol, so sorry if the question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.