Home

Video: Arrays 2

Notes for this video are found below.

Code for the demo

int[] xs;
int[] ys;
int[] widths;
int[] hues;

void setup()
{
  colorMode(HSB, 100);
  size(1000, 750);
  xs = new int[50];
  ys = new int[50];
  widths = new int[50];
  hues = new int[50];
  
  for(int i = 0; i < 50; i++)
  {
    xs[i] = 500;
    ys[i] = 100;
    widths[i] = i*10 + 20;
    hues[i] = i * 2;
  }
}

void draw()
{
  background(0);
  
  for(int i = 0; i < 50; i++)
  {
    strokeWeight(2);
    noFill();
    stroke(color(hues[i], 50, 100));
    ellipse(xs[i], ys[i], widths[i], widths[i]);
    
    hues[i] = (hues[i] + 1) % 100;
    
    if(frameCount % 30 == 0)
    {
      ys[i] += 50 - i;
    }
  }
}
CSE 1211 material by Joshua Eckroth is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Source code for this website available at GitHub.