rustango-cms 0.4.0

A page-tree content management system for Rust, built on rustango
Documentation
<!doctype html>
<!--
  Sample pictures for the starter themes, drawn here rather than taken from
  photo sites: every picture is original, so the themes ship them with no
  licence to track.

  Open with ?scene=<name> (one of SCENES below) and the canvas draws that
  picture at 1600×1000. scripts/theme-media/README.md says how to save them
  all as JPEGs into crates/rcms-scaffold/themes/_shared/media/.

  Every scene uses a seeded random generator, so a picture is the same
  every time it is drawn.
-->
<html lang="en">
<head>
<meta charset="utf-8">
<title>Theme sample pictures</title>
<style>
  html, body { margin: 0; background: #222; }
  canvas { display: block; }
</style>
</head>
<body>
<canvas id="c" width="1600" height="1000"></canvas>
<script>
const W = 1600;
const H = 1000;
const ctx = document.getElementById("c").getContext("2d");

/* Seeded random numbers (mulberry32). */
function rng(seed) {
  let a = seed >>> 0;
  return () => {
    a = (a + 0x6d2b79f5) >>> 0;
    let t = a;
    t = Math.imul(t ^ (t >>> 15), t | 1);
    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
  };
}

function linear(x0, y0, x1, y1, stops) {
  const g = ctx.createLinearGradient(x0, y0, x1, y1);
  stops.forEach(([at, colour]) => g.addColorStop(at, colour));
  return g;
}

function radial(x, y, r, stops) {
  const g = ctx.createRadialGradient(x, y, 0, x, y, r);
  stops.forEach(([at, colour]) => g.addColorStop(at, colour));
  return g;
}

function fill(style) {
  ctx.fillStyle = style;
  ctx.fillRect(0, 0, W, H);
}

/* Film grain, so flat gradients don't band and the pictures feel printed. */
function grain(amount, seed) {
  const r = rng(seed);
  const img = ctx.getImageData(0, 0, W, H);
  for (let i = 0; i < img.data.length; i += 4) {
    const n = (r() - 0.5) * amount;
    img.data[i] += n;
    img.data[i + 1] += n;
    img.data[i + 2] += n;
  }
  ctx.putImageData(img, 0, 0);
}

/* A smooth ridge line: a sum of sines with random phases. */
function ridge(r, base, height, waves) {
  const parts = Array.from({ length: waves }, (_, i) => ({
    f: (i + 1) * (0.6 + r() * 0.8) / W * Math.PI * 2,
    p: r() * Math.PI * 2,
    a: height / (i + 1.2),
  }));
  return (x) => base + parts.reduce((y, w) => y + Math.sin(x * w.f + w.p) * w.a, 0);
}

function layer(f, colour) {
  ctx.beginPath();
  ctx.moveTo(0, H);
  for (let x = 0; x <= W; x += 8) ctx.lineTo(x, f(x));
  ctx.lineTo(W, H);
  ctx.closePath();
  ctx.fillStyle = colour;
  ctx.fill();
}

const SCENES = {
  /* Rolling hills at dawn, layer behind layer. */
  hills() {
    const r = rng(11);
    fill(linear(0, 0, 0, H, [[0, "#f6d9c3"], [0.45, "#f2b8a0"], [1, "#c9867c"]]));
    ctx.fillStyle = radial(1150, 330, 260, [[0, "rgba(255,247,226,1)"], [0.35, "rgba(255,236,200,0.85)"], [1, "rgba(255,236,200,0)"]]);
    ctx.fillRect(0, 0, W, H);
    const colours = ["#c99a9a", "#a7798a", "#7f5b78", "#583f63", "#33264a"];
    colours.forEach((c, i) => layer(ridge(r, 420 + i * 120, 70 - i * 6, 4), c));
    grain(14, 1);
  },

  /* A calm sea at sunset with a low sun and light on the water. */
  sea() {
    const r = rng(22);
    const horizon = 560;
    fill(linear(0, 0, 0, horizon, [[0, "#1f3b5c"], [0.55, "#e2876a"], [1, "#f7c98b"]]));
    ctx.fillStyle = radial(800, horizon - 30, 150, [[0, "#fff4d8"], [0.4, "rgba(255,226,170,0.9)"], [1, "rgba(255,226,170,0)"]]);
    ctx.fillRect(0, 0, W, horizon);
    ctx.fillStyle = linear(0, horizon, 0, H, [[0, "#3f5874"], [1, "#152437"]]);
    ctx.fillRect(0, horizon, W, H - horizon);
    for (let i = 0; i < 260; i++) {
      const y = horizon + 6 + Math.pow(r(), 1.6) * (H - horizon);
      const spread = 40 + (y - horizon) * 0.9;
      const x = 800 + (r() - 0.5) * spread * 2;
      const w = 20 + r() * 90 * (y - horizon) / (H - horizon);
      ctx.fillStyle = `rgba(255,${200 + r() * 40},${150 + r() * 50},${0.25 + r() * 0.5})`;
      ctx.fillRect(x - w / 2, y, w, 2 + r() * 2);
    }
    grain(12, 2);
  },

  /* A city skyline at dusk, lit windows in the towers. */
  city() {
    const r = rng(33);
    fill(linear(0, 0, 0, H, [[0, "#141a33"], [0.6, "#3a3a6b"], [1, "#d17a6b"]]));
    for (let i = 0; i < 120; i++) {
      ctx.fillStyle = `rgba(255,255,255,${r() * 0.6})`;
      ctx.fillRect(r() * W, r() * 420, 2, 2);
    }
    const rows = [
      { base: 820, min: 160, max: 380, colour: "#2b2b52", lit: 0.12 },
      { base: H, min: 220, max: 560, colour: "#171833", lit: 0.28 },
    ];
    rows.forEach((row) => {
      let x = -20;
      while (x < W) {
        const w = 70 + r() * 120;
        const h = row.min + r() * (row.max - row.min);
        const top = row.base - h;
        ctx.fillStyle = row.colour;
        ctx.fillRect(x, top, w, h);
        for (let wy = top + 18; wy < row.base - 20; wy += 26) {
          for (let wx = x + 12; wx < x + w - 16; wx += 20) {
            if (r() < row.lit) {
              ctx.fillStyle = `rgba(255,${200 + r() * 40},${120 + r() * 60},0.9)`;
              ctx.fillRect(wx, wy, 8, 12);
            }
          }
        }
        x += w + 6 + r() * 16;
      }
    });
    grain(12, 3);
  },

  /* A studio wall: a calm geometric composition in warm paper tones. */
  studio() {
    fill("#efe7da");
    ctx.fillStyle = "#e3d6c2";
    ctx.fillRect(0, 700, W, H - 700);
    ctx.fillStyle = "#d9603b";
    ctx.beginPath();
    ctx.arc(520, 430, 230, 0, Math.PI * 2);
    ctx.fill();
    ctx.fillStyle = "#24435c";
    ctx.fillRect(780, 180, 360, 520);
    ctx.fillStyle = "#e9b949";
    ctx.beginPath();
    ctx.moveTo(1060, 700);
    ctx.lineTo(1330, 700);
    ctx.lineTo(1195, 430);
    ctx.closePath();
    ctx.fill();
    ctx.strokeStyle = "#2a2a2a";
    ctx.lineWidth = 6;
    ctx.beginPath();
    ctx.moveTo(240, 700);
    ctx.lineTo(1400, 700);
    ctx.stroke();
    ctx.fillStyle = "rgba(0,0,0,0.08)";
    ctx.fillRect(780, 700, 360, 40);
    grain(16, 4);
  },

  /* Sheets of paper on a desk, with ruled lines and a pencil. */
  paper() {
    fill(linear(0, 0, W, H, [[0, "#bfae98"], [1, "#9c8a73"]]));
    const sheet = (x, y, w, h, a, tone) => {
      ctx.save();
      ctx.translate(x, y);
      ctx.rotate(a);
      ctx.shadowColor = "rgba(0,0,0,0.25)";
      ctx.shadowBlur = 40;
      ctx.shadowOffsetY = 12;
      ctx.fillStyle = tone;
      ctx.fillRect(-w / 2, -h / 2, w, h);
      ctx.shadowColor = "transparent";
      ctx.strokeStyle = "rgba(70,110,160,0.35)";
      ctx.lineWidth = 2;
      for (let ly = -h / 2 + 90; ly < h / 2 - 30; ly += 38) {
        ctx.beginPath();
        ctx.moveTo(-w / 2 + 40, ly);
        ctx.lineTo(w / 2 - 40, ly);
        ctx.stroke();
      }
      ctx.restore();
    };
    sheet(640, 520, 640, 820, -0.12, "#f3eee4");
    sheet(900, 500, 640, 820, 0.06, "#fbf8f2");
    ctx.save();
    ctx.translate(1180, 640);
    ctx.rotate(-0.7);
    ctx.fillStyle = "#e9b949";
    ctx.fillRect(-260, -14, 460, 28);
    ctx.fillStyle = "#f1d3a8";
    ctx.beginPath();
    ctx.moveTo(200, -14);
    ctx.lineTo(260, 0);
    ctx.lineTo(200, 14);
    ctx.fill();
    ctx.fillStyle = "#333";
    ctx.beginPath();
    ctx.moveTo(244, -4);
    ctx.lineTo(260, 0);
    ctx.lineTo(244, 4);
    ctx.fill();
    ctx.restore();
    grain(12, 5);
  },

  /* Circuit traces on a dark board, with glowing nodes. */
  circuit() {
    const r = rng(66);
    fill(radial(800, 500, 1000, [[0, "#103a3a"], [1, "#061616"]]));
    const step = 40;
    ctx.lineCap = "round";
    for (let i = 0; i < 90; i++) {
      let x = Math.round((r() * W) / step) * step;
      let y = Math.round((r() * H) / step) * step;
      ctx.strokeStyle = `rgba(80,${200 + r() * 55},${170 + r() * 60},${0.35 + r() * 0.5})`;
      ctx.lineWidth = 2 + r() * 3;
      ctx.beginPath();
      ctx.moveTo(x, y);
      for (let s = 0; s < 6; s++) {
        const dir = Math.floor(r() * 4);
        const len = step * (1 + Math.floor(r() * 4));
        if (dir === 0) x += len; else if (dir === 1) x -= len; else if (dir === 2) y += len; else y -= len;
        ctx.lineTo(x, y);
      }
      ctx.stroke();
      ctx.fillStyle = radial(x, y, 18, [[0, "rgba(200,255,240,0.95)"], [1, "rgba(120,255,220,0)"]]);
      ctx.fillRect(x - 18, y - 18, 36, 36);
    }
    grain(10, 6);
  },

  /* Sound: rings spreading out from a stage light. */
  sound() {
    fill(linear(0, 0, W, H, [[0, "#2d0f3f"], [1, "#0f1238"]]));
    for (let i = 26; i > 0; i--) {
      ctx.strokeStyle = `hsla(${300 + i * 4}, 80%, ${45 + i}%, ${0.08 + (26 - i) * 0.02})`;
      ctx.lineWidth = 3 + i * 0.6;
      ctx.beginPath();
      ctx.arc(800, 1080, i * 46, Math.PI, Math.PI * 2);
      ctx.stroke();
    }
    ctx.fillStyle = radial(800, 1000, 520, [[0, "rgba(255,180,230,0.5)"], [1, "rgba(255,180,230,0)"]]);
    ctx.fillRect(0, 0, W, H);
    grain(14, 7);
  },

  /* Leaves of a house plant against a soft green wall. */
  leaves() {
    const r = rng(88);
    fill(linear(0, 0, 0, H, [[0, "#dfe8d8"], [1, "#c3d3bd"]]));
    const leaf = (x, y, len, w, a, colour) => {
      ctx.save();
      ctx.translate(x, y);
      ctx.rotate(a);
      ctx.fillStyle = colour;
      ctx.beginPath();
      ctx.moveTo(0, 0);
      ctx.quadraticCurveTo(len * 0.5, -w, len, 0);
      ctx.quadraticCurveTo(len * 0.5, w, 0, 0);
      ctx.fill();
      ctx.strokeStyle = "rgba(255,255,255,0.35)";
      ctx.lineWidth = 3;
      ctx.beginPath();
      ctx.moveTo(0, 0);
      ctx.lineTo(len * 0.95, 0);
      ctx.stroke();
      ctx.restore();
    };
    const greens = ["#2f6b47", "#3e8458", "#24563a", "#4f9a68", "#1d4630"];
    for (let i = 0; i < 26; i++) {
      const a = -Math.PI / 2 + (r() - 0.5) * 2.6;
      const len = 260 + r() * 300;
      leaf(800 + (r() - 0.5) * 200, 1040, len, len * (0.22 + r() * 0.12), a, greens[i % greens.length]);
    }
    grain(12, 8);
  },

  /* A cup of coffee from above on a wooden table. */
  coffee() {
    const r = rng(99);
    fill("#8a5a3b");
    for (let y = 0; y < H; y += 6) {
      ctx.fillStyle = `rgba(${60 + r() * 40},${30 + r() * 20},10,${0.05 + r() * 0.1})`;
      ctx.fillRect(0, y, W, 3 + r() * 4);
    }
    ctx.shadowColor = "rgba(0,0,0,0.35)";
    ctx.shadowBlur = 50;
    ctx.shadowOffsetY = 20;
    ctx.fillStyle = "#f4f1ec";
    ctx.beginPath();
    ctx.arc(820, 500, 330, 0, Math.PI * 2);
    ctx.fill();
    ctx.shadowColor = "transparent";
    ctx.fillStyle = "#ebe6df";
    ctx.beginPath();
    ctx.arc(820, 500, 210, 0, Math.PI * 2);
    ctx.fill();
    ctx.fillStyle = radial(820, 500, 180, [[0, "#c79a6b"], [0.7, "#8d5a32"], [1, "#4d2e17"]]);
    ctx.beginPath();
    ctx.arc(820, 500, 180, 0, Math.PI * 2);
    ctx.fill();
    ctx.strokeStyle = "rgba(245,225,200,0.75)";
    ctx.lineWidth = 6;
    for (let k = 0; k < 4; k++) {
      ctx.beginPath();
      ctx.ellipse(820, 470 + k * 22, 90 - k * 18, 60 - k * 12, 0, Math.PI * 0.1, Math.PI * 0.9);
      ctx.stroke();
    }
    ctx.fillStyle = "#f4f1ec";
    ctx.beginPath();
    ctx.ellipse(1140, 500, 70, 40, 0, 0, Math.PI * 2);
    ctx.fill();
    grain(14, 9);
  },

  /* A shelf of books in muted colours. */
  books() {
    const r = rng(1010);
    fill("#2a2420");
    const palette = ["#9c4f3c", "#d0a65a", "#3f6b6a", "#7c8b5a", "#c56b4c", "#e3d3b5", "#4b5a7a", "#8a5a7b"];
    [300, 640, 980].forEach((shelf) => {
      ctx.fillStyle = "#5a4636";
      ctx.fillRect(0, shelf, W, 24);
      let x = 60;
      while (x < W - 60) {
        const w = 28 + r() * 46;
        const h = 190 + r() * 90;
        const lean = r() < 0.06;
        ctx.save();
        ctx.translate(x, shelf);
        if (lean) ctx.rotate(-0.25);
        ctx.fillStyle = palette[Math.floor(r() * palette.length)];
        ctx.fillRect(0, -h, w, h);
        ctx.fillStyle = "rgba(255,255,255,0.18)";
        ctx.fillRect(4, -h + 24, w - 8, 6);
        ctx.fillRect(4, -40, w - 8, 4);
        ctx.restore();
        x += w + 3 + (lean ? 30 : 0);
      }
    });
    grain(14, 10);
  },
};

const scene = new URLSearchParams(location.search).get("scene") || "hills";
(SCENES[scene] || SCENES.hills)();
document.title = scene;
window.SCENES = Object.keys(SCENES);
</script>
</body>
</html>