Lesson 40 – Arrays

— golan @ 1:52 pm

“Flocking” simulation — actually, 100 drunks:

float   pxArray[]; // declaration
float[] pyArray;
int nDrunks = 100;

void setup() {
  size(400, 400);

  pxArray = new float[nDrunks]; // ALLOCATION
  pyArray = new float[nDrunks];

  for (int i=0; i

A case where the arrays are set with specific values at the start:

 
float xPoints[] = {
  280.0, 289.0, 134.0, 64.0, 151.0
};
float yPoints[] = {
  74.0, 205.0, 260.0, 194.0, 61.0
};


void setup() {
  size (400, 400);
  smooth();
}

void draw() {
  background(126);
  beginShape();
  for (int i=0; i<5; i++) {
    float px = xPoints[i] + 30*noise(i + millis()/200.0);
    float py = yPoints[i] + 30*noise(i + millis()/313.0);
    vertex(px,py);
    
  }
  endShape(CLOSE);
}

0 Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2019 CMU Electronic Media Studio II, Fall 2011, Section A | powered by WordPress with Barecity