// Package strata (v2, "Derin Zaman") is a Sinopia engine: a geological // plate of an invented earth. On the left a cross-section: beds of eight rock // types, each with its own texture, folded by an integer sine field, cut by // faults (every bed boundary steps along the fault plane), crossed by dikes, // sills or quartz veins, sometimes truncated by an angular unconformity, with // fossils in the beds and the present land surface on top (meadow, forest, // bare rock or snow). On the right the stratigraphic column of the same // beds: each formation named (Kızıldere, Akyayla, ...), dated in Ma, drawn // with its true thickness and a width by its resistance (a weathering // profile), fossils and events marked. Rare events tell a story: an aquifer // with its well, a karst cave, an oil trap under an anticline with its // derrick, a gold vein, an impact boundary. // // It is the successor of Strata v1 (p/.../art/strata/v1, which stays // untouched): the same FNV-1a + splitmix64 streams (seed+"|traits" and // seed+"|art") and the same integer sine table, a new picture. // frontend/src/engines/stratav2.ts is a byte-identical TypeScript twin; // strata_test.gno pins golden vectors that the twin asserts too. // // Unlike v1 the art reads Input.TokenID (the column's title, "Section 42"). // It never reads heights or moves, so the engine is not living. Pure integer // maths: no floats, no time, no block data. package strata import ( "errors" "strconv" "strings" "gno.land/p/g1jz6j9hj6rdf5ltl2kcrpa4jwtdh3w30z0yul06/sinopia4/engine/v2" ) // traitTypes in the order Traits returns them. var traitTypes = []string{"Era", "Event", "Fossil", "Intrusion", "Folding", "Tectonics", "Surface", "Rarity"} // MaxSVGBytes: the largest output measured is 16,755 B (10,000 default seeds // and 8,000 params renders, docs/engines/strata-v2.md); about 1.7x margin, // within the 28 KB budget. const MaxSVGBytes = 28672 // ParamsSchema is the Studio form. Studio sends JSON.stringify of the values // in this property order; ValidateParams accepts exactly that or "". const ParamsSchema = `{"type":"object","properties":{` + `"era":{"type":"string","title":"Era","enum":["Seeded","Red Beds","Chalk Sea","Volcanic Arc","Coal Age",` + `"Desert Dunes","Ice Age","Lapis Vein"],"default":"Seeded"},` + `"folding":{"type":"string","title":"Folding","enum":["Seeded","Flat","Gentle","Folded","Contorted"],"default":"Seeded"},` + `"surface":{"type":"string","title":"Surface","enum":["Seeded","Meadow","Forest","Bare Rock","Snow"],"default":"Seeded"}}}` // DefaultParams is the canonical form of the defaults; it renders exactly // like "". const DefaultParams = `{"era":"Seeded","folding":"Seeded","surface":"Seeded"}` // Manifest describes the engine. Author and FeeBps are set by the adapter. func Manifest() engine.Manifest { return engine.Manifest{ Name: "Strata · Derin Zaman", Version: "2.0.0", Description: "Strata v2: a geological plate of an invented earth. A cross-section of textured beds, " + "folded, faulted and cut by dikes, with fossils and the land surface on top, beside the " + "stratigraphic column of the same beds: every formation named and dated. Rare events tell a " + "story: an aquifer, a karst cave, an oil trap, a gold vein, an impact boundary. The token " + "number titles the section.", License: "CC-BY-NC-4.0", ParamsSchema: ParamsSchema, TraitTypes: append([]string{}, traitTypes...), Living: false, MaxSVGBytes: MaxSVGBytes, Kind: engine.KindSVG, } } // Config is a parsed params string; -1 means drawn from the seed. type Config struct { Era, Folding, Surface int } // Defaults is the showcase look (params ""). func Defaults() Config { return Config{Era: -1, Folding: -1, Surface: -1} } var errParams = errors.New(`stratav2: params must be "" or ` + `{"era":,"folding":,"surface":} in that order, without spaces`) // ParseParams accepts "" or the canonical JSON Studio produces, nothing else. func ParseParams(params string) (Config, error) { cfg := Defaults() if params == "" { return cfg, nil } v, rest, ok := strValue(params, `{"era":"`) if !ok { return cfg, errParams } if cfg.Era, ok = enumIndex(v, eras); !ok { return cfg, errParams } if v, rest, ok = strValue(rest, `","folding":"`); !ok { return cfg, errParams } if cfg.Folding, ok = enumIndex(v, foldings); !ok { return cfg, errParams } if v, rest, ok = strValue(rest, `","surface":"`); !ok { return cfg, errParams } if cfg.Surface, ok = enumIndex(v, surfaces); !ok { return cfg, errParams } if rest != `"}` { return cfg, errParams } return cfg, nil } // strValue expects s to start with prefix and returns the text up to the // next '"' and the remainder starting at that quote. func strValue(s, prefix string) (string, string, bool) { if !strings.HasPrefix(s, prefix) { return "", "", false } s = s[len(prefix):] end := strings.IndexByte(s, '"') if end < 0 { return "", "", false } return s[:end], s[end:], true } func enumIndex(v string, table []option) (int, bool) { if v == "Seeded" { return -1, true } for i, o := range table { if o.name == v { return i, true } } return 0, false } // ValidateParams accepts "" (the showcase defaults) and the canonical JSON. func ValidateParams(params string) error { _, err := ParseParams(params) return err } func mustConfig(params string) Config { cfg, err := ParseParams(params) if err != nil { panic(err) } return cfg } // Traits returns the eight traits of in.Seed in TraitTypes order. It never // renders: eight draws and a score. func Traits(in engine.Input) []engine.Trait { t := TraitsOf(in.Seed, mustConfig(in.Params)) return []engine.Trait{ {Type: "Era", Value: t.Era}, {Type: "Event", Value: t.Event}, {Type: "Fossil", Value: t.Fossil}, {Type: "Intrusion", Value: t.Intrusion}, {Type: "Folding", Value: t.Folding}, {Type: "Tectonics", Value: t.Tectonics}, {Type: "Surface", Value: t.Surface}, {Type: "Rarity", Value: t.Rarity}, } } // Render returns the raw SVG for in.Seed, in.Params and in.TokenID. func Render(in engine.Input) string { return SVG(in.Seed, mustConfig(in.Params), in.TokenID) } // --------------------------------------------------------------------------- // Deterministic randomness: FNV-1a over the seed, then splitmix64 (Strata // v1's stream). Traits use seed+"|traits", the art seed+"|art". // --------------------------------------------------------------------------- type rng struct{ state uint64 } func newRNG(seed string) *rng { h := uint64(14695981039346656037) for i := 0; i < len(seed); i++ { h ^= uint64(seed[i]) h *= 1099511628211 } if h == 0 { h = 1099511628211 } return &rng{state: h} } func (r *rng) next() uint64 { r.state += 0x9E3779B97F4A7C15 z := r.state z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9 z = (z ^ (z >> 27)) * 0x94D049BB133111EB return z ^ (z >> 31) } // intn is in [0, n); one draw whenever n > 0. func (r *rng) intn(n int) int { if n <= 0 { return 0 } return int(r.next() % uint64(n)) } // between is in [a, b]. func (r *rng) between(a, b int) int { return a + r.intn(b-a+1) } // --------------------------------------------------------------------------- // Tables // --------------------------------------------------------------------------- type option struct { name string weight int score int // contribution to the rarity score when drawn (not pinned) } func pick(r *rng, table []option) int { total := 0 for _, o := range table { total += o.weight } x := r.intn(total) for i, o := range table { x -= o.weight if x < 0 { return i } } return len(table) - 1 } var eras = []option{ {"Red Beds", 22, 0}, {"Chalk Sea", 18, 0}, {"Volcanic Arc", 14, 0}, {"Coal Age", 14, 0}, {"Desert Dunes", 14, 0}, {"Ice Age", 10, 1}, {"Lapis Vein", 6, 4}, } const ( eVolcanic = 2 eDesert = 4 eLapis = 6 ) // eraSky: the sky gradient, top and bottom. var eraSky = [][]string{ {"#e9dcc4", "#f4ecdc"}, {"#dfe6e4", "#f2f2ea"}, {"#d8d2d6", "#eeeae6"}, {"#d6dccd", "#ecefe4"}, {"#f0d9b0", "#f8eedc"}, {"#d6e2ea", "#eef3f5"}, {"#d9dbe6", "#f0eff2"}, } // eraRock: the rock colours in liths order. var eraRock = [][]string{ {"#c0643f", "#7a3426", "#d9b38c", "#a8553a", "#b98a6a", "#9a6b5a", "#3a2620", "#e8d6c0"}, {"#d8c49a", "#8a8a7a", "#ece4cc", "#b8a684", "#cfc7a8", "#a7a294", "#33302a", "#f4efe2"}, {"#8d7a76", "#4a3f48", "#b8aca8", "#6e5a5a", "#9a8c8c", "#b5a3b8", "#211d22", "#d9d0d4"}, {"#b0a080", "#4c4a44", "#c4bca4", "#8a7c64", "#9c967e", "#8c8678", "#1b1a18", "#e2ddcc"}, {"#dd9a55", "#9c5a36", "#e8cfa0", "#c07a45", "#d2a074", "#b88a6a", "#4a3022", "#f3e6cc"}, {"#a9b2b0", "#5f6a72", "#d2d8d6", "#87908e", "#b4bcbc", "#9aa0a8", "#262b30", "#eef2f2"}, {"#4a5a8a", "#1f2747", "#8a93b8", "#3a4670", "#6a73a0", "#5a5f86", "#141726", "#c9cde0"}, } var liths = []option{ {"Sandstone", 26, 0}, {"Shale", 22, 0}, {"Limestone", 20, 0}, {"Conglomerate", 9, 0}, {"Marl", 10, 0}, {"Tuff", 6, 0}, {"Coal", 4, 0}, {"Evaporite", 3, 0}, } const ( lSandstone = 0 lShale = 1 lLimestone = 2 lCoal = 6 ) // lithW is the column width of each rock: resistant rocks stand out. var lithW = []int{26, 16, 30, 28, 20, 22, 12, 18} const lithID = "kslcmtoe" var lithPat = []string{ ``, ``, ``, ``, ``, ``, ``, ``, } var foldings = []option{{"Flat", 22, 0}, {"Gentle", 34, 0}, {"Folded", 30, 0}, {"Contorted", 14, 1}} var foldAmp = []int{0, 18, 42, 70} var faultsT = []option{{"0", 30, 0}, {"1", 44, 0}, {"2", 26, 1}} var intrusions = []option{{"None", 46, 0}, {"Dike", 24, 0}, {"Sill", 16, 0}, {"Dike & Sill", 10, 1}, {"Vein Swarm", 4, 3}} const ( iDike = 1 iSill = 2 iBoth = 3 iSwarm = 4 ) var fossils = []option{ {"None", 34, 0}, {"Ammonite", 20, 0}, {"Fish", 14, 0}, {"Leaf", 14, 0}, {"Sea Urchin", 12, 0}, {"Fossil Bed", 6, 2}, } const fBed = 5 var fossilSym = []string{ ``, ``, ``, ``, } var fossilID = []string{"fa", "fb", "fy", "fd"} var events = []option{ {"None", 64, 0}, {"Aquifer", 9, 3}, {"Karst Cave", 9, 3}, {"Oil Trap", 6, 3}, {"Gold Vein", 6, 3}, {"Impact Boundary", 6, 3}, } const ( evAquifer = 1 evKarst = 2 evOil = 3 evGold = 4 evImpact = 5 ) var surfaces = []option{{"Meadow", 40, 0}, {"Forest", 26, 0}, {"Bare Rock", 22, 0}, {"Snow", 12, 0}} const ( sMeadow = 0 sForest = 1 sSnow = 3 ) const ( unconfPct = 28 scoreUnconf = 1 ) var tectonics = []string{"Undisturbed", "One Fault", "Two Faults", "Unconformity", "Unconformity + One Fault", "Unconformity + Two Faults"} // Rarity cut-offs on the summed score (10,000 default seeds: see // docs/engines/strata-v2.md). const ( scoreMythic = 8 scoreLegendary = 6 scoreRare = 4 scoreUncommon = 2 ) var namesA = []string{"Kızıl", "Ak", "Kara", "Sarı", "Boz", "Gök", "Demir", "Taş", "Çam", "Göl", "Kuru", "Ulu", "Ilı", "Yel", "Elma", "Dikmen"} var namesB = []string{"dere", "tepe", "kaya", "ova", "pınar", "bel", "yurt", "köy", "sırt", "yayla", "çay", "bük"} // --------------------------------------------------------------------------- // Traits // --------------------------------------------------------------------------- type draw struct { era, folding, faults, intrusion int unconf bool fossil, event, surface int score int rarity string } // derive draws the traits from seed+"|traits". The draw order is part of the // contract: era, folding, faults, intrusion, unconformity (intn(100) < 28), // fossil, event, surface. Params pin era/folding/surface after all draws, so // a seed's other traits never move; a pinned trait scores 0. func derive(seed string, cfg Config) draw { r := newRNG(seed + "|traits") d := draw{} d.era = pick(r, eras) d.folding = pick(r, foldings) d.faults = pick(r, faultsT) d.intrusion = pick(r, intrusions) d.unconf = r.intn(100) < unconfPct d.fossil = pick(r, fossils) d.event = pick(r, events) d.surface = pick(r, surfaces) score := faultsT[d.faults].score + intrusions[d.intrusion].score + fossils[d.fossil].score + events[d.event].score if d.unconf { score += scoreUnconf } if cfg.Era >= 0 { d.era = cfg.Era } else { score += eras[d.era].score } if cfg.Folding >= 0 { d.folding = cfg.Folding } else { score += foldings[d.folding].score } if cfg.Surface >= 0 { d.surface = cfg.Surface } else { score += surfaces[d.surface].score } d.score = score switch { case score >= scoreMythic: d.rarity = "Mythic" case score >= scoreLegendary: d.rarity = "Legendary" case score >= scoreRare: d.rarity = "Rare" case score >= scoreUncommon: d.rarity = "Uncommon" default: d.rarity = "Common" } return d } // TraitSet is the decoded traits of a seed; the picture reads the same draw. type TraitSet struct { Era, Event, Fossil, Intrusion, Folding, Tectonics, Surface, Rarity string Score int } // TraitsOf returns the traits of a seed under cfg. func TraitsOf(seed string, cfg Config) TraitSet { d := derive(seed, cfg) tec := d.faults if d.unconf { tec += 3 } return TraitSet{ Era: eras[d.era].name, Event: events[d.event].name, Fossil: fossils[d.fossil].name, Intrusion: intrusions[d.intrusion].name, Folding: foldings[d.folding].name, Tectonics: tectonics[tec], Surface: surfaces[d.surface].name, Rarity: d.rarity, Score: d.score, } } // SectionNumber is the number in the column title: Input.TokenID read as a // decimal, modulo 1,000,000. Anything but ASCII digits (or "") is 0. func SectionNumber(tokenID string) int { v := 0 for i := 0; i < len(tokenID); i++ { c := tokenID[i] if c < '0' || c > '9' { return 0 } v = (v*10 + int(c-'0')) % 1000000 } return v } // --------------------------------------------------------------------------- // Integer helpers // --------------------------------------------------------------------------- func iabs(a int) int { if a < 0 { return -a } return a } func imin(a, b int) int { if a < b { return a } return b } func imax(a, b int) int { if a > b { return a } return b } // quarter is a quarter wave, 256 steps per turn, x1024 (Strata v1's table). var quarter = []int{0, 25, 50, 75, 100, 125, 150, 175, 200, 224, 249, 273, 297, 321, 345, 369, 392, 415, 438, 460, 483, 505, 526, 548, 569, 590, 610, 630, 650, 669, 688, 706, 724, 742, 759, 775, 792, 807, 822, 837, 851, 865, 878, 891, 903, 915, 926, 936, 946, 955, 964, 972, 980, 987, 993, 999, 1004, 1009, 1013, 1016, 1019, 1021, 1023, 1024, 1024} func isin(a int) int { a %= 256 if a < 0 { a += 256 } switch { case a < 64: return quarter[a] case a < 128: return quarter[128-a] case a < 192: return -quarter[a-128] } return -quarter[256-a] } func icos(a int) int { return isin(a + 64) } const hexDigits = "0123456789abcdef" func hexByte(c string, i int) int { return strings.IndexByte(hexDigits, c[i])*16 + strings.IndexByte(hexDigits, c[i+1]) } // mix is a + (b - a) * t / 100 per channel (truncated), "#rrggbb". func mix(a, b string, t int) string { out := []byte{'#', 0, 0, 0, 0, 0, 0} for i := 1; i < 7; i += 2 { va, vb := hexByte(a, i), hexByte(b, i) v := va + (vb-va)*t/100 out[i] = hexDigits[v>>4] out[i+1] = hexDigits[v&15] } return string(out) } // contrast is a colour that reads on top of rock colour c. func contrast(c string) string { luma := (299*hexByte(c, 1) + 587*hexByte(c, 3) + 114*hexByte(c, 5)) / 1000 if luma > 110 { return mix(c, "#1a120c", 65) } return mix(c, "#ffffff", 60) } func itoa(n int) string { return strconv.Itoa(n) } // --------------------------------------------------------------------------- // The section // --------------------------------------------------------------------------- const ( sheetW = 640 // sheet sheetH = 800 sx = 16 // section box; the section is drawn in local coordinates sy = 16 sw = 480 sh = 768 bot = sh + 40 // rock bodies close below the box step = 16 // 30 steps, 31 samples ns = sw / step colX = 512 // the column colTop = 80 colH = 660 none = 99 ) // relSteps writes the relative steps between consecutive points, // "dx dy dx dy", with no separator before a minus; zero moves are skipped. func relSteps(b *strings.Builder, xs, ys []int) { first := true px, py := xs[0], ys[0] for i := 1; i < len(xs); i++ { dx, dy := xs[i]-px, ys[i]-py if dx == 0 && dy == 0 { continue } if !first && dx >= 0 { b.WriteString(" ") } b.WriteString(itoa(dx)) if dy >= 0 { b.WriteString(" ") } b.WriteString(itoa(dy)) first = false px, py = xs[i], ys[i] } } // openPath writes an open polyline "Mx yl...". func openPath(b *strings.Builder, xs, ys []int) { b.WriteString("M") b.WriteString(itoa(xs[0])) b.WriteString(" ") b.WriteString(itoa(ys[0])) b.WriteString("l") relSteps(b, xs, ys) } // bodyPath writes a rock body: the curve, continued 20 px past both sides, // closed below the box. func bodyPath(b *strings.Builder, xs, ys []int) { b.WriteString("M-20 " + itoa(bot) + "V" + itoa(ys[0]) + "h20l") relSteps(b, xs, ys) b.WriteString("h20V" + itoa(bot) + "z") } type fault struct{ x0, sl, th int } type section struct { n, uIdx, a0, lam, ph, ph2, tilt, uTilt, anti int depth, surf []int faults []fault } func (s *section) surfAt(x int) int { if x <= 0 { return s.surf[0] } if x >= sw { return s.surf[ns] } i := x / step rem := x - i*step return s.surf[i] + (s.surf[i+1]-s.surf[i])*rem/step } func (s *section) fx(f fault, y int) int { return f.x0 + f.sl*(y-300)/100 } func (s *section) throwAt(x, y int) int { t := 0 for _, f := range s.faults { if x > s.fx(f, y) { t += f.th } } return t } // eAt is the erosion surface of the unconformity. func (s *section) eAt(x int) int { return s.depth[s.uIdx] - 8 + (6*isin(3*x+s.ph)+3*isin(x*256/61+s.ph2))/1024 } // raw is boundary k (the top of bed k+1) at x before faulting. func (s *section) raw(k, x int) int { if k == s.uIdx { return s.eAt(x) } old := k > s.uIdx a := s.a0 * k / (s.n + 4) if old { a = s.a0 + 26 } y := s.depth[k] + a*isin(x*256/s.lam+s.ph+3*k)/1024 + (a>>2)*isin(x*256/97+s.ph2)/1024 + s.tilt*(x-240)*(k+2)/(100*s.n) if old { y += s.uTilt * (x - 240) / 100 } if s.anti >= 0 && k >= 1 { d := iabs(x - s.anti) if d < 170 { y -= 15 * imin(k, 4) * (1024 + icos(d*128/170)) / 2048 } } if old { y = imax(y, s.eAt(x)+1) } return y } func (s *section) clampY(x, y int) int { return imin(imax(y, s.surfAt(x)+2), sh+20) } // at is boundary k at x after faulting, kept below the land surface. func (s *section) at(k, x int) int { y0 := s.raw(k, x) return s.clampY(x, y0+s.throwAt(x, y0)) } // boundary samples boundary k every 16 px, with a step on the fault plane at // every fault it crosses. func (s *section) boundary(k int) ([]int, []int) { xs := make([]int, 0, ns+8) ys := make([]int, 0, ns+8) nf := len(s.faults) prev := make([]bool, nf) for x := 0; x <= sw; x += step { y0 := s.raw(k, x) for fi := 0; fi < nf; fi++ { f := s.faults[fi] side := x > s.fx(f, y0) if x > 0 && side != prev[fi] { xf := s.fx(f, y0) yb := s.raw(k, xf) // each side meets the fault plane at its own (thrown) depth yl, yr := yb+s.throwAt(xf-2, yb), yb+s.throwAt(xf+2, yb) xl, xr := s.fx(f, yl)-1, s.fx(f, yr)+1 xs = append(xs, xl, xr) ys = append(ys, s.clampY(xl, yl), s.clampY(xr, yr)) } prev[fi] = side } xs = append(xs, x) ys = append(ys, s.clampY(x, y0+s.throwAt(x, y0))) } return xs, ys } // --------------------------------------------------------------------------- // The plate // --------------------------------------------------------------------------- // SVG renders a seed under cfg with the token number tokenID. The art // stream's draw order is part of the contract (it mirrors stratav2.ts). func SVG(seed string, cfg Config, tokenID string) string { d := derive(seed, cfg) r := newRNG(seed + "|art") rock := eraRock[d.era] sky := eraSky[d.era] s := §ion{uIdx: none, anti: -1} // --- the plan: beds, names, ages --- n := r.between(10, 14) s.n = n lith := make([]int, n) for i := 0; i < n; i++ { l := pick(r, liths) if d.event == evAquifer && i == 3 { l = lSandstone } if d.event == evKarst && i == 5 { l = lLimestone } if d.event == evOil && i == 4 { l = lShale // the cap rock } if d.event == evOil && i == 5 { l = lSandstone // the reservoir } lith[i] = l } thick := make([]int, n) total := 0 for i := 0; i < n; i++ { if lith[i] == lCoal { thick[i] = r.between(10, 16) } else { thick[i] = r.between(30, 70) } total += thick[i] } names := make([]string, n) for i := 0; i < n; i++ { a := namesA[r.intn(len(namesA))] names[i] = a + namesB[r.intn(len(namesB))] } sBase := r.between(130, 190) sp1 := r.intn(256) sp2 := r.intn(256) sa1 := r.between(14, 40) sa2 := r.between(6, 16) if d.unconf { s.uIdx = r.between(3, imin(6, n-3)) } ages := make([]int, n) age := r.between(2, 12) for i := 0; i < n; i++ { ages[i] = age age += r.between(4, 30) if i == s.uIdx { age += r.between(60, 200) // the hiatus } } s.a0 = foldAmp[d.folding] s.lam = r.between(150, 330) s.ph = r.intn(256) s.tilt = r.between(-14, 14) s.ph2 = r.intn(256) if d.unconf { s.uTilt = r.between(18, 34) if r.intn(2) != 0 { s.uTilt = -s.uTilt } } for f := 0; f < d.faults; f++ { x0 := r.between(90, sw-90) sl := r.between(-35, 35) th := r.between(16, 46) if r.intn(100) >= 70 { th = -th } s.faults = append(s.faults, fault{x0, sl, th}) } if d.event == evOil { s.anti = r.between(170, sw-170) } seedR := r.between(1, 900) seedG := r.between(1, 900) sunX := r.between(60, 420) sunY := r.between(36, 80) sunR := r.between(16, 28) ridge := make([]int, 14) for i := 0; i < 14; i++ { ridge[i] = sBase - r.between(10, 60) } volc := -1 if d.era == eVolcanic { volc = r.between(2, 10) } // --- geometry --- s.surf = make([]int, ns+1) sxs := make([]int, ns+1) for i := 0; i <= ns; i++ { x := i * step sxs[i] = x s.surf[i] = sBase + (sa1*isin(x*256/700+sp1)+sa2*isin(x*256/190+sp2))/1024 } top0 := sBase + 20 span := sh - 40 - top0 s.depth = make([]int, n-1) cum := 0 for k := 0; k < n-1; k++ { cum += thick[k] s.depth[k] = top0 + span*cum/total } bx := make([][]int, n-1) by := make([][]int, n-1) for k := 0; k < n-1; k++ { bx[k], by[k] = s.boundary(k) } // --- SVG --- tid := itoa(SectionNumber(tokenID)) out := &strings.Builder{} out.WriteString(``) out.WriteString(`Strata · Section ` + tid + `` + eras[d.era].name + `: ` + itoa(n) + ` formations, ` + names[0] + ` (` + itoa(ages[0]) + ` Ma) down to ` + names[n-1] + ` (` + itoa(ages[n-1]) + ` Ma)`) if d.event > 0 { out.WriteString("; " + events[d.event].name) } out.WriteString(`.`) defs := &strings.Builder{} defs.WriteString(``) used := make([]bool, 8) for _, l := range lith { used[l] = true } for l := 0; l < 8; l++ { if used[l] { defs.WriteString(lithPat[l]) } } dunes := d.era == eDesert && used[lSandstone] if dunes { defs.WriteString(``) } defs.WriteString(`` + ``) defs.WriteString(`` + ``) var kinds []int if d.fossil == fBed { kinds = []int{0, 1, 2, 3} } else if d.fossil > 0 { kinds = []int{d.fossil - 1} } for _, fk := range kinds { defs.WriteString(fossilSym[fk]) } defs.WriteString(``) for k := 0; k < n-1; k++ { defs.WriteString(``) } // rock colour of each bed col := make([]string, n) for i := 0; i < n; i++ { if d.event == evAquifer && i == 3 { col[i] = mix(rock[lSandstone], "#3f7fa8", 45) } else { col[i] = rock[lith[i]] } } body := &strings.Builder{} // sky, sun, distant ridge body.WriteString(``) rxs := make([]int, 14) rys := make([]int, 14) for i := 0; i < 14; i++ { y := ridge[i] if volc >= 0 { y = imin(y, sBase-118+26*iabs(i-volc)) } rxs[i] = -20 + 40*i rys[i] = y } body.WriteString(``) if volc >= 0 { vx, vy := -20+40*volc, sBase-118 body.WriteString(``) } // beds body.WriteString(``) for i := 0; i < n; i++ { li := itoa(i) body.WriteString(``) if dunes && lith[i] == lSandstone { body.WriteString(``) } } // intrusions cut the beds ign := "#4a3b38" if d.era == eVolcanic { ign = "#3a3036" } ignEdge := mix(ign, "#ffffff", 45) quartz := "#eee8dc" // vein swarm: pale quartz if d.era == eLapis { quartz = "#e9d9a0" } if d.intrusion == iDike || d.intrusion == iBoth || d.intrusion == iSwarm { nd := 1 if d.intrusion == iSwarm { nd = 4 } for k := 0; k < nd; k++ { x0 := r.between(60, sw-60) var w0 int if d.intrusion == iSwarm { w0 = r.between(4, 8) } else { w0 = r.between(14, 26) } sl := r.between(-20, 20) var top int if d.unconf { top = s.eAt(x0) + 6 } else { top = sBase + r.between(20, 60) } var cx, cy []int for y := bot; y >= top; y -= 40 { cx = append(cx, x0+sl*(bot-y)/100+r.between(-3, 3)) cy = append(cy, y) } m := len(cx) xs := make([]int, 0, 2*m+1) ys := make([]int, 0, 2*m+1) for i := 0; i < m; i++ { xs = append(xs, cx[i]-w0/2) ys = append(ys, cy[i]) } xs = append(xs, cx[m-1]) ys = append(ys, top-6) right := make([]int, m) for i := 0; i < m; i++ { right[i] = cx[i] + w0/2 + r.between(-2, 2) } for i := m - 1; i >= 0; i-- { xs = append(xs, right[i]) ys = append(ys, cy[i]) } body.WriteString(``) } else { body.WriteString(`z" fill="` + ign + `" stroke="` + ignEdge + `" stroke-width="1.5"/>`) } } } if d.intrusion == iSill || d.intrusion == iBoth { k := imin(n-3, r.between(4, 8)) bxs, bys := bx[k], by[k] i0 := r.between(2, 10) i1 := imin(len(bxs)-1, i0+r.between(12, 24)) th := r.between(8, 14) var xs, ys []int for i := i0; i <= i1; i++ { xs = append(xs, bxs[i]) ys = append(ys, bys[i]) } for i := i1; i >= i0; i-- { xs = append(xs, bxs[i]) ys = append(ys, bys[i]+th*imin(3, imin(i-i0, i1-i))/3) } if i1 > i0 { body.WriteString(``) } } body.WriteString(``) // the unconformity: a dashed erosion line if d.unconf { body.WriteString(``) } // fossils fossilIn := make([]int, n) for i := range fossilIn { fossilIn[i] = -1 } nfos := 0 if d.fossil == fBed { nfos = 14 } else if len(kinds) > 0 { nfos = r.between(3, 6) } for i := 0; i < nfos; i++ { fk := kinds[r.intn(len(kinds))] k := r.between(0, n-3) x := r.between(30, sw-30) sz0 := r.between(14, 26) rot := r.between(-40, 40) yt := s.at(k, x) gap := s.at(k+1, x) - yt if gap < 8 { continue } sz := imin(sz0, imax(8, gap-4)) y := yt + gap/2 body.WriteString(``) if fossilIn[k+1] < 0 { fossilIn[k+1] = fk } } // events goldLayer, impactK := -1, -1 if d.event == evImpact { impactK = r.between(1, n-4) defs.WriteString(``) body.WriteString(`` + ``) } if d.event == evKarst { // a chamber in the limestone: vaulted roof, flat floor with a pool, dripstones x := r.between(120, sw-120) rw := r.between(40, 64) rh := r.between(22, 34) yc := s.at(4, x) + rh + 6 drip := mix(rock[lLimestone], "#ffffff", 40) st := &strings.Builder{} for xi := x - rw + 8; xi < x+rw-8; xi += r.between(6, 11) { dd := xi - x ln := r.between(3, 3+rh*(rw*rw-dd*dd)/(rw*rw*2)) st.WriteString("M" + itoa(xi-1) + " " + itoa(yc-rh*(rw*rw-dd*dd)/(rw*rw)-1) + "l1 " + itoa(ln) + "l1-" + itoa(ln) + "z") if r.intn(3) == 0 { st.WriteString("M" + itoa(xi-2) + " " + itoa(yc+1) + "l2-" + itoa(ln/2+2) + "l2 " + itoa(ln/2+2) + "z") } } body.WriteString(`` + ``) } if d.event == evGold { defs.WriteString(``) x := r.between(80, sw-80) y := sh + 10 p := &strings.Builder{} p.WriteString("M" + itoa(x) + " " + itoa(y)) for i := 0; i < 14; i++ { dx := r.between(-26, 26) dy := -r.between(18, 34) p.WriteString("l" + itoa(dx) + " " + itoa(dy)) x += dx y += dy if r.intn(100) < 30 { ex := r.between(-30, 30) ey := r.between(-20, 8) p.WriteString("l" + itoa(ex) + " " + itoa(ey) + "m" + itoa(-ex) + " " + itoa(-ey)) } } body.WriteString(``) goldLayer = n - 1 } if d.event == evOil { crest := s.at(4, s.anti) owc := crest + r.between(16, 26) // the oil-water contact is flat var xs, ys []int for x := s.anti - 140; x <= s.anti+140; x += 8 { xs = append(xs, x) ys = append(ys, imin(s.at(4, x), owc)) } body.WriteString(``) y := s.surfAt(s.anti) body.WriteString(``) } if d.event == evAquifer { x := r.between(100, sw-100) y := s.surfAt(x) b := s.at(2, x) + 16 well := `M` + itoa(x) + ` ` + itoa(y) + `V` + itoa(b) body.WriteString(``) } // faults: from the land surface down fl := "" for _, f := range s.faults { yt := s.surfAt(s.fx(f, sBase)) fl += "M" + itoa(s.fx(f, yt)) + " " + itoa(yt) + "L" + itoa(s.fx(f, sh+10)) + " " + itoa(sh+10) } if fl != "" { body.WriteString(``) } // the land surface body.WriteString(``) if d.surface == sMeadow || d.surface == sForest { green := "#4d6b38" if d.surface == sMeadow { green = "#6f8a44" } body.WriteString(``) } if d.surface == sSnow { body.WriteString(``) } if d.surface == sMeadow || d.surface == sForest { t0 := &strings.Builder{} t1 := &strings.Builder{} var nt int if d.surface == sForest { nt = r.between(10, 18) } else { nt = r.between(2, 4) } for i := 0; i < nt; i++ { x := r.between(8, sw-8) h := r.between(16, 34) y := s.surfAt(x) + 1 tr := "M" + itoa(x) + " " + itoa(y-h) + "l" + itoa(h/4) + " " + itoa(h) + "h-" + itoa(h/2) + "z" if r.intn(2) == 0 { t0.WriteString(tr) } else { t1.WriteString(tr) } } if t0.Len() > 0 { body.WriteString(``) } if t1.Len() > 0 { body.WriteString(``) } } body.WriteString(``) defs.WriteString(``) out.WriteString(defs.String()) out.WriteString(``) out.WriteString(body.String()) out.WriteString(``) // --- the stratigraphic column --- yb := make([]int, n+1) acc := 0 for i := 0; i < n; i++ { yb[i] = colTop + colH*acc/total acc += thick[i] } yb[n] = colTop + colH leaders := &strings.Builder{} labels := &strings.Builder{} for i := 0; i < n; i++ { w, h := lithW[lith[i]], yb[i+1]-yb[i] box := `` + box + `url(#` + lithID[lith[i]:lith[i]+1] + `)" stroke="#2a2420" stroke-width=".6"/>`) mid := (yb[i] + yb[i+1]) / 2 ly := colTop + colH*(2*i+1)/(2*n) leaders.WriteString("M" + itoa(colX+w+2) + " " + itoa(mid) + "L546 " + itoa(ly-5)) labels.WriteString(`` + names[i] + `` + itoa(ages[i]) + ` Ma · ` + liths[lith[i]].name + ``) if fossilIn[i] >= 0 { out.WriteString(``) } } if d.unconf { out.WriteString(``) } // event marks left of the column switch d.event { case evAquifer: out.WriteString(``) case evKarst: out.WriteString(``) case evOil: out.WriteString(``) } if goldLayer >= 0 { out.WriteString(``) } if impactK >= 0 { y := yb[impactK+1] out.WriteString(`Ir`) } out.WriteString(``) out.WriteString(`Section ` + tid + `` + eras[d.era].name + `` + itoa(n) + ` formations · ` + itoa(ages[0]) + `–` + itoa(ages[n-1]) + ` Ma`) out.WriteString(labels.String()) out.WriteString(`` + `0 · 100 mDerin Zaman`) return out.String() } func offset(ys []int, d int) []int { o := make([]int, len(ys)) for i, y := range ys { o[i] = y - d } return o }