Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

deutsche Version

https://processing.org/tutorials/arrays/

An array is a container that holds a fixed number of values, a bit like a spreadsheet table. With arrays we can store multiple variables of the same type, and access them easily.

...

Exercise 8.2

Use an array or arraylist ArrayList to draw animated icons on the screen.

...

Code Block
titleExercise 8.2 possible solution
linenumberstrue
collapsetrue
int noOfPuffs =
60;
int[] puffsX = new int[noOfPuffs60];
int[] puffsY = new int[noOfPuffs60];
 
int puffSizecurrentPuff= 400;
int scaleDirection = 1;
int currentPufffloat angle = 0;
void setup() {
  size(600,600);
  noStroke();
}
 
void draw() {
  background(0);
 
  for(int i = 0; i < puffsX.length; i++) {
    puffsDrawPuff(puffsX[i],puffsY[i],i);
  }
  puffSizeangle+=scaleDirection;
  if (puffSize>70 || puffSize<20) {
    scaleDirection = -scaleDirection;
  }

} 0.1;
}
 
void puffsDrawPuff(int x, int y, int index) {
  fill(255);
  float puffSize= (sin(angle+index)*10)+20;
  ellipse(x,y,puffSize,puffSize);
};
 
 
void mouseMoved(){
  currentPuff++;
  if (currentPuff >= noOfPuffspuffsX.length) {
    currentPuff = 0;
  }
  puffsX[currentPuff] = mouseX;
  puffsY[currentPuff] = mouseY;
};

...