Recitation 7: Functions and Arrays
Part 1: Grid Pattern
As it mentioned we could use it to display what we had made before, the idea of playing pictures which could turn out to be an animation suddenly came into my head, so I screenshot a gif into 4 pictures and tried to use processing to display them constantly, which turn out to be useful.
The code:
int maxImages = 4; int imageIndex = 0; PImage[] images = new PImage[maxImages]; void setup() { size(800,800); for (int i = 0; i < images.length; i ++ ) { images[i] = loadImage( "1" + i + ".jpg" ); } frameRate(5); } void draw() { background(#E799B0); image(images[imageIndex],250, 250, 300, 300); imageIndex = (imageIndex + 1) % images.length; }
Part 2: Moving Shapes
I have studied the functions for a long time but still not fixed the problem, so now it could only copy the gif for 100 times which would casually appeared in the window. I will try harder and update this blog if I have made the animation like dropping.
The code:
int numberOfInstances = 100; float[] xPositions = new float[numberOfInstances]; int x[] = new int[100]; int y[] = new int[100]; int maxImages = 4; int imageIndex = 0; PImage[] images = new PImage[maxImages]; void setup() { size(800, 800); for (int index = 0; index < numberOfInstances; index++) { x[index] = round(random(width)); y[index] = round(random(height)); for (int i = 0; i < images.length; i ++ ) { images[i] = loadImage( "1" + i + ".jpg" ); } } frameRate(5); } void draw() { background(#E799B0); for (int index = 0; index < numberOfInstances; index++) { for (int i = 0; i < images.length; i ++ ) { image(images[imageIndex], x[index], y[index], 100, 100); } } imageIndex = (imageIndex + 1) % images.length; }
Questions:
Answer the following:
- 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.
- Q2: What is the benefit of using arrays? How might you use arrays in a potential project?