review:
draw a rotating shape in the center of screen.
also use 'scale()' to change the size of the object.
參考:
https://processing.org/examples/array2d.html
用 2D array 設定每個元素的顏色,旋轉速度,屬性。
float[][] distances;
float[][] rotateAngles;
float[][] rotateRates;
float maxDistance;
int spacer;
void setup() {
size(640, 360);
maxDistance = dist(width/2, height/2, width, height);
distances = new float[width][height];
rotateAngles = new float[width][height];
rotateRates = new float[width][height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
float distance = dist(width/2, height/2, x, y);
distances[x][y] = distance/maxDistance * 255;
rotateAngles[x][y] = random(5.0);
rotateRates[x][y] = random(5.0, 40.0);
}
}
spacer = 30;
strokeWeight(3);
//noLoop(); // Run once and stop
}
void draw() {
background(0);
// This embedded loop skips over values in the arrays based on
// the spacer variable, so there are more values in the array
// than are drawn here. Change the value of the spacer variable
// to change the density of the points
for (int y = 0; y < height; y += spacer) {
for (int x = 0; x < width; x += spacer) {
pushMatrix();
translate(x, y);
rotate(frameCount/rotateRates[x][y]+rotateAngles[x][y]);
rect(-spacer/2, -spacer/2, spacer, spacer);
stroke(distances[x][y]);
popMatrix();
}
}
}
沒有留言:
張貼留言