3D空間上で沢山の図形を動かす
float angleX = 0; float angleY = 0; float angleZ = 0; float [] x = new float[20]; float [] y = new float[20]; float [] z = new float[20]; float [] vx = new float[20]; float [] vy = new float[20]; float [] vz = new float[20]; void setup() { size(400, 400, P3D); fill(255, 255, 255); for (int i = 0; i < x.length; i++) { x[i] = random(400); y[i] = random(400); z[i] = random(100); vx[i] = random(3)-1.5; vy[i] = random(3)-1.5; vz[i] = random(3)-1.5; } } void draw() { background(0); angleX += 1; angleY += 2; angleZ += 0.5; for (int i = 0; i < x.length; i++) { enkeiMethod(x[i], y[i], z[i]); x[i] += vx[i]; if (x[i] < 0 || x[i] > width) { vx[i] *= -1; } y[i] += vy[i]; if (y[i] < 0 || y[i] > height) { vy[i] *= -1; } z[i] += vz[i]; if (z[i] < -100 || z[i] > 100) { vz[i] *= -1; } } } void enkeiMethod(float x, float y, float z) { pushMatrix(); translate(x, y, z); scale(0.1); for (int j = 0; j < 10; j++) { for (int i = 0; i < 10; i++) { rect(0, 0, 100, 50); rotateZ(radians(36)); } rotateY(radians(36)); } popMatrix(); }
Copy