Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Symta v0.2

Name: Anonymous 2012-12-08 11:36

Ok. I put out the second release of Symta: http://sym.at.ua/load

Also the SymCraft/LispCraft sources are under 1100 lines (http://sym.at.ua/photo), including UI and a simple AI.

Name: Anonymous 2012-12-13 17:57

I'm doing a new random map generator, so I rewrote simplex noise function from JS...

Symta:

noise X Y Z
= dot:<G X Y Z = G,0*X + G,1*Y + G,2*Z>
= mix:<A B T = (1.0-T)*A + T*B>
= fade:<T = T*T*T*(T*(T*6.0-15.0)+10.0)>
= FX:X,floor = FY:Y,floor = FZ:Z,floor // Find unit grid cell containing point
= !X-FX = !Y-FY = !Z-FZ // Get relative xyz coordinates of point within that cell
// Wrap the integer cells at 255 (smaller integer period can be introduced here)
= and !FX 255 = and !FY 255 = and !FZ 255
// Calculate a set of eight hashed gradient indices
= GI000: mod Perm,(FX+Perm,(FY+Perm,(FZ))) 12
= GI001: mod Perm,(FX+Perm,(FY+Perm,(FZ+1))) 12
= GI010: mod Perm,(FX+Perm,(FY+1+Perm,(FZ))) 12
= GI011: mod Perm,(FX+Perm,(FY+1+Perm,(FZ+1))) 12
= GI100: mod Perm,(FX+1+Perm,(FY+Perm,(FZ))) 12
= GI101: mod Perm,(FX+1+Perm,(FY+Perm,(FZ+1))) 12
= GI110: mod Perm,(FX+1+Perm,(FY+1+Perm,(FZ))) 12
= GI111: mod Perm,(FX+1+Perm,(FY+1+Perm,(FZ+1))) 12
// Calculate noise contributions from each of the eight corners
= N000: dot Grad3,GI000 X   Y   Z
= N100: dot Grad3,GI100 X-1 Y   Z
= N010: dot Grad3,GI010 X   Y-1 Z
= N110: dot Grad3,GI110 X-1 Y-1 Z
= N001: dot Grad3,GI001 X   Y   Z-1
= N101: dot Grad3,GI101 X-1 Y   Z-1
= N011: dot Grad3,GI011 X   Y-1 Z-1
= N111: dot Grad3,GI111 X-1 Y-1 Z-1
// Compute the fade curve value for each of x, y, z
= U:X,fade = V:Y,fade = W:Z,fade
// Interpolate along x the contributions from each of the corners
= NX00: mix N000 N100 U
= NX01: mix N001 N101 U
= NX10: mix N010 N110 U
= NX11: mix N011 N111 U
// Interpolate the four results along y
= NXY0: mix NX00 NX10 V
= NXY1: mix NX01 NX11 V
// Interpolate the two last results along z
= NXYZ: mix NXY0 NXY1 W
= NXYZ+0.5


JavaScript:

ClassicalNoise.prototype.dot = function(g, x, y, z) {
    return g[0]*x + g[1]*y + g[2]*z;
};

ClassicalNoise.prototype.mix = function(a, b, t) {
    return (1.0-t)*a + t*b;
};

ClassicalNoise.prototype.fade = function(t) {
    return t*t*t*(t*(t*6.0-15.0)+10.0);
};

  // Classic Perlin noise, 3D version
ClassicalNoise.prototype.noise = function(x, y, z) {
  // Find unit grid cell containing point
  var X = Math.floor(x);
  var Y = Math.floor(y);
  var Z = Math.floor(z);

  // Get relative xyz coordinates of point within that cell
  x = x - X;
  y = y - Y;
  z = z - Z;

  // Wrap the integer cells at 255 (smaller integer period can be introduced here)
  X = X & 255;
  Y = Y & 255;
  Z = Z & 255;

  // Calculate a set of eight hashed gradient indices
  var gi000 = this.perm[X+this.perm[Y+this.perm[Z]]] % 12;
  var gi001 = this.perm[X+this.perm[Y+this.perm[Z+1]]] % 12;
  var gi010 = this.perm[X+this.perm[Y+1+this.perm[Z]]] % 12;
  var gi011 = this.perm[X+this.perm[Y+1+this.perm[Z+1]]] % 12;
  var gi100 = this.perm[X+1+this.perm[Y+this.perm[Z]]] % 12;
  var gi101 = this.perm[X+1+this.perm[Y+this.perm[Z+1]]] % 12;
  var gi110 = this.perm[X+1+this.perm[Y+1+this.perm[Z]]] % 12;
  var gi111 = this.perm[X+1+this.perm[Y+1+this.perm[Z+1]]] % 12;

  // The gradients of each corner are now:
  // g000 = grad3[gi000];
  // g001 = grad3[gi001];
  // g010 = grad3[gi010];
  // g011 = grad3[gi011];
  // g100 = grad3[gi100];
  // g101 = grad3[gi101];
  // g110 = grad3[gi110];
  // g111 = grad3[gi111];
  // Calculate noise contributions from each of the eight corners
  var n000= this.dot(this.grad3[gi000], x, y, z);
  var n100= this.dot(this.grad3[gi100], x-1, y, z);
  var n010= this.dot(this.grad3[gi010], x, y-1, z);
  var n110= this.dot(this.grad3[gi110], x-1, y-1, z);
  var n001= this.dot(this.grad3[gi001], x, y, z-1);
  var n101= this.dot(this.grad3[gi101], x-1, y, z-1);
  var n011= this.dot(this.grad3[gi011], x, y-1, z-1);
  var n111= this.dot(this.grad3[gi111], x-1, y-1, z-1);
  // Compute the fade curve value for each of x, y, z
  var u = this.fade(x);
  var v = this.fade(y);
  var w = this.fade(z);
   // Interpolate along x the contributions from each of the corners
  var nx00 = this.mix(n000, n100, u);
  var nx01 = this.mix(n001, n101, u);
  var nx10 = this.mix(n010, n110, u);
  var nx11 = this.mix(n011, n111, u);
  // Interpolate the four results along y
  var nxy0 = this.mix(nx00, nx10, v);
  var nxy1 = this.mix(nx01, nx11, v);
  // Interpolate the two last results along z
  var nxyz = this.mix(nxy0, nxy1, w);

  return nxyz;
};

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List