Rendezvous With Rama

Rendezvous With Rama

Rendezvous With Rama is a seminal work by Arthur C Clarke. It tells the tale of a long cylindrical object, probably some kind of starship, that enters our solar system. It is named Rama by Earth and, as it gets closer, an expedition is sent out to make contact with it.

At first the object seems dead and doesn't respond to any attempts at contact. The expedition members find a way on board and discover a world within the object featuring lakes and buildings but still an alarming lack of life. As Rama gets closer to the sun strange things begin to happen. Robotic creatures appear and the buildings shift in shape. Eventually the expedition has to leave, as it is evident that Rama is picking up speed and they will be stuck inside forever. The expedition, once again safe in their own ship, watch as Rama departs taking its mysteries with it and leaving humanity behind - an insignificant encounter.

And here is the code:


    
let t = 1;
let maxBoxes = 500;
let stars = [];
let numStars = 800;

function setup() {
  createCanvas(400, 400, WEBGL);

  // Generate star positions on a large surrounding sphere
  for (let i = 0; i < numStars; i++) {
    let theta = random(TWO_PI);
    let phi = acos(random(-1, 1));
    let r = random(800, 1500);
    stars.push({
      x: r * sin(phi) * cos(theta),
      y: r * sin(phi) * sin(theta),
      z: r * cos(phi),
      size: random(1, 3.5),
      brightness: random(150, 255)
    });
  }
}

function draw() {
  background(0, 36, 57);
  orbitControl();

  //starfield
  push();
  noStroke();
  for (let s of stars) {
    push();
    translate(s.x, s.y, s.z);
    // Make stars glow slightly by using emissive material so lights don't dim them
    emissiveMaterial(s.brightness, s.brightness, random(200, 255));
    sphere(s.size);
    pop();
  }
  pop();

  
  rotateX(t);
  rotateY(t);
  rotateZ(t);

  noStroke();
  fill('#4e7988');

  ambientLight(10);
  directionalLight(255, 255, 255, 1, 1, -1);
  pointLight(255, 255, 255, 0, 0, 300);

  let count = 0;

  for (let j = 0; j < 400; j += 7) {
    for (let i = 0; i < 400; i += 3) {
      if (count >= maxBoxes) break;

      let x = j * sin(i / t) / tan(t / 4);
      let y = i * cos(j / t) * tan(t);
      let z = 100 * sin(i * 0.1 + t) * cos(j * 0.1 + t);

      push();
      translate(x, y, z);

      ambientMaterial(255, 25, 120);
      box(20 * sin(t));
      pop();

      count++;
    }
    if (count >= maxBoxes) break;
  }

  t += 0.008;
}
    

Comments

Popular posts from this blog

Tutorial: Hello, world! in Z80 Assembly Language

La Isla Bonita

にゃー、にゃー。(Meow, meow)