Recitation 7: Functions and Arrays
Part 1: Grid Pattern
Code:
int instances=100;
float[] move = new float[100];
float [] xPos= new float [instances];
float [] yPos= new float[instances];
color [] cL=new color[instances];
void shapeX (float x, float y, color c) {
fill (c);
circle (x, y, 20);
fill (c/2);
rectMode (CENTER);
square (x, y, 30);
fill (c/4);
}
void setup() {
size (600, 600);
background (0);
for (int i=0; i<instances; i++) {
xPos[i]=(random(0, 600));
yPos[i]=(random(0, 600));
cL[i]=color (random(0, 255), random (0, 255), random (0, 255));
move[i]=(random(5));
}
noStroke();
}
void draw() {
background (0);
for (int i=0; i<instances; i++) {
shapeX (xPos[i], yPos[i], cL[i]);
if ((xPos[i] + move[i] > 600)||(xPos[i] + move[i] < 0)) {
move[i]=-move[i];
}
xPos[i] = xPos[i]+move[i];
}
}
- Q1: In the reading “Art, Interaction and Engagement” by Ernest Edmonds, he identifies four situations in an interactive artwork: ‘Static’, ‘Dynamic-Passive’, ‘Dynamic-Interactive’ and ‘Dynamic-Interactive(Varying)’. From the exercise you did today which situations you identify in every part you executed? Explain.
Today’s works are both static artworks, in my opinion. Because the patterns are self-moving and unaffected by the context or the user’s actions.
- Q2: What is the benefit of using arrays? How might you use arrays in a potential project?
The advantage of utilizing arrays, in my opinion, is that they may efficiently represent several data types with a single object. The data inside the array may be easily created with the help of the for loop, which is really useful. It’s also a lot easier to access data from an array by calling its index.