Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float randomRadians() {
- return random(2 * PI);
- }
- // x = y axis rotation
- void rotateXY(float omega) {
- final float c = cos(omega);
- final float s = sin(omega);
- final float r2 = sqrt(2);
- applyMatrix(
- (1+c)/2, (1-c)/2, r2*s/2, 0,
- (1-c)/2, (1+c)/2, -r2*s/2, 0,
- -r2*s/2, r2*s/2, c, 0,
- 0, 0, 0, 1
- );
- }
- // red and block core
- void centralBoxes() {
- stroke(#ff0000, 200);
- strokeWeight(3);
- fill(#000000, 150);
- pushMatrix();
- rotateXY(-atan(sqrt(2)));
- final int boxSize = 20;
- for(int i = 0; i < 8; ++i) {
- pushMatrix();
- translate(
- (i & 1) != 0 ? boxSize : -boxSize,
- (i & 2) != 0 ? boxSize : -boxSize,
- (i & 4) != 0 ? boxSize : -boxSize
- );
- box(boxSize * 1.5);
- popMatrix();
- }
- popMatrix();
- strokeWeight(1);
- }
- // around the central core
- void orbitalBoards(float size, float radius, int n) {
- stroke(#ffffff, 255);
- fill(#444444);
- for(int i = 0; i < n; ++i) {
- final float theta = i * 2*PI / n;
- pushMatrix();
- rotateX(PI/2);
- translate(radius * cos(theta), 0, radius * sin(theta));
- rotateY(-theta + PI/2);
- rect(-size/2, -size/2, size, size);
- line(-size/6, -size/2, -size/6, 0);
- line(-size/6, 0, size/6, 0);
- line( size/6, size/2, size/6, 0);
- popMatrix();
- }
- }
- // wire-framed triangles
- void asteroidBelt() {
- stroke(#ffffff, 127);
- noFill();
- final int n = 500;
- final float r = 210.f; // radius
- final float phi = 2 * PI / n;
- for(int i = 0; i < n; ++i) {
- final float theta = i * phi + random(phi);
- final float randomR = r + randomGaussian() * 16.f;
- final float x = randomR * cos(theta);
- final float y = randomR * sin(theta);
- pushMatrix();
- translate(x, y, 0);
- rotateX(randomRadians());
- rotateY(randomRadians());
- rotateZ(randomRadians());
- scale(1.5);
- // (0, 0)-(0, 3)-(4, 0) => G(4/3, 1)
- triangle(-4.f/3,-1, -4.f/3,2, 8.f/3,-1);
- popMatrix();
- }
- }
- // boxels converge to the origin
- void logGrid() {
- final int xn = 100;
- final int yn = 100;
- final int size = 5;
- for(int xi = -xn; xi < xn; ++xi) {
- final float x = xi * size; // x : [-xn * size, xn * size)
- for(int yi = -yn; yi < yn; ++yi) {
- final float y = yi * size; // y : [-yn * size, yn * size)
- final float d = sqrt(x*x + y*y); // distance from the origin
- final float z = 30 * log(d + 1) + 20;
- final float a = constrain(4000 / (d + 1), 0, 255); // alpha
- if(d >= 500) {
- continue; // off-range
- }
- // random spot highlight
- if((int)random(200) == 0 && d < 300) {
- stroke(#ffffff, a/2 + 30);
- fill(#cccccc, a);
- }
- else {
- stroke(#aaaaaa, a/4);
- fill(#444444, a);
- }
- pushMatrix();
- translate(x - size/2.f, y - size/2.f, z);
- box(size);
- popMatrix();
- }
- }
- }
- // red lightning from central core
- void thunderBolt() {
- noStroke();
- fill(#ff0000, 255);
- float x = 0.f;
- float y = 0.f;
- for(int i = 0; i < 100; ++i) {
- final float weight = i * 0.02f;
- final float widthBase = i * 0.3f;
- final float xr = random(i * 0.3f);
- final float yr = random(widthBase) * (i % 2 == 0 ? 1 : -1);
- triangle(x, y, x + xr, yr + weight, x + xr, yr - weight);
- x += xr;
- y = yr;
- }
- }
- void setup() {
- size(800, 600, P3D);
- randomSeed(131);
- background(0);
- pushMatrix();
- translate(width*3/5, height*4/9, height*2/5);
- rotateX(PI * 4 / 11);
- rotateY(PI / 11);
- rotateZ(PI / 11);
- // center boxes
- centralBoxes();
- // orbital boards
- pushMatrix();
- rotateZ(PI / 11 * 16);
- rotateX(PI / 13);
- orbitalBoards(20, 120, 12);
- popMatrix();
- pushMatrix();
- rotateZ(PI / 11 * 9);
- rotateX(PI / 13 * 2);
- orbitalBoards(10, 90, 16);
- popMatrix();
- // asteroids
- asteroidBelt();
- // grid
- logGrid();
- pushMatrix();
- rotateX(PI);
- logGrid();
- popMatrix();
- // thunderbolt
- pushMatrix();
- rotateZ(PI/10 * 6);
- rotateY(PI/11);
- translate(50, 0, 0);
- thunderBolt();
- popMatrix();
- pushMatrix();
- rotateX(PI/2);
- rotateZ(PI/12 * 11);
- translate(70, 0, 0);
- thunderBolt();
- popMatrix();
- pushMatrix();
- rotateZ(-PI/7);
- rotateY(-PI/9);
- translate(70, 0, 0);
- thunderBolt();
- popMatrix();
- popMatrix();
- //save("output.png");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement