fogón

← Level pieces 23D assetfogon/nivel-gema

Gema

by fogonCC03772 blocks
GemaDrag to turn it
// «Gema» · gpt-6-sol (medium)
// A cut gemstone collectible: a big faceted emerald green gem shaped like a bipyramid (a wide hexagonal middle, a short pointed top and a longer pointed bottom), about 26 tall and 22 wide, in 4 shades of green with lighter facet edges and a white sparkle highlight, floating with its tip at z 4.

part("gema", [24, 24, 17]);

const green = ["#087b50", "#0da365", "#1fca79", "#48eb98"];
const edge = "#91ffd0";

function inside(x, y, z) {
  if (z < 0 || z > 25) return false;

  // Wide hexagonal middle, short upper point, longer lower point.
  const t = z < 16 ? z / 16
          : z <= 18 ? 1
          : (25 - z) / 7;
  const dx = Math.abs(x - 24);
  const dy = Math.abs(y - 24);
  const limit = 11 * t + 0.05;

  return dx <= limit &&
         dy <= 9.5 * t + 0.05 &&
         dx * 0.5 + dy * 0.866 <= limit;
}

for (let z = 0; z <= 25; z++) {
  for (let y = 13; y <= 35; y++) {
    for (let x = 13; x <= 35; x++) {
      if (!inside(x, y, z)) continue;

      const angle = (Math.atan2(y - 24, x - 24) + Math.PI * 2) % (Math.PI * 2);
      const sector = Math.floor((angle + Math.PI / 6) / (Math.PI / 3)) % 6;
      const shades = z >= 18
        ? [2, 1, 1, 2, 3, 3]
        : [1, 0, 0, 1, 2, 3];

      set(x, y, z, green[shades[sector]]);
    }
  }
}

// Pale lines along the sloping facet edges.
for (let z = 1; z <= 24; z++) {
  const t = z < 16 ? z / 16
          : z <= 18 ? 1
          : (25 - z) / 7;

  for (let k = 0; k < 6; k++) {
    const a = k * Math.PI / 3;
    const vx = 24 + 11 * t * Math.cos(a);
    const vy = 24 + 11 * t * Math.sin(a);

    for (let y = Math.round(vy) - 1; y <= Math.round(vy) + 1; y++) {
      for (let x = Math.round(vx) - 1; x <= Math.round(vx) + 1; x++) {
        if (inside(x, y, z) && Math.hypot(x - vx, y - vy) < 0.85) {
          set(x, y, z, edge);
        }
      }
    }
  }
}

// Bright hexagonal girdle.
for (let z = 16; z <= 18; z++) {
  for (let y = 13; y <= 35; y++) {
    for (let x = 13; x <= 35; x++) {
      if (!inside(x, y, z)) continue;
      if (!inside(x - 1, y, z) || !inside(x + 1, y, z) ||
          !inside(x, y - 1, z) || !inside(x, y + 1, z)) {
        set(x, y, z, z === 17 ? "#6af5ab" : "#43db90");
      }
    }
  }
}

// White four-point sparkle on the viewer-facing upper facets.
function sparkle(x, z, color) {
  for (let y = 13; y <= 24; y++) {
    if (inside(x, y, z) && !inside(x, y - 1, z)) {
      set(x, y, z, color);
      break;
    }
  }
}

sparkle(20, 21, "#ffffff");
sparkle(20, 20, "#ffffff");
sparkle(20, 19, "#ffffff");
sparkle(19, 20, "#ffffff");
sparkle(21, 20, "#ffffff");
sparkle(20, 22, "#baffdf");
sparkle(18, 20, "#baffdf");
sparkle(22, 20, "#baffdf");

animate("gema", { type: "spin", axis: "z", speed: -2 });
animate("gema", { type: "bob", axis: "z", amplitude: 1.5 });