Verified contractExactMIT
ArgonautsPictureV6C
Address0xa75052914ec960389e8dca257340bfcaee995160
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.24
- Same code
Only this contract
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,328,085
- Creation transaction
- 0xb6d896f101…41252c1a79
3 files
- src/PictureV6C.solmain22.32 KB
- src/PictureV6Kit.sol16.32 KB
- src/Strokes.sol19.64 KB
src/PictureV6C.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Ink, Pen, Fixed} from "./Strokes.sol";
import {ArgonautsPictureV6Kit} from "./PictureV6Kit.sol";
interface IFramesV6C {
function frames(uint256 tok, uint8[576] calldata own, uint256[576] calldata rgb, uint256 water, bool band)
external
pure
returns (bytes memory);
}
interface IDropsV6C {
function drops(uint256 tok, uint8[576] calldata own, uint256[576] calldata rgb, uint256 water, bool band)
external
pure
returns (bytes memory);
}
/// @title ArgonautsPictureV6C
contract ArgonautsPictureV6C is ArgonautsPictureV6Kit {
using Pen for Ink;
IFramesV6C public immutable life;
IDropsV6C public immutable drip;
struct S {
C c;
bool band;
uint256[6] wt;
int256 chop;
int256[3] top;
int256[3] TOP;
int256[3] DEEP;
int256 sw;
int256 pulse;
int256 under;
int256 out;
int256[] us;
int256[] vs;
uint256 n;
uint8[576] own;
uint256[576] rgb;
uint256 water;
}
constructor(address life_, address drip_) {
life = IFramesV6C(life_);
drip = IDropsV6C(drip_);
}
function layer(
uint256 tok,
uint8[576] calldata own,
uint256[576] calldata rgb,
uint256 water,
bool band,
bytes calldata bub
) external view returns (bytes memory) {
unchecked {
R memory r = _shape(own, rgb);
S memory s;
s.c = _clock(tok, band);
s.band = band;
s.own = own;
s.rgb = rgb;
s.water = water;
(s.wt, s.chop) = _water(water);
s.top = _cw(s.wt[0]);
s.TOP = _lerp(s.top, [s.top[0] * 8 / 10, s.top[1] * 105 / 100, s.top[2] * 115 / 100], _f(_h2(tok, 613), W));
s.DEEP = _cw(s.wt[1]);
s.sw = _f(_h2(2, s.c.Z), 6 * W);
s.pulse = 7 * W / 10 + _f(_h2(tok, 615), 8 * W / 10);
s.us = new int256[](200);
s.vs = new int256[](200);
Ink memory st = Pen.open(12_000);
Ink memory df = Pen.open(6_000);
Ink memory un = Pen.open(70_000);
Ink memory af = Pen.open(40_000);
(bytes memory rise, bytes memory he, bytes memory ue) = _clocks(s, st);
_defs(s, r, df);
_sea(s, r, un, rise, he);
_bubbles(s, r, un, ue);
_eyes(s, r, un, ue);
if (band) {
Ink memory gh = Pen.open(20_000);
_reef(s, r, st, gh);
_drain(s, r, st, af);
af.put(gh.close());
} else {
_ghost(s, r, st, un);
_drain(s, r, st, af);
}
return bytes.concat(
"<defs>",
df.close(),
"</defs><style>",
st.close(),
"</style>",
un.close(),
bub,
life.frames(tok, own, rgb, water, band),
af.close()
);
}
}
function _wcol(S memory s, uint256 y) internal pure returns (int256[3] memory) {
unchecked {
// forge-lint: disable-next-line(unsafe-typecast)
return _lerp(s.TOP, s.DEEP, _cl((int256(y) + 3) * W / 10));
}
}
function _cyc(S memory s, Ink memory k, int256 per, int256 phase) internal pure {
unchecked {
k.w("--p:", 4);
_dec(k, per, 3);
k.w("s;--d:-", 7);
_dec(k, _mod(phase - s.c.s0, per), 2);
k.ch(0x73);
}
}
function _pt(S memory s, int256 u, int256 v) internal pure {
unchecked {
s.us[s.n] = u;
s.vs[s.n] = v;
s.n++;
}
}
function _ramp(S memory s, int256 a, int256 b, bool up) internal pure {
unchecked {
for (int256 k = 0; k <= 10; k++) {
int256 u = a + (b - a) * k / 10;
int256 v = _sm((u - a) * W / (b - a));
_pt(s, u, up ? v : W - v);
}
}
}
function _kf(S memory s, Ink memory st, bytes2 name, bool rise, bool stepped) internal pure returns (bytes memory) {
unchecked {
int256 u0 = s.us[0];
st.w("@keyframes ", 11);
st.w(name, 2);
st.num(s.c.tok);
st.ch(0x7b);
for (uint256 i = 0; i < s.n; i++) {
_pct(st, s.us[i] - u0);
if (rise) {
st.w("{transform:translateY(", 22);
st.sint(s.vs[i]);
st.w("px)}", 4);
} else {
st.w("{opacity:", 9);
_dec(st, s.vs[i], 3);
st.ch(0x7d);
}
}
st.ch(0x7d);
s.n = 0;
Ink memory a = Pen.open(100);
a.w(name, 2);
a.num(s.c.tok);
if (stepped) a.w(" 200s step-end infinite", 23);
else a.w(" 200s linear infinite", 21);
a.w(";animation-delay:-", 18);
_dec(a, _at(s.c, u0), 2);
a.ch(0x73);
return a.close();
}
}
function _lvl(S memory s, int256 u) internal pure returns (int256) {
unchecked {
return 245e17 - _sm((u - W) * 10 / 55) * 275 / 10 * (W - _sm((u - s.c.end) * 10 / 35)) / W;
}
}
function _clocks(S memory s, Ink memory st)
internal
pure
returns (bytes memory rise, bytes memory he, bytes memory ue)
{
unchecked {
int256 end = s.c.end;
_pt(s, 0, 25);
int256 last = 25;
s.under = -1;
s.out = -1;
for (uint256 i = 0; i < 2; i++) {
int256 a = i == 0 ? W : end;
int256 b = i == 0 ? int256(65e17) : end + 35e17;
for (int256 u = a; u <= b; u += 5e16) {
int256 L = _lvl(s, u);
int256 v = _ceilI(L - HALF);
if (v != last) _pt(s, u, v);
last = v;
if (L < 0 && s.under == -1) s.under = u;
if (L >= 0 && s.under != -1 && s.out == -1 && u >= end) s.out = u;
}
}
_pt(s, end + 401e16, 25);
rise = _kf(s, st, "cr", true, true);
_pt(s, -W / 100, 0);
_ramp(s, 0, 15e17, true);
_ramp(s, end + 25e17, end + 4 * W, false);
_pt(s, end + 401e16, 0);
he = _kf(s, st, "ch", false, false);
_pt(s, s.under - W / 100, 0);
_pt(s, s.under, W);
_pt(s, s.out, W);
_pt(s, s.out + W / 100, 0);
ue = _kf(s, st, "cu", false, false);
}
}
function _runs(Ink memory k, R memory r, uint256 which) internal pure {
unchecked {
for (uint256 y = 0; y < 24; y++) {
uint256 x = 0;
while (x < 24) {
if (!_is(r, y * 24 + x, which)) {
x++;
continue;
}
uint256 w = 1;
while (x + w < 24 && _is(r, y * 24 + x + w, which)) w++;
k.ch(0x4d);
k.num(x);
k.ch(0x20);
k.num(y);
k.ch(0x68);
k.num(w);
k.w("v1h-", 4);
k.num(w);
k.ch(0x7a);
x += w;
}
}
}
}
function _is(R memory r, uint256 p, uint256 which) internal pure returns (bool) {
unchecked {
uint8 o = r.own[p];
if (which == 0) return o == 0;
if (which == 1) return o != 0 && o != 4;
if (which == 2) return o == 4;
return o == 1;
}
}
function _defs(S memory s, R memory r, Ink memory k) internal pure {
unchecked {
uint256 tok = s.c.tok;
k.w('<linearGradient id="cs', 22);
k.num(tok);
k.put(bytes('" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="0" y2="12">'));
for (int256 j = 0; j <= 11; j++) {
Ink memory c = Pen.open(8);
_hex(c, _lerp(s.TOP, s.DEEP, _cl(j * W / 10)));
bytes memory hx = c.close();
k.w('<stop offset="', 14);
_dec(k, j * W / 12, 3);
k.w('" stop-color="', 14);
k.put(hx);
k.w('"/><stop offset="', 17);
_dec(k, (j + 1) * W / 12, 3);
k.w('" stop-color="', 14);
k.put(hx);
k.w('"/>', 3);
}
k.w("</linearGradient>", 17);
k.w('<clipPath id="cg', 16);
k.num(tok);
k.w('"><path d="', 11);
_runs(k, r, 0);
k.w('"/></clipPath><clipPath id="cf', 30);
k.num(tok);
k.w('"><path d="', 11);
_runs(k, r, 1);
k.w('"/></clipPath>', 14);
if (_eyeCount(r) != 0) {
k.w('<clipPath id="ce', 16);
k.num(tok);
k.w('"><path d="', 11);
_runs(k, r, 2);
k.w('"/></clipPath>', 14);
}
}
}
function _eyeCount(R memory r) internal pure returns (uint256 n) {
unchecked {
for (uint256 p = 0; p < 576; p++) {
if (r.own[p] == 4) n++;
}
}
}
function _columns(S memory s, bool glint) internal pure returns (bytes memory) {
unchecked {
Ink memory k = Pen.open(16_000);
int256 chop = s.chop * W / 100;
int256 k1 = 7 * W / 10 * (W + chop * 4 / 10) / W;
int256 w1 = 18 * W / 10 * (W + chop) / W;
for (uint256 x = 0; x < 24; x++) {
// forge-lint: disable-next-line(unsafe-typecast)
int256 X = int256(x) * W;
if (s.chop >= 50) {
k.w('<g class="cwv" style="', 22);
_cyc(s, k, Fixed.TWO_PI * W / w1, _mod((X * k1 / W + s.sw) * W / w1, Fixed.TWO_PI * W / w1));
k.w('">', 2);
}
k.w('<rect x="', 9);
k.num(x);
k.w('" y="0" width="1" height="40"', 29);
k.w(' fill="url(#cs', 14);
k.num(s.c.tok);
k.w(')"/>', 4);
if (glint) {
k.w('<rect x="', 9);
k.num(x);
k.w('" y="0" width="1" height="1"', 28);
k.w(' fill="', 7);
k.hex6(s.wt[2]);
k.w('" fill-opacity=".4"/><rect', 26);
k.w(' class="cgl" style="', 20);
_cyc(s, k, Fixed.TWO_PI / 3, (Fixed.PI - 13 * X / 10 - s.sw) / 3);
k.w('" x="', 5);
k.num(x);
k.w('" y="0" width="1" height="1"', 28);
k.w(' fill="', 7);
k.hex6(s.wt[3]);
k.w('"/>', 3);
}
if (s.chop >= 50) k.w("</g>", 4);
}
return k.close();
}
}
function _sea(S memory s, R memory r, Ink memory k, bytes memory rise, bytes memory he) internal pure {
unchecked {
uint256 tok = s.c.tok;
bytes memory cols = _columns(s, true);
k.w('<g style="opacity:0;animation:', 30);
k.put(he);
k.w('">', 2);
for (uint256 i = 0; i < 3; i++) {
if (i == 2 && _eyeCount(r) == 0) break;
k.w('<g clip-path="url(#c', 20);
k.ch(i == 0 ? 0x67 : i == 1 ? 0x66 : 0x65);
k.num(tok);
// forge-lint: disable-next-line(unsafe-typecast)
k.w(
i == 0
? bytes32(')" opacity=".95">')
: i == 1 ? bytes32(')" opacity=".62">') : bytes32(')" opacity=".28">'),
17
);
k.put(bytes('<g style="transform:translateY(25px);animation:'));
k.put(rise);
k.w('">', 2);
k.put(i == 2 ? _columns(s, false) : cols);
k.w("</g></g>", 8);
}
k.w("</g>", 4);
}
}
function _bubbles(S memory s, R memory r, Ink memory k, bytes memory ue) internal pure {
unchecked {
uint256 Z = s.c.Z;
uint256 cnt = r.nb == 0 ? 1 : r.nb;
// forge-lint: disable-next-line(unsafe-typecast)
int256 cx = int256(r.sx) * W / int256(cnt);
// forge-lint: disable-next-line(unsafe-typecast)
int256 span = int256(r.x1) - int256(r.x0) + 4;
k.w('<g clip-path="url(#cg', 21);
k.num(s.c.tok);
k.w(')" fill="', 9);
k.hex6(s.wt[4]);
k.w('" style="opacity:0;animation:', 29);
k.put(ue);
k.w('">', 2);
for (uint256 b = 0; b < 10; b++) {
int256 per = 18 * W / 10 + _f(_h2(b, Z + 3), 16 * W / 10);
int256 v0 = _f(_h2(b, Z + 4), W);
int256 bx = cx + (_f(_h2(b, Z + 5), W) - HALF) * span;
// forge-lint: disable-next-line(unsafe-typecast)
int256 ang = int256(b) * W;
k.w('<rect class="cb" x="', 20);
_dec(k, bx, 3);
k.w('" y="0" width="1" height="1" st', 31);
k.w('yle="--c:', 9);
_dec(k, Fixed.cos(ang) / 2, 3);
k.w(";--s:", 5);
_dec(k, Fixed.sin(ang) / 2, 3);
k.w(";--p:", 5);
_dec(k, per, 3);
k.w("s;--d:-", 7);
_dec(k, _mod(v0 * per / W - s.c.s0, per), 2);
k.w('s"/>', 4);
}
k.w("</g>", 4);
}
}
function _eyes(S memory s, R memory r, Ink memory k, bytes memory ue) internal pure {
unchecked {
if (_eyeCount(r) == 0) return;
k.w('<g style="opacity:0;animation:', 30);
k.put(ue);
k.w('">', 2);
for (uint256 p = 0; p < 576; p++) {
if (r.own[p] != 4) continue;
// forge-lint: disable-next-line(unsafe-typecast)
int256 ph = (8 * int256(p % 24) * W / 10 + int256(p / 24) * W) * 10 / 15;
k.w('<path class="vs" style="', 24);
_cyc(s, k, Fixed.TWO_PI * 10 / 15, ph);
k.w('" fill="', 8);
_hex(k, _wcol(s, p / 24));
k.w('" fill-opacity=".16" d="', 24);
_px(k, p);
k.w('"/>', 3);
}
k.w("</g>", 4);
}
}
function _tenth(S memory s, int256 u) internal pure returns (uint256) {
unchecked {
// forge-lint: disable-next-line(unsafe-typecast)
return uint256((_at(s.c, u) * 10 + HALF) / W) % 2000;
}
}
function _seen(uint256[8] memory bits, uint256 v) internal pure returns (bool) {
unchecked {
// forge-lint: disable-next-line(incorrect-shift)
bool was = bits[v >> 8] & (1 << (v & 255)) != 0;
// forge-lint: disable-next-line(incorrect-shift)
bits[v >> 8] |= 1 << (v & 255);
return was;
}
}
function _ghost(S memory s, R memory r, Ink memory st, Ink memory k) internal pure {
unchecked {
uint256 Z = s.c.Z;
uint256[8] memory sn;
uint256[8] memory sf;
uint256[] memory ln = new uint256[](576);
uint256[] memory lf = new uint256[](576);
uint256 nn;
uint256 nf;
for (uint256 i = 0; i < r.nb; i++) {
uint256 p = r.body[i];
int256 d = r.d[p];
int256[3] memory hue = _cw(r.rgb[p]);
int256[3] memory gr = _lerp(hue, _wcol(s, p / 24), 62e16);
uint256 a = _tenth(s, 25e17 + d * 14 * W / 100 + _f(_h2(p, Z), 6e17));
uint256 b = _tenth(s, s.c.end + (20 - d) * 5 * W / 100 + _f(_h2(p, Z + 1), W / 2));
if (!_seen(sn, a)) ln[nn++] = a;
if (!_seen(sf, b)) lf[nf++] = b;
k.w('<g class="g cn', 14);
k.num(a);
k.w(" cf", 3);
k.num(b);
k.w('">', 2);
// forge-lint: disable-next-line(unsafe-typecast)
int256 ip = int256(p) * W;
if (r.reef[p]) {
int256 w = s.pulse * (14 * W / 10 + _f(_h2(p, Z + 7), 16 * W / 10)) / W;
int256[3] memory mid = _lerp(gr, hue, 85e16);
_cell(k, p, _lerp(mid, _bright(hue), 35e16), 0, 0, 0, 0);
_cell(k, p, _lerp(mid, _bright(hue), 8e17), 1, s.c.s0, Fixed.TWO_PI * W / w, 7 * ip / 10 * W / w);
} else {
uint256 v = r.rgb[p];
uint256 sum = (v >> 16) + ((v >> 8) & 255) + (v & 255);
int256[3] memory glow = _cw(s.wt[5]);
if (r.edge[p] || sum * 100 > 72 * 765) {
_cell(k, p, _lerp(gr, glow, 36e16), 0, 0, 0, 0);
_cell(k, p, _lerp(gr, glow, 6e17), 1, s.c.s0, Fixed.TWO_PI, ip);
} else {
_cell(k, p, _lerp(gr, hue, 14e16), 0, 0, 0, 0);
}
if (_h2(p, Z + 3100) * 100 > 92 * 4294967296) {
int256 w = 13 * W / 10 + _f(_h2(p, 9), 25 * W / 10);
k.put(bytes('<path fill="#fffcfa" opacity=".075" d="'));
_px(k, p);
k.w('"/><g opacity=".675">', 21);
_cell(k, p, [255 * W, 252 * W, 250 * W], 1, s.c.s0, Fixed.TWO_PI * W / w, ip * W / w);
k.w("</g>", 4);
}
}
k.w("</g>", 4);
}
for (uint256 i = 0; i < nn; i++) {
st.w(".cn", 3);
st.num(ln[i]);
st.w("{--n:-", 6);
// forge-lint: disable-next-line(unsafe-typecast)
_dec(st, int256(ln[i]) * W / 10, 1);
st.w("s}", 2);
}
for (uint256 i = 0; i < nf; i++) {
st.w(".cf", 3);
st.num(lf[i]);
st.w("{--f:-", 6);
// forge-lint: disable-next-line(unsafe-typecast)
_dec(st, int256(lf[i]) * W / 10, 1);
st.w("s}", 2);
}
}
}
function _cell(Ink memory k, uint256 p, int256[3] memory c, uint256 kind, int256 s0, int256 per, int256 phase)
internal
pure
{
unchecked {
if (kind == 0) {
k.w('<path fill="', 12);
} else {
k.w('<path class="vs" style="--p:', 28);
_dec(k, per, 3);
k.w("s;--d:-", 7);
_dec(k, _mod(phase - s0, per), 2);
k.w('s" fill="', 9);
}
_hex(k, c);
k.w('" d="', 5);
_px(k, p);
k.w('"/>', 3);
}
}
function _reef(S memory s, R memory r, Ink memory st, Ink memory k) internal pure {
unchecked {
if (r.nr == 0) return;
int256 end = s.c.end;
_pt(s, 2 * W - W / 100, 0);
_ramp(s, 2 * W, 4 * W, true);
_ramp(s, end, end + 3 * W, false);
_pt(s, end + 301e16, 0);
bytes memory anim = _kf(s, st, "ck", false, false);
k.w('<g style="opacity:0;animation:', 30);
k.put(anim);
k.w('">', 2);
for (uint256 i = 0; i < r.nr; i++) {
uint256 p = r.reefs[i];
Ink memory c = Pen.open(8);
_hex(c, _bright(_cw(r.rgb[p])));
bytes memory hx = c.close();
k.w('<path fill="', 12);
k.put(hx);
k.w('" fill-opacity=".5" d="', 23);
_px(k, p);
k.w('"/><path class="vs" style="', 27);
// forge-lint: disable-next-line(unsafe-typecast)
_cyc(s, k, Fixed.PI, 7 * int256(p) * W / 20 + s.c.sea0);
k.w('" fill="', 8);
k.put(hx);
k.w('" fill-opacity=".8" d="', 23);
_px(k, p);
k.w('"/>', 3);
}
k.w("</g>", 4);
}
}
function _drain(S memory s, R memory r, Ink memory st, Ink memory k) internal view {
unchecked {
int256 end = s.c.end;
uint256 Z = s.c.Z;
_pt(s, end + 14 * W / 10 - W / 100, 0);
_ramp(s, end + 14 * W / 10, end + 22 * W / 10, true);
_ramp(s, end + 46 * W / 10, end + 62 * W / 10, false);
_pt(s, end + 621e16, 0);
bytes memory anim = _kf(s, st, "cd", false, false);
k.w('<g style="opacity:0;animation:', 30);
k.put(anim);
k.w('"><path fill="', 14);
_hex(k, _lerp(s.top, _cw(s.wt[2]), 4e17));
k.w('" fill-opacity=".16" d="', 24);
_runs(k, r, 3);
k.w('"/>', 3);
for (uint256 i = 0; i < r.nb; i++) {
uint256 p = r.body[i];
if (_h2(p, Z + 41) * 100 <= 93 * 4294967296) continue;
k.w('<path class="vs" style="', 24);
// forge-lint: disable-next-line(unsafe-typecast)
_cyc(s, k, Fixed.TWO_PI / 4, int256(p) * W / 4);
k.w('" fill="', 8);
k.hex6(s.wt[3]);
k.w('" fill-opacity=".35" d="', 24);
_px(k, p);
k.w('"/>', 3);
}
k.w("</g>", 4);
k.put(drip.drops(s.c.tok, s.own, s.rgb, s.water, s.band));
}
}
}
src/PictureV6Kit.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Ink, Pen, Fixed} from "./Strokes.sol";
/// @title ArgonautsPictureV6Kit
abstract contract ArgonautsPictureV6Kit {
using Pen for Ink;
int256 internal constant W = 1e18;
int256 internal constant HALF = 5e17;
int256 internal constant LOOP = 200e18;
int256 internal constant PH = 4e16;
uint256 internal constant M32 = 0xFFFFFFFF;
struct R {
uint8[576] own;
uint256[576] rgb;
uint256[] body;
uint256 nb;
bool[576] edge;
uint256[] edges;
uint256 ne;
bool[576] reef;
uint256[] reefs;
uint256 nr;
uint256[24] top;
int256[576] d;
uint256 x0;
uint256 x1;
uint256 y0;
uint256 y1;
uint256 sx;
uint256 sy;
uint256 run;
}
struct C {
uint256 tok;
uint256 Z;
int256 hold;
int256 end;
int256 sea0;
int256 s0;
}
function _mark() internal pure returns (uint256 m) {
assembly ("memory-safe") {
m := mload(0x40)
}
}
function _free(uint256 m) internal pure {
assembly {
mstore(0x40, m)
}
}
function _h2(uint256 a, uint256 b) internal pure returns (uint256 h) {
unchecked {
h = ((a * 0x9E3779B1) & M32) ^ (((b + 0x632BE5AB) * 0x85EBCA77) & M32);
h ^= h >> 16;
h = (h * 0x7FEB352D) & M32;
h ^= h >> 15;
}
}
function _f(uint256 h, int256 x) internal pure returns (int256) {
unchecked {
// forge-lint: disable-next-line(unsafe-typecast)
return int256((h * uint256(x)) >> 32);
}
}
function _fi(uint256 h, uint256 n) internal pure returns (uint256) {
unchecked {
return (h * n) >> 32;
}
}
function _lt(uint256 h, uint256 num, uint256 den) internal pure returns (bool) {
unchecked {
return h * den < num * 4294967296;
}
}
function _mod(int256 a, int256 m) internal pure returns (int256 r) {
unchecked {
r = a % m;
if (r < 0) r += m;
}
}
function _cl(int256 v) internal pure returns (int256) {
unchecked {
return v < 0 ? int256(0) : v > W ? W : v;
}
}
function _sm(int256 v) internal pure returns (int256) {
v = _cl(v);
unchecked {
return v * v / W * (3 * W - 2 * v) / W;
}
}
function _floorI(int256 x) internal pure returns (int256 q) {
assembly {
q := sdiv(x, W)
if and(slt(x, 0), iszero(iszero(smod(x, W)))) { q := sub(q, 1) }
}
}
function _roundI(int256 x) internal pure returns (int256 q) {
assembly {
x := add(x, HALF)
q := sdiv(x, W)
if and(slt(x, 0), iszero(iszero(smod(x, W)))) { q := sub(q, 1) }
}
}
function _ceilI(int256 x) internal pure returns (int256) {
unchecked {
return -_floorI(-x);
}
}
function _sqrtW(int256 v) internal pure returns (int256) {
unchecked {
// forge-lint: disable-next-line(unsafe-typecast)
uint256 n = uint256(v) * uint256(W);
if (n < 2) return int256(n);
uint256 t = n;
uint256 x = 2;
if (t >= 1 << 128) {
t >>= 128;
x <<= 64;
}
if (t >= 1 << 64) {
t >>= 64;
x <<= 32;
}
if (t >= 1 << 32) {
t >>= 32;
x <<= 16;
}
if (t >= 1 << 16) {
t >>= 16;
x <<= 8;
}
if (t >= 1 << 8) {
t >>= 8;
x <<= 4;
}
if (t >= 1 << 4) {
t >>= 4;
x <<= 2;
}
if (t >= 1 << 2) x <<= 1;
uint256 y = (x + n / x) / 2;
while (y < x) {
x = y;
y = (x + n / x) / 2;
}
// forge-lint: disable-next-line(unsafe-typecast)
return int256(x);
}
}
function _dec(Ink memory k, int256 v, uint256 places) internal pure {
assembly ("memory-safe") {
function wnum(at, n) -> e {
let l := 1
for { let t := n } gt(t, 9) {} {
t := div(t, 10)
l := add(l, 1)
}
e := add(at, l)
let q := e
for {} 1 {} {
q := sub(q, 1)
mstore8(q, add(48, mod(n, 10)))
n := div(n, 10)
if iszero(n) { break }
}
}
let at := mload(k)
if slt(v, 0) {
mstore8(at, 0x2d)
at := add(at, 1)
v := sub(0, v)
}
let p := exp(10, places)
let q := div(add(mul(v, p), HALF), W)
let whole := div(q, p)
let fr := mod(q, p)
if or(iszero(fr), iszero(iszero(whole))) { at := wnum(at, whole) }
if fr {
mstore8(at, 0x2e)
at := add(at, 1)
let d := div(p, 10)
for {} fr {} {
mstore8(at, add(48, div(fr, d)))
at := add(at, 1)
fr := mod(fr, d)
d := div(d, 10)
}
}
mstore(k, at)
}
}
function _pct(Ink memory k, int256 u) internal pure {
unchecked {
_dec(k, u * 100 / 200, 4);
k.ch(0x25);
}
}
function _hex(Ink memory k, int256[3] memory c) internal pure {
unchecked {
uint256 rgb;
for (uint256 i = 0; i < 3; i++) {
int256 q = _roundI(c[i]);
if (q < 0) q = 0;
if (q > 255) q = 255;
// forge-lint: disable-next-line(unsafe-typecast)
rgb = (rgb << 8) | uint256(q);
}
k.hex6(rgb);
}
}
function _pack(int256[3] memory c) internal pure returns (uint256 rgb) {
unchecked {
for (uint256 i = 0; i < 3; i++) {
int256 q = _roundI(c[i]);
if (q < 0) q = 0;
if (q > 255) q = 255;
// forge-lint: disable-next-line(unsafe-typecast)
rgb = (rgb << 8) | uint256(q);
}
}
}
function _px(Ink memory k, uint256 p) internal pure {
unchecked {
k.ch(0x4d);
k.num(p % 24);
k.ch(0x20);
k.num(p / 24);
k.w("h1v1h-1z", 8);
}
}
function _lerp(int256[3] memory a, int256[3] memory b, int256 f) internal pure returns (int256[3] memory o) {
unchecked {
for (uint256 i = 0; i < 3; i++) {
o[i] = a[i] + (b[i] - a[i]) * f / W;
}
}
}
function _cw(uint256 v) internal pure returns (int256[3] memory o) {
unchecked {
// forge-lint: disable-next-line(unsafe-typecast)
o = [int256(v >> 16) * W, int256((v >> 8) & 255) * W, int256(v & 255) * W];
}
}
function _min255(int256 v) internal pure returns (int256) {
unchecked {
return v > 255 * W ? 255 * W : v;
}
}
function _bright(int256[3] memory c) internal pure returns (int256[3] memory) {
unchecked {
return
[_min255(c[0] * 14 / 10 + 30 * W), _min255(c[1] * 14 / 10 + 30 * W), _min255(c[2] * 14 / 10 + 40 * W)];
}
}
function _water(uint256 w) internal pure returns (uint256[6] memory c, int256 chop) {
unchecked {
if (w == 1) return ([uint256(0x080c1a), 0x000106, 0x28466e, 0x78a0d2, 0x78aadc, 0x96dcff], 35);
if (w == 2) return ([uint256(0x460e20), 0x240612, 0xf09c84, 0xffdece, 0xffdece, 0xffd6d2], 45);
if (w == 3) return ([uint256(0x2c3e46), 0x0a121a, 0x96aab4, 0xe2ecf0, 0xd2e2ec, 0xc8e2f0], 120);
return ([uint256(0x103a52), 0x030e20, 0x78c8e4, 0xdcf8ff, 0xc8f0ff, 0xbeeeff], 45);
}
}
function _clock(uint256 tok, bool band) internal pure returns (C memory c) {
unchecked {
c.tok = tok;
c.Z = tok * 7919;
c.hold = 40 * W + _f(_h2(tok, 77), 20 * W);
c.end = c.hold + W;
c.sea0 = band ? 4 * W : int256(0);
c.s0 = _f(_h2(tok, 1201), 180 * W) + c.sea0;
}
}
function _at(C memory c, int256 u) internal pure returns (int256) {
unchecked {
return _mod(-(c.s0 + u), LOOP);
}
}
function _fig(R memory r, int256 p) internal pure returns (bool) {
unchecked {
// forge-lint: disable-next-line(unsafe-typecast)
return p >= 0 && p < 576 && r.own[uint256(p)] != 0;
}
}
function _shape(uint8[576] calldata own, uint256[576] calldata rgb) internal pure returns (R memory r) {
unchecked {
r.body = new uint256[](576);
r.edges = new uint256[](576);
r.reefs = new uint256[](576);
r.x0 = 24;
r.y0 = 24;
for (uint256 p = 0; p < 576; p++) {
r.own[p] = own[p];
r.rgb[p] = rgb[p];
if (own[p] != 1) continue;
uint256 x = p % 24;
uint256 y = p / 24;
r.body[r.nb++] = p;
r.sx += x;
r.sy += y;
if (x < r.x0) r.x0 = x;
if (x > r.x1) r.x1 = x;
if (y < r.y0) r.y0 = y;
if (y > r.y1) r.y1 = y;
}
for (uint256 i = 0; i < r.nb; i++) {
uint256 p = r.body[i];
// forge-lint: disable-next-line(unsafe-typecast)
int256 q = int256(p);
if (!_fig(r, q - 1) || !_fig(r, q + 1) || !_fig(r, q - 24) || (p < 552 && !_fig(r, q + 24))) {
r.edge[p] = true;
r.edges[r.ne++] = p;
}
uint256 v = rgb[p];
uint256 cr = v >> 16;
uint256 cg = (v >> 8) & 255;
uint256 cb = v & 255;
uint256 mx = cr > cg ? (cr > cb ? cr : cb) : (cg > cb ? cg : cb);
uint256 mn = cr < cg ? (cr < cb ? cr : cb) : (cg < cb ? cg : cb);
uint256 d = mx - mn;
if (d < 40) continue;
bool tan = mx == cr && cg >= cb && 14 * d <= 60 * (cg - cb) && 60 * (cg - cb) <= 52 * d;
if (!tan) {
r.reef[p] = true;
r.reefs[r.nr++] = p;
}
}
for (uint256 x = 0; x < 24; x++) {
r.top[x] = 24;
for (uint256 y = 0; y < 24; y++) {
uint256 p = y * 24 + x;
if (own[p] != 0 && own[p] != 4) {
r.top[x] = y;
break;
}
}
}
_depth(r);
}
}
function _depth(R memory r) internal pure {
unchecked {
uint256[] memory q = new uint256[](576);
uint256 n;
for (uint256 p = 0; p < 576; p++) {
r.d[p] = -1;
}
for (uint256 i = 0; i < r.nb; i++) {
uint256 p = r.body[i];
// forge-lint: disable-next-line(unsafe-typecast)
if (!_fig(r, int256(p) - 24) && p / 24 <= r.y0 + 2) {
r.d[p] = 0;
q[n++] = p;
}
}
if (n == 0 && r.nb != 0) {
r.d[r.body[0]] = 0;
q[n++] = r.body[0];
}
int256[8] memory ks = [int256(-1), 1, -24, 24, -25, -23, 23, 25];
for (uint256 i = 0; i < n; i++) {
uint256 p0 = q[i];
for (uint256 j = 0; j < 8; j++) {
// forge-lint: disable-next-line(unsafe-typecast)
int256 m = int256(p0) + ks[j];
if (m < 0 || m > 575) continue;
// forge-lint: disable-next-line(unsafe-typecast)
uint256 um = uint256(m);
if (r.own[um] != 1 || r.d[um] != -1) continue;
if ((um % 24 > p0 % 24 ? um % 24 - p0 % 24 : p0 % 24 - um % 24) > 1) continue;
r.d[um] = r.d[p0] + 1;
q[n++] = um;
}
}
for (uint256 i = 0; i < r.nb; i++) {
if (r.d[r.body[i]] == -1) r.d[r.body[i]] = 20;
}
}
}
function _put(Ink memory k, R memory r, int256 x, int256 y, uint256 c, int256 a, bool behind) internal pure {
x = _roundI(x);
y = _roundI(y);
if (x < 0 || y < 0 || x > 23 || y > 23 || a <= 0) return;
uint256 q;
unchecked {
// forge-lint: disable-next-line(unsafe-typecast)
q = uint256(y * 24 + x);
}
uint8 o = r.own[q];
if (o == 4 || (behind && o != 0)) return;
if (a > W) a = W;
if (r.run != c | (1 << 24)) {
if (r.run != 0) k.w("</g>", 4);
k.w('<g fill="', 9);
k.hex6(c);
k.w('">', 2);
r.run = c | (1 << 24);
}
assembly ("memory-safe") {
function wnum(at, n) -> e {
switch lt(n, 10)
case 1 {
mstore8(at, add(48, n))
e := add(at, 1)
}
default {
mstore8(at, add(48, div(n, 10)))
mstore8(add(at, 1), add(48, mod(n, 10)))
e := add(at, 2)
}
}
let at := mload(k)
mstore(at, '<path opacity="')
at := add(at, 15)
let v := div(add(mul(a, 1000), HALF), W)
let fr := mod(v, 1000)
switch fr
case 0 {
mstore8(at, add(48, div(v, 1000)))
at := add(at, 1)
}
default {
if iszero(lt(v, 1000)) {
mstore8(at, 49)
at := add(at, 1)
}
mstore8(at, 0x2e)
at := add(at, 1)
let d := 100
for {} fr {} {
mstore8(at, add(48, div(fr, d)))
at := add(at, 1)
fr := mod(fr, d)
d := div(d, 10)
}
}
mstore(at, '" d="M')
at := wnum(add(at, 6), x)
mstore8(at, 0x20)
at := wnum(add(at, 1), y)
mstore(at, 'h1v1h-1"/>')
mstore(k, add(at, 10))
}
}
function _dot(Ink memory k, R memory r, int256 x, int256 y, uint256 c, int256 a, bool behind) internal pure {
unchecked {
int256 x0 = _floorI(x);
int256 y0 = _floorI(y);
int256 fx = x - x0 * W;
int256 fy = y - y0 * W;
_put(k, r, x0 * W, y0 * W, c, a * (W - fx) / W * (W - fy) / W * 115 / 100, behind);
_put(k, r, (x0 + 1) * W, y0 * W, c, a * fx / W * (W - fy) / W * 115 / 100, behind);
_put(k, r, x0 * W, (y0 + 1) * W, c, a * (W - fx) / W * fy / W * 115 / 100, behind);
_put(k, r, (x0 + 1) * W, (y0 + 1) * W, c, a * fx / W * fy / W * 115 / 100, behind);
}
}
function _frame(Ink memory o, Ink memory cells, C memory c, int256 u, R memory r) internal pure {
unchecked {
if (cells.at == cells.from) return;
if (r.run != 0) {
cells.w("</g>", 4);
r.run = 0;
}
o.w('<g class="vw" style="--t:-', 26);
_dec(o, _at(c, u), 1);
o.w('s">', 3);
o.put(cells.close());
o.w("</g>", 4);
cells.at = cells.from;
}
}
}
src/Strokes.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
struct Ink {
uint256 at;
uint256 from;
uint256 cap;
}
library Pen {
error TooLong();
function open(uint256 cap) internal pure returns (Ink memory k) {
bytes memory b = new bytes(cap + 32);
uint256 at;
assembly ("memory-safe") {
at := add(b, 32)
}
k.at = at;
k.from = at;
k.cap = cap;
}
function put(Ink memory k, bytes memory s) internal pure {
assembly ("memory-safe") {
let n := mload(s)
let at := mload(k)
mcopy(at, add(s, 32), n)
mstore(k, add(at, n))
}
}
function w(Ink memory k, bytes32 s, uint256 n) internal pure {
assembly ("memory-safe") {
let at := mload(k)
mstore(at, s)
mstore(k, add(at, n))
}
}
function ch(Ink memory k, uint256 c) internal pure {
assembly ("memory-safe") {
let at := mload(k)
mstore8(at, c)
mstore(k, add(at, 1))
}
}
function num(Ink memory k, uint256 v) internal pure {
assembly ("memory-safe") {
let at := mload(k)
switch lt(v, 10)
case 1 {
mstore8(at, add(48, v))
mstore(k, add(at, 1))
}
default {
switch lt(v, 100)
case 1 {
mstore8(at, add(48, div(v, 10)))
mstore8(add(at, 1), add(48, mod(v, 10)))
mstore(k, add(at, 2))
}
default {
let n := 1
for { let t := v } gt(t, 9) {} {
t := div(t, 10)
n := add(n, 1)
}
let p := add(at, n)
mstore(k, p)
for {} 1 {} {
p := sub(p, 1)
mstore8(p, add(48, mod(v, 10)))
v := div(v, 10)
if iszero(v) { break }
}
}
}
}
}
function sint(Ink memory k, int256 v) internal pure {
if (v < 0) {
ch(k, 0x2d);
// forge-lint: disable-next-line(unsafe-typecast)
num(k, uint256(-v));
} else {
// forge-lint: disable-next-line(unsafe-typecast)
num(k, uint256(v));
}
}
function hex6(Ink memory k, uint256 rgb) internal pure {
assembly ("memory-safe") {
let at := mload(k)
mstore8(at, 0x23)
let n := and(shr(20, rgb), 15)
mstore8(add(at, 1), add(add(n, 48), mul(39, gt(n, 9))))
n := and(shr(16, rgb), 15)
mstore8(add(at, 2), add(add(n, 48), mul(39, gt(n, 9))))
n := and(shr(12, rgb), 15)
mstore8(add(at, 3), add(add(n, 48), mul(39, gt(n, 9))))
n := and(shr(8, rgb), 15)
mstore8(add(at, 4), add(add(n, 48), mul(39, gt(n, 9))))
n := and(shr(4, rgb), 15)
mstore8(add(at, 5), add(add(n, 48), mul(39, gt(n, 9))))
n := and(rgb, 15)
mstore8(add(at, 6), add(add(n, 48), mul(39, gt(n, 9))))
mstore(k, add(at, 7))
}
}
function op(Ink memory k, uint256 v) internal pure {
assembly ("memory-safe") {
let at := mload(k)
switch iszero(v)
case 1 {
mstore8(at, 48)
at := add(at, 1)
}
default {
switch lt(v, 1000)
case 0 {
mstore8(at, 49)
at := add(at, 1)
}
default {
mstore8(at, 46)
mstore8(add(at, 1), add(48, div(v, 100)))
at := add(at, 2)
let r := mod(v, 100)
if r {
mstore8(at, add(48, div(r, 10)))
at := add(at, 1)
r := mod(r, 10)
if r {
mstore8(at, add(48, r))
at := add(at, 1)
}
}
}
}
mstore(k, at)
}
}
function secs(Ink memory k, uint256 steps) internal pure {
num(k, steps / 10);
uint256 r = steps % 10;
if (r != 0) {
ch(k, 0x2e);
ch(k, 48 + r);
}
ch(k, 0x73);
}
function close(Ink memory k) internal pure returns (bytes memory b) {
uint256 used = k.at - k.from;
if (used > k.cap) revert TooLong();
uint256 from = k.from;
assembly ("memory-safe") {
b := sub(from, 32)
mstore(b, used)
}
}
}
library Fixed {
int256 internal constant WAD = 1e18;
int256 internal constant HALF = 5e17;
int256 internal constant PI = 3141592653589793238;
int256 internal constant TWO_PI = 6283185307179586476;
int256 internal constant HALF_PI = 1570796326794896619;
function sin(int256 x) internal pure returns (int256) {
unchecked {
x = x % TWO_PI;
if (x < 0) x += TWO_PI;
bool neg;
if (x >= PI) {
x -= PI;
neg = true;
}
if (x > HALF_PI) x = PI - x;
int256 x2 = x * x / WAD;
int256 term = x;
int256 sum = x;
term = term * x2 / WAD / 6;
sum -= term;
term = term * x2 / WAD / 20;
sum += term;
term = term * x2 / WAD / 42;
sum -= term;
term = term * x2 / WAD / 72;
sum += term;
term = term * x2 / WAD / 110;
sum -= term;
term = term * x2 / WAD / 156;
sum += term;
return neg ? -sum : sum;
}
}
function cos(int256 x) internal pure returns (int256) {
return sin(x + HALF_PI);
}
function round(int256 x) internal pure returns (int256 q) {
unchecked {
int256 v = x + HALF;
q = v / WAD;
if (v < 0 && v % WAD != 0) q -= 1;
}
}
function op(int256 x) internal pure returns (uint256 k) {
unchecked {
if (x <= 0) return 0;
// forge-lint: disable-next-line(unsafe-typecast)
k = uint256((x * 1000 + HALF) / WAD);
if (k > 1000) k = 1000;
}
}
}
struct Card {
uint256 tok;
uint8[7] t;
uint256[576] px;
uint256[128] x;
uint256[] eyes;
uint256[] lens;
uint256[] red;
uint256[] blue;
uint256[] screen;
uint256[] body;
uint256[] head;
uint256[] halo;
uint256[] led;
uint256[] smoke;
uint256[] petals;
uint256[] polyps;
uint256[] glints;
uint256[] crown;
uint256 smokeRGB;
bool dragon;
int256 tempo;
int256 tb0;
int256 pv;
}
struct Wisps {
uint256 nw;
uint256[] full;
uint256[] half;
int256[] dx;
uint256[] dy;
uint256 any1;
uint256 any2;
}
struct Light {
uint256[] mask;
uint256 count;
uint256 cycle;
bool own;
uint256 loop;
uint256 colour;
int256 amount;
int256 rise;
int256 fall;
uint256 mulC;
uint256 mulS;
uint256 add;
uint256 mod;
}
/// @title Strokes
abstract contract Strokes {
using Pen for Ink;
int256 internal constant WAD = 1e18;
uint256 internal constant RGB = 0xFFFFFF;
uint256 internal constant SMK = 1 << 27;
uint256 internal constant RED = 1 << 28;
uint256 internal constant BLUE = 1 << 29;
uint256 internal constant GROUND = 0;
uint256 internal constant BODY = 1;
uint256 internal constant CLOAK = 2;
uint256 internal constant EYES = 4;
uint256 internal constant MOUTH = 5;
uint256 internal constant HEAD = 6;
uint256 internal constant SMOKE = 7;
function _mark() internal pure returns (uint256 m) {
assembly ("memory-safe") {
m := mload(0x40)
}
}
function _free(uint256 m) internal pure {
assembly {
mstore(0x40, m)
}
}
function _own(uint256 v) internal pure returns (uint256) {
return (v >> 24) & 7;
}
function _chroma(uint256 c) internal pure returns (uint256) {
unchecked {
uint256 r = (c >> 16) & 255;
uint256 g = (c >> 8) & 255;
uint256 b = c & 255;
uint256 mx = r > g ? r : g;
if (b > mx) mx = b;
uint256 mn = r < g ? r : g;
if (b < mn) mn = b;
return mx - mn;
}
}
function _top(uint256 c) internal pure returns (uint256 mx) {
uint256 r = (c >> 16) & 255;
uint256 g = (c >> 8) & 255;
uint256 b = c & 255;
mx = r > g ? r : g;
if (b > mx) mx = b;
}
function _lum(uint256 c) internal pure returns (uint256) {
unchecked {
return 299 * ((c >> 16) & 255) + 587 * ((c >> 8) & 255) + 114 * (c & 255);
}
}
function _trim(uint256[] memory a, uint256 n) internal pure {
assembly ("memory-safe") {
mstore(a, n)
}
}
function _sw(Card memory c, uint256 i) internal pure returns (int256) {
// forge-lint: disable-next-line(unsafe-typecast)
return int256((c.x[i] * 1e18) >> 32);
}
function _steps(Card memory c, uint256 p10) internal pure returns (uint256 n) {
unchecked {
// forge-lint: disable-next-line(unsafe-typecast)
n = uint256((int256(p10) * WAD * 2 + c.tempo) / (2 * c.tempo));
if (n < 2) n = 2;
}
}
function _from(Card memory c, uint256 p10) internal pure returns (int256) {
unchecked {
// forge-lint: disable-next-line(unsafe-typecast)
return (c.tb0 * 10 / int256(p10)) % WAD;
}
}
function _at(int256 from, uint256 i, uint256 n) internal pure returns (int256) {
unchecked {
// forge-lint: disable-next-line(unsafe-typecast)
return (from + WAD * int256(i) / int256(n)) % WAD;
}
}
function _ch(uint256 v, uint256 a, uint256 b) internal pure returns (uint256 o) {
unchecked {
o = (v * a + b * 100 + 50) / 100;
if (o > 255) o = 255;
}
}
function _scaled(uint256 rgb, uint256 a, uint256 b) internal pure returns (uint256) {
return (_ch(rgb >> 16, a, b) << 16) | (_ch((rgb >> 8) & 255, a, b) << 8) | _ch(rgb & 255, a, b);
}
function _flat(uint256 n, uint256 colour) internal pure returns (uint256[] memory out) {
unchecked {
out = new uint256[](n);
for (uint256 i = 0; i < n; i++) {
out[i] = colour;
}
}
}
function _tint(Card memory c, uint256[] memory pxs, uint256 a, uint256 b)
internal
pure
returns (uint256[] memory out)
{
unchecked {
out = new uint256[](pxs.length);
for (uint256 i = 0; i < pxs.length; i++) {
out[i] = _scaled(c.px[pxs[i]] & RGB, a, b);
}
}
}
function _any(uint256[] memory v) internal pure returns (bool) {
unchecked {
for (uint256 i = 0; i < v.length; i++) {
if (v[i] != 0) return true;
}
return false;
}
}
function _anim(
Ink memory k,
bytes32 attr,
uint256 attrLen,
uint256[] memory v,
uint256 steps,
uint256 shift,
bool raw
) internal pure {
unchecked {
k.w('<animate attributeName="', 24);
k.w(attr, attrLen);
k.w('" values="', 10);
_vals(k, v, raw);
k.w('" dur="', 7);
k.secs(steps);
k.ch(0x22);
if (shift != 0) {
k.w(' begin="-', 9);
k.secs(shift);
k.ch(0x22);
}
k.w(' calcMode="discrete" repeatCount', 32);
k.w('="indefinite"/>', 15);
}
}
function _vals(Ink memory k, uint256[] memory v, bool raw) internal pure {
assembly ("memory-safe") {
let at := mload(k)
let n := mload(v)
let p := add(v, 32)
for { let i := 0 } lt(i, n) { i := add(i, 1) } {
if i {
mstore8(at, 0x3b)
at := add(at, 1)
}
let x := mload(add(p, shl(5, i)))
switch raw
case 0 {
switch iszero(x)
case 1 {
mstore8(at, 48)
at := add(at, 1)
}
default {
switch lt(x, 1000)
case 0 {
mstore8(at, 49)
at := add(at, 1)
}
default {
mstore8(at, 46)
mstore8(add(at, 1), add(48, div(x, 100)))
at := add(at, 2)
let r := mod(x, 100)
if r {
mstore8(at, add(48, div(r, 10)))
at := add(at, 1)
r := mod(r, 10)
if r {
mstore8(at, add(48, r))
at := add(at, 1)
}
}
}
}
}
default {
if gt(x, 99) {
mstore8(at, add(48, div(x, 100)))
at := add(at, 1)
x := mod(x, 100)
mstore8(at, add(48, div(x, 10)))
at := add(at, 1)
x := mod(x, 10)
}
if gt(x, 9) {
mstore8(at, add(48, div(x, 10)))
at := add(at, 1)
x := mod(x, 10)
}
mstore8(at, add(48, x))
at := add(at, 1)
}
}
mstore(k, at)
}
}
function _run(Ink memory k, uint256 x, uint256 y, uint256 n) internal pure {
assembly ("memory-safe") {
function d(at, v) -> to {
to := at
if gt(v, 9) {
mstore8(to, add(48, div(v, 10)))
to := add(to, 1)
}
mstore8(to, add(48, mod(v, 10)))
to := add(to, 1)
}
let at := mload(k)
mstore8(at, 0x4d)
at := d(add(at, 1), x)
mstore8(at, 0x20)
at := d(add(at, 1), y)
mstore8(at, 0x68)
at := d(add(at, 1), n)
mstore(at, "v1h-")
at := d(add(at, 4), n)
mstore8(at, 0x7a)
mstore(k, add(at, 1))
}
}
function _px(uint256[576] memory px, uint256 p) internal pure returns (uint256 v) {
assembly ("memory-safe") {
v := mload(add(px, shl(5, p)))
}
}
function _paths(Ink memory k, uint256[] memory pxs, uint256[] memory cols) internal pure {
unchecked {
uint256 len = pxs.length;
uint256[] memory runs = new uint256[](len);
uint256 nr;
uint256 i;
while (i < len) {
uint256 p = pxs[i];
uint256 col = cols[i];
uint256 n = 1;
while (i + n < len && pxs[i + n] == p + n && (p + n) / 24 == p / 24 && cols[i + n] == col) n++;
runs[nr++] = p | (n << 16) | (col << 32);
i += n;
}
for (i = 0; i < nr; i++) {
uint256 r = runs[i];
if (r >> 255 != 0) continue;
uint256 col = (r >> 32) & RGB;
k.w('<path fill="', 12);
k.hex6(col);
k.w('" d="', 5);
for (uint256 j = i; j < nr; j++) {
uint256 q = runs[j];
if (q >> 255 != 0 || ((q >> 32) & RGB) != col) continue;
_run(k, (q & 0xFFFF) % 24, (q & 0xFFFF) / 24, (q >> 16) & 0xFFFF);
runs[j] = q | (1 << 255);
}
k.w('"/>', 3);
}
}
}
function _shape(Ink memory k, uint256[] memory pxs, uint256 parity) internal pure {
unchecked {
uint256 len = pxs.length;
uint256 i;
while (i < len) {
uint256 p = pxs[i];
if (parity < 2 && p % 2 != parity) {
i++;
continue;
}
uint256 n = 1;
if (parity == 2) {
while (i + n < len && pxs[i + n] == p + n && (p + n) / 24 == p / 24) n++;
}
_run(k, p % 24, p / 24, n);
i += n;
}
}
}
function _fade(Ink memory k, uint256[] memory pxs, uint256[] memory cols, uint256[] memory v, uint256 steps)
internal
pure
{
if (pxs.length == 0 || !_any(v)) return;
k.w('<g opacity="0">', 15);
_anim(k, "opacity", 7, v, steps, 0, false);
_paths(k, pxs, cols);
k.w("</g>", 4);
}
function _lights(Ink memory k, Card memory c, Light memory o) internal pure {
unchecked {
uint256 nc = o.own ? _steps(c, o.cycle) : o.cycle;
uint256[] memory xs = new uint256[](o.loop);
uint256[] memory ys = new uint256[](o.loop);
uint256[] memory env = new uint256[](nc);
for (uint256 s = 0; s < o.count; s++) {
// forge-lint: disable-next-line(unsafe-typecast)
int256 c0 = (o.own ? c.tb0 * 10 / int256(o.cycle) : int256(0)) + WAD * int256(s) / int256(o.count);
// forge-lint: disable-next-line(unsafe-typecast)
uint256 first = uint256(c0 / WAD);
int256 fr = c0 % WAD;
// forge-lint: disable-next-line(unsafe-typecast)
uint256 sh = uint256(fr * int256(nc) / WAD);
for (uint256 j = 0; j < o.loop; j++) {
uint256 p = o.mask[(c.x[((first + j) * o.mulC + s * o.mulS + o.add) % o.mod] * o.mask.length) >> 32];
xs[j] = p % 24;
ys[j] = p / 24;
}
for (uint256 m = 0; m < nc; m++) {
int256 f = _at(fr, m, nc);
int256 e = f < o.rise ? f * WAD / o.rise : WAD - (f - o.rise) * WAD / o.fall;
env[m] = Fixed.op(e * o.amount / 1000);
}
k.w('<rect width="1" height="1" fill=', 32);
k.w('"', 1);
k.hex6(o.colour);
k.w('" opacity="0">', 14);
_anim(k, "x", 1, xs, nc * o.loop, sh, true);
_anim(k, "y", 1, ys, nc * o.loop, sh, true);
_anim(k, "opacity", 7, env, nc, 0, false);
k.w("</rect>", 7);
}
}
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"forge-std/=lib/forge-std/src/",
"ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.