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

  • SEARCH
  • Home
  • 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 9308405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:37:26+00:00 2026-06-19T00:37:26+00:00

I am new to processing and am creating a sketch where a 600px by

  • 0

I am new to processing and am creating a sketch where a 600px by 600px canvas is filled with 50px rects of a random color from my orange[] palette. The random formation of blocks need to be located inside of the draw() function in order to operate correctly with some conditionals that I will put in later.

The error that I am getting is ArrayIndexOutOfBoundsException: 12 on this line:

randomSize[varCreator] = sIncrement[int(random(0,sIncrement.length-1))];

I can’t seem to figure out why this error is occurring. I have looked into related questions, and maybe its just because I am so new, but I can’t figure it out:

int x; //x coordinate
int y; //y coordinat
int s = 50; //rect size
int wide = 600; //canvas width
int tall = 600; //canvas height
int[] sIncrement = new int[12];//{s, s*2, s*3, s*4, s*5, s*6};

//colors
int[] oranges = {
  #773600, #5f3613, #552700, #9c5215, #9c5c26
};
int[] blues = {
  #004848, #0c3939, #003333, #107979, #1e7979
};
int[] palette = oranges;//holds current color pallete

//random
int fillColor = palette[int(random(0, palette.length))]; //random starting fill color
int changeColor = palette[int(random(0, palette.length))]; //random new color
int[] randomSize = new int[sIncrement.length]; //array of lots of random s values to place newly color changed blocks


//setup
void setup(){
  size(wide, tall);
  background(255);
  noStroke();
  frameRate(24);

  /*fills sIncrement array with incrementing s values (i.e. if s = 50 then array 
   contains 50, 100, 150, etc...) from 0 to canvas width for use in a conditional statement*/
  for(int i = 0; i <= sIncrement.length-1; i++){
    sIncrement[i] = s*i;
  }

 //creates multiple randomSize variables for if() x or y == randomSize[varCreator] 
 for(int varCreator = 0; varCreator <= (width/s)+(height/s); varCreator++){
   randomSize[varCreator] = sIncrement[int(random(0,sIncrement.length-1))];
 }
}

//draw
void draw(){
  fill(fillColor); //selects random color from palette

  //draws grid colored boxes with s size
  for (y = 0; y <= height; y+= s) {
    for (x = 0; x <= width; x+= s) {
      if(x == sIncrement[randomSize[1]] && y == sIncrement[randomSize[3]]){
        fill(changeColor); //selects random color from palette
        rect(x, y, s, s);
      }

      else{
      fill(fillColor);
     // fill(palette[int(random(0, palette.length))]); //selects random color from palette
      rect(x, y, s, s);
      }
    }
  }
}
  • 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-19T00:37:27+00:00Added an answer on June 19, 2026 at 12:37 am

    You are accessing elements of the array randomSize. How long is this array? Let’s see its declaration:

    int[] randomSize = new int[sIncrement.length];
    

    So, it’s the same length as the array sIncrement. If we look a bit earlier:

    int[] sIncrement = new int[12];
    

    The length of sIncrement, and therefore the length of randomSize is 12.

    In this code:

    for(int varCreator = 0; varCreator <= (width/s)+(height/s); varCreator++){
        randomSize[varCreator] = sIncrement[int(random(0,sIncrement.length-1))];
    }
    

    The index you use to access the elements in the array randomSize is in the variable varCreator, which goes from 0 to (width/s)+(height/s). Since the length of randomSize is 12, you can only use indexes from 0 to 11 to access elements, or you will have the error you are reporting.

    So, if (width/s)+(height/s) should not be 12 or more. How much it is ?

    That’s where we are stuck, because nothing in your code tells us where width and height are declared. We only know that s is 50.

    But you have these variables, wide and tall, each equals to 600. I’m going to take a wild guess and estimate that somewhere in your code you have width = wide and height = tall.

    So (width/s)+(height/s) = (600/50) + (600/50) = 12 + 12 = 24

    That’s it. varCreator goes from 0 to 24 (included) and therefore you run out of bounds of the array.

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

Sidebar

Related Questions

Am trying to execute ssis package using dtexec utility from c# app(Creating New Process,
I am new in c#. I am working on image processing. I am creating
During the processing of an Exchange received from JMS I'm creating dynamically a route
I am very new to processing.org and Java. I am trying to store objects
I am quite new to image processing and I am looking for a solution
I have problem on my blog: http://osify.com while processing add new post with above
I am new to multicast data feed processing, my question is what's the best
When a new resource is created and it needs to do some lengthy processing
I have the following async queue processing routing. var commandQueue = new BlockingCollection<MyCommand>(); commandQueue
New to PHP and MySQL, have heard amazing things about this website from Leo

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.