diff --git a/.dockerignore b/.dockerignore index 38ad426..dca80db 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,7 +6,7 @@ frontend/out frontend/.cpcache frontend/test/browser/out static/arthur/js -db.sqlite3* +db.sqlite3 var frames scratch @@ -16,5 +16,3 @@ manifest.json *.tflite .claude .venv* -stable-audio-3 -**/.DS_Store diff --git a/frontend/src/arthur/domain/clip.cljs b/frontend/src/arthur/domain/clip.cljs index a92106d..96eaa1f 100644 --- a/frontend/src/arthur/domain/clip.cljs +++ b/frontend/src/arthur/domain/clip.cljs @@ -303,10 +303,7 @@ (+ (* (aget m 1) x) (* (aget m 3) y) (aget m 5))]) scale (node/mean-scale m) n (:node op) - op (cond-> (assoc op :node (if (vector? n) (into path n) (conj path n))) - ;; A warp's field is in its shape's space, which is now one - ;; matrix further down. - (:warp op) (assoc :m (node/mul! (node/mat) m (:m op))))] + op (assoc op :node (if (vector? n) (into path n) (conj path n)))] (case (:kind op) :poly (let [out (js/Float64Array. (.-length (:pts op)))] (dotimes [i (:n op)] diff --git a/frontend/src/arthur/domain/node.cljs b/frontend/src/arthur/domain/node.cljs index 24838da..cc7b305 100644 --- a/frontend/src/arthur/domain/node.cljs +++ b/frontend/src/arthur/domain/node.cljs @@ -76,13 +76,13 @@ ;; A sound is not in the picture: no transform, no visibility. After ;; Effects' audio-only layer has no Transform group for the same reason. :audio #{[:audio :gain] [:audio :pan] [:audio :rate]} - :poly (into base [[:geom :pts] [:style :color] [:warp :amount] [:warp :size] [:warp :phase]]) + :poly (into base [[:geom :pts] [:style :color]]) ;; A disc's radius is framed in practice — iris size is a knob, not a ;; performance — but it is a channel like any other so it can be keyed. - :disc (into base [[:geom :radius] [:style :color] [:warp :amount] [:warp :size] [:warp :phase]]) + :disc (into base [[:geom :radius] [:style :color]]) ;; :size, not a radius: the pupil is a SQUARE, an exactly size x size ;; block. See raster/fill-rect!. - :rect (into base [[:geom :size] [:style :color] [:warp :amount] [:warp :size] [:warp :phase]])})) + :rect (into base [[:geom :size] [:style :color]])})) (def defaults "The identity transform, as channels. A node's channel map is merged over this, @@ -109,21 +109,10 @@ [:audio :pan] (ch/framed 0.0) [:audio :rate] (ch/framed 1.0)}) -(def warp-defaults - "The channels a shape coloured `[:warp kind]` has, by kind, at values that show - the warp plainly. A lens has only an amount; a wave also has a wavelength and - where along it the wave is. See `warp/field` for what each one means." - {:lens {[:warp :amount] (ch/framed 1.0)} - :tiles {[:warp :amount] (ch/framed 2.0) [:warp :size] (ch/framed 8.0)} - :wave {[:warp :amount] (ch/framed 2.0) [:warp :size] (ch/framed 16.0) [:warp :phase] (ch/framed 0.0)} - :ripple {[:warp :amount] (ch/framed 2.0) [:warp :size] (ch/framed 8.0) [:warp :phase] (ch/framed 0.0)} - :mirror {[:warp :amount] (ch/framed 0.3) [:warp :size] (ch/framed 64.0) [:warp :phase] (ch/framed 0.0)}}) - (def ^:private channel-names {[:xform :pos] "pos" [:xform :rot] "rot°" [:xform :scale] "scale" [:xform :skew] "skew" [:xform :pivot] "pivot" [:geom :pts] "shape" - [:style :color] "color" [:vis] "vis" [:palette] "palette" - [:warp :amount] "warp" [:warp :size] "size" [:warp :phase] "phase"}) + [:style :color] "color" [:vis] "vis" [:palette] "palette"}) (defn channel-name "What to call channel `path` on screen: the same short word in the inspector @@ -131,21 +120,8 @@ [path] (or (channel-names path) (str/join " " (map name path)))) -(defn defaults-of - "The channels node `n` has before it stores any: its kind's, and a warp's for - each warp its colour names on any key, as a sound has a gain. Read every - frame for every node, so a colour that names no vector is answered without - walking its keys." - [n] - (let [c (get-in n [:channels [:style :color]])] - (cond - (= :audio (:kind n)) audio-defaults - (not (or (:keys c) (vector? (:value c)))) defaults - :else (reduce (fn [d v] - (if (and (vector? v) (= :warp (first v))) - (merge d (warp-defaults (second v))) - d)) - defaults (cons (:value c) (vals (:keys c))))))) +(defn defaults-of [n] + (if (= :audio (:kind n)) audio-defaults defaults)) (defn channels "The node's channels with its kind's defaults filled in." diff --git a/frontend/src/arthur/domain/palette.cljs b/frontend/src/arthur/domain/palette.cljs index 6ae16f7..d213375 100644 --- a/frontend/src/arthur/domain/palette.cljs +++ b/frontend/src/arthur/domain/palette.cljs @@ -195,14 +195,14 @@ (defn- colour-slots "The slots a colour channel names at any key: a slot, a legacy tone, or both - sides of a remap's map. A knockout and a warp name none." + sides of a remap's map. A knockout names none." [ch] (let [values (if (:keys ch) (vals (:keys ch)) [(:value ch)])] (into #{} (comp (mapcat (fn [v] (cond (and (vector? v) (= :remap (first v))) (mapcat identity (second v)) - (or (= :clear v) (and (vector? v) (= :warp (first v)))) [] + (= :clear v) [] :else [v]))) (map slot) (remove #{255})) diff --git a/frontend/src/arthur/domain/pick.cljs b/frontend/src/arthur/domain/pick.cljs index 347b50d..9e35423 100644 --- a/frontend/src/arthur/domain/pick.cljs +++ b/frontend/src/arthur/domain/pick.cljs @@ -104,8 +104,7 @@ nil. A knockout is never hit: it is a hole, and a click in it is a click on whatever shows through — so it hides the ops beneath it in its own symbol, of the colour it clears. A remap is the same kind of thing the other way up: it is - light on what is under it, so a click goes through it to what it lights, and - a warp is glass a click goes through in the same way. + light on what is under it, so a click goes through it to what it lights. EXCEPT WHAT IS ALREADY SELECTED, which `selected` is the row path of. Both of those rules are about reaching PAST a shape, and neither has anything to say @@ -124,7 +123,7 @@ (cond (not (on? op x y)) holes (and selected (prefix? selected (path-of op))) (reduced {:op op}) - (or (:lut op) (:warp op)) holes + (:lut op) holes (:knock op) (conj holes [(pop (path-of op)) (:knock op)]) (some (fn [[in k]] (and (prefix? in (path-of op)) (or (neg? k) (== k (:color op))))) diff --git a/frontend/src/arthur/domain/raster.cljs b/frontend/src/arthur/domain/raster.cljs index fe63033..38cd5ba 100644 --- a/frontend/src/arthur/domain/raster.cljs +++ b/frontend/src/arthur/domain/raster.cljs @@ -19,21 +19,15 @@ A raster may have an `:origin`, the stage point its first pixel is, and ops stay in stage pixels either way: the editor rasterises whatever part of the - work area is on screen, which need not be the stage. It may have a `:scale` - too, a whole number of its pixels to a stage pixel, which is how a lens sees - what is under it more finely than the stage does; see `warp!`." - (:require [arthur.domain.warp :as warp])) + work area is on screen, which need not be the stage.") (defn make [w h] {:w w :h h :buf (js/Uint8Array. (* w h))}) -(defn clear! - "`r` filled with `index`, which it remembers as what is under everything - drawn on it." - [{:keys [buf cov] :as r} index] +(defn clear! [{:keys [buf cov] :as r} index] (.fill buf index) (when cov (.fill cov 0)) - (assoc r :bg index)) + r) ;; --------------------------------------------------------------------------- ;; layers and knockouts @@ -45,7 +39,7 @@ ;; only where it is covered. The main raster has no `:cov` and is always ;; covered. ;; -;; THE INK is how a shape marks the pixels it covers, and there are four, as +;; THE INK is how a shape marks the pixels it covers, and there are three, as ;; Deluxe Paint and Animator Pro had inks: ;; ;; nil an ordinary fill: write the shape's index @@ -53,10 +47,6 @@ ;; that index only ;; a Uint8Array a REMAP, index -> index: what is already there is drawn ;; in another slot. A flashlight is a circle of this. -;; an Int32Array a WARP: what is already there is drawn from somewhere -;; else. The fill only collects the pixels it covers here, -;; counted in its first entry; `warp!` draws them, once it -;; has read every one. (defn- plot! [^js buf cov o index ink] (cond @@ -64,9 +54,6 @@ (when cov (aset cov o 1))) (number? ink) (when (and cov (or (neg? ink) (== (aget buf o) ink))) (aset cov o 0)) - (instance? js/Int32Array ink) (let [n (inc (aget ink 0))] - (aset ink n o) - (aset ink 0 n)) :else (aset buf o (aget ink (aget buf o))))) (defn- shows? @@ -102,21 +89,15 @@ `pts` may be a CLJS vector or any typed array; scanline crossings are collected into a plain JS array and sorted in place. `ink` is as `plot!`'s." ([r pts n index] (fill-poly-buf! r pts n index nil)) - ([{:keys [w h buf cov origin scale] :as r} pts n index ink] + ([{:keys [w h buf cov origin] :as r} pts n index ink] (when (>= n 3) (let [[ox oy] (or origin [0 0]) - sc (or scale 1) - px (fn [i] (* sc (- (if (vector? pts) (-nth pts (* 2 i)) (aget pts (* 2 i))) ox))) - py (fn [i] (* sc (- (if (vector? pts) (-nth pts (inc (* 2 i))) (aget pts (inc (* 2 i)))) oy))) + px (fn [i] (- (if (vector? pts) (-nth pts (* 2 i)) (aget pts (* 2 i))) ox)) + py (fn [i] (- (if (vector? pts) (-nth pts (inc (* 2 i))) (aget pts (inc (* 2 i)))) oy)) xs (array) ys (map py (range n)) y0 (max 0 (js/Math.ceil (- (reduce min ys) 0.5))) - y1 (min (dec h) (inc (js/Math.floor (- (reduce max ys) 0.5)))) - ;; A shape wholly to one side of the raster has no span on any row - ;; of it, and need not be walked row by row to find that out: a lens - ;; redraws everything before it over a small box. - y1 (let [qs (map px (range n))] - (if (or (< (reduce max qs) 0) (> (reduce min qs) w)) -1 y1))] + y1 (min (dec h) (inc (js/Math.floor (- (reduce max ys) 0.5))))] ;; `dotimes` over the span rather than a hand-rolled index: bounded ;; iteration with no accumulator is what it is for, and it compiles to the ;; same JS for-loop the recur did. @@ -174,11 +155,9 @@ clamp that would flatten the performance at the extremes." ([r cx cy rad index] (fill-disc! r cx cy rad index nil nil)) ([r cx cy rad index over] (fill-disc! r cx cy rad index over nil)) - ([{:keys [w h buf cov origin scale] :as r} cx cy rad index over ink] + ([{:keys [w h buf cov origin] :as r} cx cy rad index over ink] (let [[ox oy] (or origin [0 0]) - sc (or scale 1) - cx (* sc (- cx ox)) cy (* sc (- cy oy)) - rad (* sc rad) + cx (- cx ox) cy (- cy oy) rr (* rad rad) y0 (max 0 (js/Math.floor (- cy rad))) y1 (min (dec h) (js/Math.ceil (+ cy rad))) @@ -209,21 +188,16 @@ The top-left is rounded rather than the centre, so the block is size x size on every frame. Round the extents instead and a fractional centre gives you three pixels on one frame and four on the next, which reads as the pupil - breathing. - - On a finer raster it is snapped to the STAGE's grid and then scaled, so a - lens shows the same block bigger, not a block of another size." + breathing." ([r cx cy size index] (fill-rect! r cx cy size index nil nil)) ([r cx cy size index over] (fill-rect! r cx cy size index over nil)) - ([{:keys [w h buf cov origin scale] :as r} cx cy size index over ink] + ([{:keys [w h buf cov origin] :as r} cx cy size index over ink] (let [[ox oy] (or origin [0 0]) - sc (or scale 1) cx (- cx ox) cy (- cy oy) size (js/Math.round size)] (when (>= size 1) - (let [x0 (* sc (js/Math.round (- cx (/ size 2)))) - y0 (* sc (js/Math.round (- cy (/ size 2)))) - size (* sc size) + (let [x0 (js/Math.round (- cx (/ size 2))) + y0 (js/Math.round (- cy (/ size 2))) ya (max 0 y0) yb (min h (+ y0 size)) xa (max 0 x0) xb (min w (+ x0 size))] (dotimes [iy (- yb ya)] @@ -319,134 +293,16 @@ r) ;; One layer per depth of nesting, reused from frame to frame, as the resolver -;; reuses its point buffers — and one set per LEVEL, a lens's finer redraw of -;; what is under it being level 1, so the redraw never draws into a layer the -;; frame it is part of is still using. +;; reuses its point buffers. (defonce ^:private layers (atom {})) -(defn- layer-at [level depth {:keys [w h origin scale]}] - (let [l (get @layers [level depth])] +(defn- layer-at [depth {:keys [w h origin]}] + (let [l (get @layers depth)] (if (and l (= w (:w l)) (= h (:h l))) - (assoc l :origin origin :scale scale) + (assoc l :origin origin) (let [l (layer w h)] - (swap! layers assoc [level depth] l) - (assoc l :origin origin :scale scale))))) - -;; What a warp works with, per level, reused from op to op as the layers are -;; and grown only for a bigger raster: the pixels it covers, where each reads -;; from, and what each will show. A warp costs what it covers and allocates -;; nothing for that. -(defonce ^:private scratch (atom {})) - -(defn- scratch-at [level {:keys [w h]}] - (let [n (* w h) - sc (get @scratch level)] - (if (and sc (<= n (.-length (:shown sc)))) - sc - (let [sc {:covered (js/Int32Array. (inc n)) :src (js/Float64Array. (* 2 n)) - :shown (js/Int32Array. n) :at (js/Float64Array. 2)}] - (swap! scratch assoc level sc) - sc)))) - -(defn- covered-for - "The scratch a warp over raster `r` at `level` records its pixels into, - emptied." - [level r] - (doto (:covered (scratch-at level r)) (aset 0 0))) - -;; How much finer a lens may see, and how many pixels its redraw may come to: -;; four stage rasters' worth, which a full-stage lens at 2x is exactly. -(def ^:private finest 4) -(def ^:private fine-budget (* 4 320 200)) - -;; The buffers a finer redraw draws into, grown and never shrunk. -(defonce ^:private fine-bufs (volatile! {:buf (js/Uint8Array. 0) :cov (js/Uint8Array. 0)})) - -(defn- fine-raster - "A raster `k` times finer than the stage over stage box `[x0 y0 x1 y1]`, for - a redraw of what is under a lens: a layer when `layer?`, otherwise filled - with `bg`, as the raster the lens is on was." - [k [x0 y0 x1 y1] layer? bg] - (let [ox (js/Math.floor x0) oy (js/Math.floor y0) - w (* k (inc (- (js/Math.ceil x1) ox))) - h (* k (inc (- (js/Math.ceil y1) oy))) - n (* w h)] - (when (< (.-length (:buf @fine-bufs)) n) - (vreset! fine-bufs {:buf (js/Uint8Array. n) :cov (js/Uint8Array. n)})) - (let [buf (.subarray (:buf @fine-bufs) 0 n) - cov (when layer? (.subarray (:cov @fine-bufs) 0 n))] - (.fill buf (or bg 0)) - (when cov (.fill cov 0)) - {:w w :h h :buf buf :cov cov :origin [ox oy] :scale k}))) - -(declare draw!) - -(defn- warp! - "Draw each pixel the fill before this covered as what `field` says it shows, - read from where it shows it. - - EVERY PIXEL IS READ BEFORE ANY IS WRITTEN. A pixel a lens moves is one some - other pixel of the lens reads, so writing as it goes would magnify what it - had already magnified. Nothing outside what is covered is written. - - WHAT IT MAGNIFIES IS DRAWN AGAIN, FINER, not blown up. Magnifying the pixels - would show each one as a block and lose what the drawing has between them; - but what is under a lens is `under`, the ops drawn before it in this buffer, - and drawing them again `k` times finer over the box it reads from shows what - the shapes are at that size — the same picture as bending the shapes before - rasterising, at a fraction of the work. `k` is how much the field magnifies - where it magnifies most: one over the smallest step between what two - neighbouring pixels read. It is a whole number, at most `finest`, and small - enough that the redraw keeps to `fine-budget`; a warp that magnifies nothing - reads the buffer as it is. A redraw is level 1, and a lens in it reads its - own buffer rather than redrawing again. - - A point off the raster reads its nearest edge. In a layer what is shown - includes whether anything is there: a warp moves a hole as it moves a mark." - [{:keys [w h ^js buf ^js cov origin scale bg] :as r} field level under] - (let [[ox oy] (or origin [0 0]) - sc (or scale 1) - {:keys [^js covered ^js src ^js shown ^js at]} (scratch-at level r) - n (aget covered 0) - layer? (some? cov) - box #js [js/Infinity js/Infinity (- js/Infinity) (- js/Infinity)] - step (volatile! js/Infinity)] - ;; `js-mod` and a division rather than `rem` and `quot`, which are calls: - ;; this is once per covered pixel. - (dotimes [i n] - (let [o (aget covered (inc i)) - ix (js-mod o w)] - (field at (+ ox (/ (+ ix 0.5) sc)) (+ oy (/ (+ (/ (- o ix) w) 0.5) sc))) - (let [x (aget at 0) y (aget at 1)] - (aset src (* 2 i) x) - (aset src (inc (* 2 i)) y) - (aset box 0 (min (aget box 0) x)) (aset box 1 (min (aget box 1) y)) - (aset box 2 (max (aget box 2) x)) (aset box 3 (max (aget box 3) y)) - (when (and (pos? i) (== o (inc (aget covered i)))) - (let [d (js/Math.hypot (- x (aget src (* 2 (dec i)))) (- y (aget src (dec (* 2 i)))))] - (when (< 1e-6 d @step) (vreset! step d))))))) - (let [area (* (- (aget box 2) (aget box 0) -2) (- (aget box 3) (aget box 1) -2)) - k (if (and under (pos? n) (< @step (/ 1 sc))) - (loop [k (min finest (js/Math.ceil (- (/ 1 @step) 1e-6)))] - (if (and (< 1 k) (< fine-budget (* area k k))) (recur (dec k)) k)) - 1) - ;; Where the lens reads from: the stage drawn again, finer, or the - ;; buffer as it is. - {fw :w fh :h ^js fbuf :buf ^js fcov :cov [fx fy] :origin fs :scale} - (if (< 1 k) - (draw! (fine-raster k (vec box) layer? bg) under 1) - {:w w :h h :buf buf :cov cov :origin [ox oy] :scale sc})] - (dotimes [i n] - (let [x (max 0 (min (dec fw) (js/Math.floor (* fs (- (aget src (* 2 i)) fx))))) - y (max 0 (min (dec fh) (js/Math.floor (* fs (- (aget src (inc (* 2 i))) fy))))) - s (+ (* y fw) x)] - (aset shown i (if layer? (+ (aget fbuf s) (* 256 (aget fcov s))) (aget fbuf s)))))) - (dotimes [i n] - (let [o (aget covered (inc i)) - v (aget shown i)] - (aset buf o (bit-and v 255)) - (when layer? (aset cov o (bit-shift-right v 8))))) - r)) + (swap! layers assoc depth l) + (assoc l :origin origin))))) (defn draw-ops! "Paint a list of draw ops, in the order given, into the raster. Stage 7. @@ -458,43 +314,23 @@ here indistinguishable from each other, which is the point. `:begin` and `:end` bracket the ops of a symbol drawn into a layer of its own; - `:knock` on an op makes it a knockout, `:lut` a remap and `:warp` a warp. See - `plot!`. A warp with no field — a kind there is none of — is drawn MAGENTA, - as a colour the palette lacks is: loud, and not fatal." + `:knock` on an op makes it a knockout and `:lut` a remap. See `plot!`." [r ops] - (draw! r ops 0)) - -(defn- draw! - "`draw-ops!` at `level`, which a lens's finer redraw of what is under it is - 1 of. Each buffer on the stack remembers where in `ops` it began, so a lens - knows which ops are under it: the ones before it in its own buffer." - [r ops level] - (let [ops (vec ops)] - (reduce - (fn [stack i] - (let [{:keys [kind pts n color stencil cx cy size] :as op} (nth ops i) - top (:r (peek stack)) - field (when (:warp op) (warp/field op)) - color (if (and (:warp op) (nil? field)) 255 color) - ink (if field (covered-for level top) (or (:knock op) (:lut op)))] - (case kind - :begin (let [l (layer-at level (count stack) r)] - (.fill (:cov l) 0) - (conj stack {:r l :from (inc i)})) - :end (if (< 1 (count stack)) - (let [s (pop stack)] (composite! (:r (peek s)) top) s) - stack) - (do (case kind - :poly (fill-poly-buf! top pts n color ink) - :disc (fill-disc! top cx cy (:r op) color stencil ink) - :rect (fill-rect! top cx cy size color stencil ink) - ;; A brush stroke's mask is a byte per stage pixel, and has - ;; nothing finer to show. - :mask (when (= 1 (or (:scale top) 1)) (fill-mask! top (:mask op) color ink)) - (throw (ex-info "draw op kind is not rasterisable" {:op (dissoc op :pts)}))) - (when field - (warp! top field level - (when (zero? level) (subvec ops (:from (peek stack)) i)))) - stack)))) - [{:r r :from 0}] (range (count ops)))) + (reduce + (fn [stack {:keys [kind pts n color stencil cx cy size] :as op}] + (let [top (peek stack) + ink (or (:knock op) (:lut op))] + (case kind + :begin (let [l (layer-at (count stack) r)] + (.fill (:cov l) 0) + (conj stack l)) + :end (if (< 1 (count stack)) + (let [s (pop stack)] (composite! (peek s) top) s) + stack) + :poly (do (fill-poly-buf! top pts n color ink) stack) + :disc (do (fill-disc! top cx cy (:r op) color stencil ink) stack) + :rect (do (fill-rect! top cx cy size color stencil ink) stack) + :mask (do (fill-mask! top (:mask op) color ink) stack) + (throw (ex-info "draw op kind is not rasterisable" {:op (dissoc op :pts)}))))) + [r] ops) r) diff --git a/frontend/src/arthur/domain/symbol.cljs b/frontend/src/arthur/domain/symbol.cljs index 5570f36..17e75c9 100644 --- a/frontend/src/arthur/domain/symbol.cljs +++ b/frontend/src/arthur/domain/symbol.cljs @@ -294,13 +294,6 @@ [c] (and (vector? c) (= :remap (first c)))) -(defn warp? - "Is colour `c` a WARP: `[:warp kind]`? Like a remap it draws nothing of its - own; what is already under it is drawn from somewhere else — a lens, a glass - brick, a ripple. See `warp/field`." - [c] - (and (vector? c) (= :warp (first c)))) - (defn- knock-index [palette c] (if (= :clear c) -1 (colour-index palette (second c)))) @@ -455,12 +448,6 @@ (cond (knockout? c) (assoc op :knock (knock-index palette c) :color 0) (remap? c) (assoc op :lut (lut palette c) :color 0) - ;; The field is in the shape's own space, so the op - ;; carries the matrix that space is drawn through. - (warp? c) (assoc op :warp (second c) :m m :color 0 - :amount (rd [:warp :amount]) - :size (rd [:warp :size]) - :phase (rd [:warp :phase])) :else (assoc op :color (colour-index palette c)))))] (case (:kind n) :group nil diff --git a/frontend/src/arthur/domain/warp.cljs b/frontend/src/arthur/domain/warp.cljs deleted file mode 100644 index b5ea2bf..0000000 --- a/frontend/src/arthur/domain/warp.cljs +++ /dev/null @@ -1,97 +0,0 @@ -(ns arthur.domain.warp - "What a warp shape shows at each pixel it covers: what is under it, from - somewhere else. - - A WARP IS A REMAP IN SPACE. A remap redraws what is under a shape in another - slot and leaves it where it is; a warp redraws it from another place and - leaves its slot alone. So it lands where a remap does — on what was drawn - before it, in the buffer it is drawn into — and what is drawn after it is - untouched. A lens is between things for the same reason a flashlight is: draw - order. Nothing here knows about depth. - - Each kind is a FIELD, a map from a point to the point it shows, in the shape's - OWN space: the origin is the middle of what it draws (`paint/centred`), and a - field that moves, turns and scales with its node is a field written about that - origin and carried by its matrix. A lens magnifies about the lens. - - AMOUNT 0 IS UNTOUCHED, for every kind, so tweening amount from 0 brings any - warp in from nothing. Size is a length in the shape's space — a wavelength or - a tile — and phase is in turns, so keying it 0 then 1 runs a wave through once. - - Sampling is nearest-neighbour, by construction: a warp moves indices and - never invents one, so it keeps the hard indexed edge the rasteriser exists - for." - (:require [arthur.domain.node :as node])) - -(def ^:private tau (* 2 js/Math.PI)) - -(defn- local-field - "Kind `kind`'s field about the origin, as (fn [out x y]) writing the point - `(x, y)` shows into `out`. nil for a kind there is none of." - [kind a s ph rim] - (case kind - ;; Glass that bulges: (1 + a) times as big in the middle, easing back to - ;; as it is at the rim, so the edge meets what is outside it with no seam - ;; and what is near it is squeezed round the curve — Photoshop's - ;; Spherize. A negative amount pinches. Outside the rim, as it is. - :lens (let [rr (* rim rim)] - (fn [^js out x y] - (let [t2 (/ (+ (* x x) (* y y)) rr) - k (if (< t2 1) (/ 1 (max 0.01 (+ 1 (* a (- 1 t2))))) 1)] - (aset out 0 (* x k)) - (aset out 1 (* y k))))) - ;; Each tile of glass shows what is behind its own middle: 1 is one flat - ;; colour per tile, 2 the tile's view turned over, as a glass brick does. - :tiles (fn [^js out x y] - (let [cx (* s (+ 0.5 (js/Math.floor (/ x s)))) - cy (* s (+ 0.5 (js/Math.floor (/ y s))))] - (aset out 0 (+ cx (* (- x cx) (- 1 a)))) - (aset out 1 (+ cy (* (- y cy) (- 1 a)))))) - ;; Rows slid side to side: water, heat over a road. - :wave (fn [^js out x y] - (aset out 0 (+ x (* a (js/Math.sin (* tau (+ (/ y s) ph)))))) - (aset out 1 y)) - ;; Rings running out from the middle: a stone in a pond. - :ripple (fn [^js out x y] - (let [r (js/Math.hypot x y) - d (if (pos? r) (/ (* a (js/Math.sin (* tau (- (/ r s) ph)))) r) 0)] - (aset out 0 (+ x (* x d))) - (aset out 1 (+ y (* y d))))) - ;; Widths swelling and pinching down the height: the fairground mirror. - :mirror (fn [^js out x y] - (aset out 0 (* x (- 1 (* a (js/Math.sin (* tau (+ (/ y s) ph))))))) - (aset out 1 y)) - nil)) - -(defn- rim - "How far shape op `op` reaches from its own middle, in its own space: the - farthest of its points, through `inv`. A lens is back to as it is there, so - its edge is the edge of the glass drawn, at any size." - [{:keys [kind ^js pts n r size]} ^js inv m] - (case kind - :poly (reduce (fn [far i] - (let [x (aget pts (* 2 i)) y (aget pts (inc (* 2 i)))] - (max far (js/Math.hypot - (+ (* (aget inv 0) x) (* (aget inv 2) y) (aget inv 4)) - (+ (* (aget inv 1) x) (* (aget inv 3) y) (aget inv 5)))))) - 0 (range n)) - :disc (/ r (node/mean-scale m)) - :rect (/ (* size js/Math.SQRT1_2) (node/mean-scale m)) - 0)) - -(defn field - "Warp op `op`'s field in stage space: (fn [out x y]) writing into `out` the - stage point that stage point `(x, y)` shows. nil when it has none — a kind - there is no field for, or a shape scaled to nothing, which covers nothing." - [{:keys [warp m amount size phase] :as op}] - (when-let [^js inv (node/invert m)] - (when-let [f (local-field warp (or amount 0) (max 1 (or size 1)) (or phase 0) - (when (= :lens warp) (max 1 (rim op inv m))))] - (fn [^js out x y] - (f out - (+ (* (aget inv 0) x) (* (aget inv 2) y) (aget inv 4)) - (+ (* (aget inv 1) x) (* (aget inv 3) y) (aget inv 5))) - (let [u (aget out 0) v (aget out 1)] - (aset out 0 (+ (* (aget m 0) u) (* (aget m 2) v) (aget m 4))) - (aset out 1 (+ (* (aget m 1) u) (* (aget m 3) v) (aget m 5)))) - out)))) diff --git a/frontend/src/arthur/ui/icon.cljs b/frontend/src/arthur/ui/icon.cljs index 2a16b0b..a80a026 100644 --- a/frontend/src/arthur/ui/icon.cljs +++ b/frontend/src/arthur/ui/icon.cljs @@ -74,15 +74,6 @@ "M4.4 7.8 8.5 2" "M7.6 7.8 3.5 2"]} :paste {:stroke ["M3.8 2.5H2.5v8h7v-8H8.2" "M4.5 1.5h3v2h-3z"]} :duplicate {:stroke ["M4.5 4.5h5v5h-5z" "M2.5 7.5v-5h5" "M7 5.8v2.4" "M5.8 7h2.4"]} - ;; The warps, each as what it does to what is behind it: a magnifying - ;; glass, a square of glass bricks, water, rings on a pond, and the - ;; fairground mirror's waist. - :lens {:stroke ["M2 5a3 3 0 1 0 6 0a3 3 0 1 0 -6 0" "M7.2 7.2 10.5 10.5"]} - :tiles {:stroke ["M1.5 1.5h9v9h-9z" "M6 1.5v9" "M1.5 6h9"]} - :wave {:stroke ["M1.5 4.5c1.5-2 3-2 4.5 0s3 2 4.5 0" "M1.5 8.5c1.5-2 3-2 4.5 0s3 2 4.5 0"]} - :ripple {:fill ["M5 6a1 1 0 1 0 2 0a1 1 0 1 0 -2 0z"] - :stroke ["M3 6a3 3 0 1 0 6 0a3 3 0 1 0 -6 0" "M1 6a5 5 0 1 0 10 0a5 5 0 1 0 -10 0"]} - :mirror {:stroke ["M3 1.5c2.2 2.5 2.2 6.5 0 9" "M9 1.5c-2.2 2.5-2.2 6.5 0 9"]} ;; Whether others may follow you: an eye, open to being watched. :eye {:stroke ["M1.5 6C2.8 3.8 4.3 2.8 6 2.8S9.2 3.8 10.5 6C9.2 8.2 7.7 9.2 6 9.2S2.8 8.2 1.5 6z"] :fill ["M4.8 6a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0 -2.4 0z"]}}) diff --git a/frontend/src/arthur/ui/palette.cljs b/frontend/src/arthur/ui/palette.cljs index 9d3c8f5..247d5bf 100644 --- a/frontend/src/arthur/ui/palette.cljs +++ b/frontend/src/arthur/ui/palette.cljs @@ -21,7 +21,6 @@ [arthur.footage.store :as store] [arthur.domain.palette :as pal] [arthur.domain.symbol :as symbol] - [arthur.ui.icon :as icon] [arthur.subs.playback :as playback] [arthur.events.project :as project] [arthur.events.ui :as ui] @@ -85,20 +84,6 @@ (rf/dispatch [::ui/set-tone tone])) ;; --------------------------------------------------------------------------- -;; warps: a shape that shows what is under it from somewhere else -;; -;; As a remap does, a warp draws nothing of its own and lands on what is drawn -;; before it; how much is its `[:warp …]` channels, in the inspector and the -;; timeline like any other. See `domain/warp`. - -(def warps - "Each warp a shape can be: its kind, its name and what it does." - [[:lens "lens" "lens — glass that bulges: what is under its middle is magnified, easing back to as it is at its edge. How much is its warp channel; below 0 it pinches."] - [:tiles "glass tiles" "glass tiles — each tile shows what is behind it, turned over"] - [:wave "wave" "wave — slides what is under it side to side, as water does. Key its phase to run it."] - [:ripple "ripple" "ripple — rings out from its middle, as a stone in a pond. Key its phase to run it."] - [:mirror "funhouse mirror" "funhouse mirror — widths swell and pinch down its height"]]) - ;; remap: a shape that lights what is under it ;; ;; A shape coloured `[:remap {from to …}]` draws nothing of its own: whatever is @@ -211,16 +196,12 @@ ", the palette the stage is in") :on-click #(rf/dispatch [::select followed followed])} "↩ active"]) - [:div {:class (str "chip" (cond (= :clear tone) " clear" (symbol/remap? tone) " map" - (symbol/warp? tone) " warp")) + [:div {:class (str "chip" (cond (= :clear tone) " clear" (symbol/remap? tone) " map")) :style (when hex {:background hex}) :title (cond (= :clear tone) "clear: what is drawn knocks out what is under it in its symbol" (symbol/remap? tone) "remap: what is drawn lights what is under it" - (symbol/warp? tone) (some (fn [[k _ t]] (when (= k (second tone)) t)) warps) :else (str "slot " tone " · " hex))} - (if (symbol/warp? tone) - [icon/view (second tone)] - [:span (cond (= :clear tone) "×" (symbol/remap? tone) "⇄" :else tone)])] + [:span (cond (= :clear tone) "×" (symbol/remap? tone) "⇄" :else tone)]] [:div.cells (let [rm (remap) hex-of #(:hex (get (:slots palette) %))] (doall (map-indexed #(swatch pid %1 %2 tone rm hex-of (contains? used %1)) @@ -233,15 +214,7 @@ [:button {:class (str "cell map" (when (symbol/remap? tone) " on")) :title "remap — draws light: what is under it is drawn in other slots of the palette. Set which in the inspector." :on-click #(pick! [:remap {}])} - "⇄"]] - (doall - (for [[kind label title] warps] - ^{:key kind} - [:div.slot - [:button {:class (str "cell warp" (when (= [:warp kind] tone) " on")) - :aria-label label :title title - :on-click #(pick! [:warp kind])} - [icon/view kind]]]))] + "⇄"]]] [:div.grid-tools [:button {:class (when solo? "on") :disabled (not (number? tone)) diff --git a/frontend/src/arthur/ui/params.cljs b/frontend/src/arthur/ui/params.cljs index 2e65f0b..52da6b0 100644 --- a/frontend/src/arthur/ui/params.cljs +++ b/frontend/src/arthur/ui/params.cljs @@ -126,7 +126,7 @@ (def ^:private order (zipmap [[:xform :pos] [:xform :rot] [:xform :scale] [:xform :skew] [:xform :pivot] - paint/geometry [:style :color] [:warp :amount] [:warp :size] [:warp :phase] [:vis]] + paint/geometry [:style :color] [:vis]] (range))) (defn- gap-at @@ -215,7 +215,7 @@ (doall (map-indexed (fn [i x] (field i x #(put (assoc (vec v) i %)))) v))))) (defn- swatches - "A shape's colour, to change: every slot, then clear, remap and the warps, as the strip + "A shape's colour, to change: every slot, then clear and remap, as the strip beside the tools offers them for the next shape. This is where something already drawn is recoloured — the strip only says what is drawn next." [v off? palette pick!] @@ -245,17 +245,7 @@ :disabled off? :aria-label "remap" :aria-pressed (boolean (symbol/remap? v)) :title "remap — lights what is under it in other slots; set which below" - :on-click #(when-not (symbol/remap? v) (pick! [:remap {}]))}] - (doall - (for [[kind label title] palette/warps] - ^{:key kind} - [:button.swatch.warp - {:class (when (= [:warp kind] v) "on") - :disabled off? - :aria-label label :aria-pressed (= [:warp kind] v) - :title title - :on-click #(pick! [:warp kind])} - [icon/view kind]]))])) + :on-click #(when-not (symbol/remap? v) (pick! [:remap {}]))}]])) (defn- channel-value "The editor for channel `path` of node `n`: boxes, a switch, swatches — or, diff --git a/frontend/src/arthur/ui/player.cljs b/frontend/src/arthur/ui/player.cljs index f622fce..fe7cd4d 100644 --- a/frontend/src/arthur/ui/player.cljs +++ b/frontend/src/arthur/ui/player.cljs @@ -22,9 +22,7 @@ [arthur.domain.clip :as clip] [arthur.domain.cut :as cut] [arthur.domain.outline :as outline] - [arthur.domain.node :as node] [arthur.domain.onion :as onion] - [arthur.domain.paint :as paint] [arthur.domain.palette :as pal] [arthur.domain.pick :as pick] [arthur.domain.raster :as raster] @@ -346,22 +344,10 @@ (defn- inked "Op `op` drawn in tone `tone`: a slot's colour, or — for a remap — light on - what is under it, through the same table the saved shape gets. A warp is - about the middle of what is drawn, where the saved shape's origin will be, - at its kind's defaults." + what is under it, through the same table the saved shape gets." [op tone] - (cond - (symbol/remap? tone) + (if (symbol/remap? tone) (assoc op :lut (symbol/lut pal/slot tone) :color 0) - - (symbol/warp? tone) - (let [[cx cy] (paint/middle (array-seq (:pts op)))] - (into (assoc op :warp (second tone) :color 0 - :m (js/Float64Array. #js [1 0 0 1 cx cy])) - (map (fn [[[_ k] c]] [k (:value c)])) - (node/warp-defaults (second tone)))) - - :else (assoc op :color (pal/slot tone)))) (defn- with-previews @@ -376,7 +362,7 @@ {:keys [slot knock paths] :as s} @stroke rings (when (:mask s) (traced s fit))] (cond-> ops - (and (<= 6 (count pts)) (or (number? tone) (symbol/remap? tone) (symbol/warp? tone))) + (and (<= 6 (count pts)) (or (number? tone) (symbol/remap? tone))) (clip/atop target (inked (poly pts {}) tone)) paths diff --git a/frontend/test/arthur/domain/instance_test.cljs b/frontend/test/arthur/domain/instance_test.cljs index b6d8c14..ff58fb1 100644 --- a/frontend/test/arthur/domain/instance_test.cljs +++ b/frontend/test/arthur/domain/instance_test.cljs @@ -651,38 +651,6 @@ (is (= [a b c p] (clip/atop [a b c] [] p)) "the open symbol is on top of everything") (is (= [a b c p] (clip/atop [a b c] [:empty] p))))) -(deftest a-looping-symbol-of-one-remap-cycles-what-is-under-it - ;; Colour cycling, as Deluxe Paint did it, with nothing made for it: a - ;; three-frame symbol holding one remap shape whose map turns a step a frame, - ;; placed looping over what it cycles. The symbol draws into the buffer the - ;; stage is drawn into, so its remap reaches what is under the instance — - ;; and only under its shape. - (let [sq (fn [x0 y0 x1 y1] [x0 y0 x1 y0 x1 y1 x0 y1]) - doc (-> (clip/blank) - (paint/new-shape :main :a 0 (sq 0 0 10 10) 1) - (paint/new-shape :main :b 0 (sq 10 0 20 10) 2) - (paint/new-shape :main :c 0 (sq 20 0 30 10) 3) - (paint/new-shape :main :d 0 (sq 30 0 40 10) 1) - (assoc-in [:symbols :main :nodes :a :z] "a") - (assoc-in [:symbols :main :nodes :b :z] "b") - (assoc-in [:symbols :main :nodes :c :z] "c") - (assoc-in [:symbols :main :nodes :d :z] "d") - (assoc-in [:symbols :spin] - {:id :spin :frames 3 - :nodes {:glass {:id :glass :kind :poly :z "a" - :channels {[:geom :pts] (ch/framed (sq 0 0 30 10)) - [:style :color] (ch/keyed {0 [:remap {}] - 1 [:remap {1 2 2 3 3 1}] - 2 [:remap {1 3 2 1 3 2}]} :hold)}}}}) - (assoc-in [:symbols :main :nodes :spun] - {:id :spun :kind :instance :z "z" :source {:symbol :spin} - :playback {:in 0 :speed 1 :end :loop}})) - res (clip/resolver doc :main nil (pal/compile doc) nil) - at (fn [f] (let [r (raster/draw-ops! (raster/clear! (raster/make 320 200) 0) (res f))] - (mapv #(aget (:buf r) (+ % (* 5 320))) [5 15 25 35])))] - (is (= [[1 2 3 1] [2 3 1 1] [3 1 2 1] [1 2 3 1] [2 3 1 1]] (mapv at (range 5))) - "the three stripes under it turn and come round again; the fourth, outside it, does not"))) - (deftest a-remap-shape-lights-what-is-under-it-and-nothing-else ;; A flashlight: a circle that draws nothing of its own, and draws what is ;; already under it in other slots of the palette. diff --git a/frontend/test/arthur/domain/warp_test.cljs b/frontend/test/arthur/domain/warp_test.cljs deleted file mode 100644 index e7eabaf..0000000 --- a/frontend/test/arthur/domain/warp_test.cljs +++ /dev/null @@ -1,173 +0,0 @@ -(ns arthur.domain.warp-test - (:require [cljs.test :refer [deftest is testing]] - [arthur.domain.channel :as ch] - [arthur.domain.clip :as clip] - [arthur.domain.node :as node] - [arthur.domain.paint :as paint] - [arthur.domain.palette :as pal] - [arthur.domain.pick :as pick] - [arthur.domain.raster :as raster] - [arthur.domain.warp :as warp])) - -(defn- sq [x0 y0 x1 y1] [x0 y0 x1 y0 x1 y1 x0 y1]) - -(defn- drawn - "`document`'s root at frame 0, rasterised: the raster and its ops." - ([document] (drawn document (raster/make 320 200))) - ([document r] - (let [ops (vec ((clip/resolver document :main nil (pal/compile document) nil) 0))] - {:ops ops :ras (raster/draw-ops! (raster/clear! r 0) ops)}))) - -(defn- at [{:keys [ras]} x y] (aget (:buf ras) (+ x (* y (:w ras))))) - -(defn- row - "Slots along row `y` from `x0` up to `x1`." - [d y x0 x1] - (mapv #(at d % y) (range x0 x1))) - -(defn- shapes - "Shapes in the root, drawn in the order given." - [& specs] - (reduce (fn [doc [i [id pts c]]] - (-> doc - (paint/new-shape :main id 0 pts c) - (assoc-in [:symbols :main :nodes id :z] (str "z" i)))) - (clip/blank) (map-indexed vector specs))) - -;; A wall in two slots, a two-pixel dot on it, and over them a 20px square of -;; glass about (20, 20). What is drawn after the glass is a mark on top. -(def wall [:wall (sq 0 0 40 40) 2]) -(def dot [:dot (sq 20 20 22 22) 4]) -(def lens [:lens (sq 10 10 30 30) [:warp :lens]]) -(def mark [:mark (sq 25 25 28 28) 5]) - -(deftest a-lens-magnifies-what-is-under-it-and-nothing-over-it - (let [d (drawn (shapes wall dot lens mark))] - (is (= [2 2 4 4 4 4 2] (row d 21 18 25)) - "the dot under the lens is twice as wide, about the lens's middle") - (is (= [2 4 4 2] (row (drawn (shapes wall dot mark)) 21 19 23)) - "where without it the dot is two pixels") - (is (= [2 5 5 5 2] (row d 26 24 29)) - "the mark drawn after the lens is exactly the mark: above, untouched") - (is (= 2 (at d 5 5)) "and the wall outside the glass is as it was") - (is (= [:wall] (pick/hit (:ops d) [12 12])) "a click goes through the glass") - (is (= [:lens] (pick/hit (:ops d) [12 12] [:lens])) - "unless the glass is what is selected, which is how it is dragged"))) - -(deftest a-lens-draws-what-is-under-it-finer-not-bigger - ;; A line half a pixel wide is one pixel on the stage, and twice the size it - ;; is one pixel still: magnifying the pixel would make it two. The lens's - ;; middle is over the line, where it magnifies twice. - (let [line [:line (sq 20.2 10 20.7 30) 4] - glass [:lens (sq 10 10 30 30) [:warp :lens]] - d (drawn (shapes wall line glass)) - across (row d 20 17 24)] - (is (= [2 2 2 2 4 2 2 2 2] (row (drawn (shapes wall line)) 20 16 25)) "one pixel without the lens") - (is (= 1 (count (filter #{4} across))) (str "and one under it: " across)))) - -(deftest a-lens-bulges-and-has-no-seam - ;; A round glass of radius 10 about (50, 50): magnified in the middle, as it - ;; is at its rim and outside it, and squeezed in between. - (let [ring (into [] (mapcat #(let [t (* % (/ js/Math.PI 16))] - [(* 10 (js/Math.cos t)) (* 10 (js/Math.sin t))])) - (range 32)) - op (fn [a] {:kind :poly :pts (js/Float64Array. (clj->js (map-indexed #(+ %2 50) ring))) - :n 32 :warp :lens :amount a - :m (js/Float64Array. #js [1 0 0 1 50 50])}) - shows (fn [a x] (aget ((warp/field (op a)) (js/Float64Array. 2) x 50) 0)) - near? (fn [a b] (< (js/Math.abs (- a b)) 1e-9))] - (is (< (js/Math.abs (- 50.5 (shows 1 51))) 0.01) "twice the size at the middle: one pixel out shows half of one") - (is (near? 60 (shows 1 60)) "as it is at the rim, so the edge meets what is outside it") - (is (near? 63 (shows 1 63)) "and outside it") - (is (< (- (shows 1 54) (shows 1 53)) 1) "magnified across its middle two thirds") - (is (> (- (shows 1 59.5) (shows 1 58.5)) 1) "and squeezed round the curve at it") - (is (> (shows -0.5 51) 51) "below 0 it pinches") - (is (near? 55 (shows 0 55)) "and at 0 it is not there"))) - -(deftest a-warp-at-amount-zero-is-not-there - ;; Amount 0 is untouched for every kind, which is what lets a tween from 0 - ;; bring any of them in from nothing. - (let [plain (vec (:buf (:ras (drawn (shapes wall dot mark)))))] - (doseq [kind (keys node/warp-defaults)] - (let [doc (-> (shapes wall dot [:glass (sq 4 4 36 36) [:warp kind]] mark) - (assoc-in [:symbols :main :nodes :glass :channels [:warp :amount]] - (ch/framed 0.0)))] - (is (= plain (vec (:buf (:ras (drawn doc))))) (str kind " at 0")))))) - -(deftest every-warp-moves-what-is-under-it - ;; A bar near the glass's edge as well as the dot in its middle: a funhouse - ;; mirror hardly moves the middle of itself. - (let [bar [:bar (sq 30 4 32 36) 4] - plain (vec (:buf (:ras (drawn (shapes wall dot bar mark)))))] - (doseq [kind (keys node/warp-defaults)] - (is (not= plain (vec (:buf (:ras (drawn (shapes wall dot bar [:glass (sq 4 4 36 36) [:warp kind]] mark)))))) - (str kind " at its defaults moves something"))))) - -(deftest a-warps-parameters-are-channels-its-colour-gives-it - (let [doc (shapes wall lens) - n (get-in doc [:symbols :main :nodes :lens]) - tile (assoc-in n [:channels [:style :color]] (ch/keyed {0 [:warp :lens] 3 [:warp :tiles]} :hold))] - (is (= (ch/framed 1.0) (get (node/channels n) [:warp :amount])) - "a lens has an amount, as a sound has a gain, without storing one") - (is (nil? (get (node/channels n) [:warp :size])) "and nothing it does not read") - (is (nil? (get (node/channels (get-in doc [:symbols :main :nodes :wall])) [:warp :amount])) - "a shape in a slot has none") - (is (contains? (node/channels tile) [:warp :size]) - "a colour keyed from one warp to another has what both read") - (is (empty? (node/problems (assoc-in n [:channels [:warp :amount]] (ch/keyed {0 0.0 4 2.0} :linear)))) - "and keying one is a valid node") - (is (= #{2} (pal/slots-used (vals (:symbols doc)))) "a warp names no slot"))) - -(deftest a-keyed-amount-tweens-the-warp - (let [doc (-> (shapes wall dot lens) - (assoc-in [:symbols :main :nodes :lens :channels [:warp :amount]] - (ch/keyed {0 0.0 2 2.0} :linear))) - frame (fn [f] (let [ops ((clip/resolver doc :main nil (pal/compile doc) nil) f)] - (raster/draw-ops! (raster/clear! (raster/make 320 200) 0) ops))) - wide (fn [f] (count (filter #(= 4 (aget (:buf (frame f)) (+ % (* 21 320)))) (range 10 30))))] - (is (= [2 4 5] (mapv wide [0 1 2])) - "wider through the tween: 2× and 3× in the middle, easing off toward the rim"))) - -(deftest a-lens-in-a-symbol-magnifies-what-is-outside-the-symbol - ;; The point of a lens is to go BETWEEN things, so a lens a symbol holds sees - ;; everything drawn under that symbol, not only what the symbol draws. And it - ;; is a field in its shape's space: placed at (20, 20) twice the size, the - ;; symbol's 10px glass covers 20px about (20, 20). - (let [base (shapes wall dot) - doc (-> base - (assoc-in [:symbols :glass] - {:id :glass :frames 1 - :nodes {:lens {:id :lens :kind :poly :z "a" - :channels {[:geom :pts] (ch/framed (sq -5 -5 5 5)) - [:style :color] (ch/framed [:warp :lens])}}}}) - (assoc-in [:symbols :main :nodes :held] - {:id :held :kind :instance :z "z9" :source {:symbol :glass} - :playback {:in 0 :speed 0 :end :hold} - :channels {[:xform :pos] (ch/framed [20 20]) - [:xform :scale] (ch/framed [2 2])}})) - d (drawn doc)] - (is (= [2 2 4 4 4 4 2] (row d 21 18 25)) "the root's dot, magnified by the symbol's lens"))) - -(deftest a-warp-in-a-layer-moves-holes-with-marks - ;; A symbol that knocks out is drawn into a layer of its own, and what is - ;; under its lens is only what it drew — holes included. - (let [doc (-> (shapes wall dot - [:hole (sq 20 18 22 20) :clear] - lens) - (assoc-in [:symbols :main :nodes :wall :channels [:style :color]] (ch/framed 3))) - d (drawn doc)] - (is (= [3 3 0 0 0 0 3] (row d 17 18 25)) - "the knocked out pixels are magnified as holes onto the background"))) - -(deftest a-warp-in-part-of-the-work-area-is-the-same-warp - ;; The editor rasterises what is on screen, which need not start at the - ;; stage's corner. The same pixels come out wherever the raster starts. - (let [doc (shapes wall dot lens mark) - full (drawn doc) - part (drawn doc (assoc (raster/make 30 30) :origin [8 8]))] - (is (= (row full 21 10 30) - (mapv #(aget (:buf (:ras part)) (+ (- % 8) (* (- 21 8) 30))) (range 10 30)))))) - -(deftest a-warp-of-no-kind-is-loud - (is (= 255 (at (drawn (shapes wall [:glass (sq 4 4 36 36) [:warp :teleport]])) 20 20)) - "magenta, as a slot the palette lacks is")) diff --git a/static/arthur/app.css b/static/arthur/app.css index b8fd3e6..2a4d237 100644 --- a/static/arthur/app.css +++ b/static/arthur/app.css @@ -1866,17 +1866,6 @@ button.tl-gap:hover { background: rgba(47, 111, 192, .28); } background: linear-gradient(135deg, #3a3f52 0 50%, #e8d9a8 50% 100%); color: #fff; font-size: 11px; line-height: 1; text-shadow: 0 1px 1px rgba(0, 0, 0, .6); } -/* A warp: glass, which shows what is behind it from somewhere else. */ -.palette-grid .cell.warp, -.palette-grid .chip.warp, -.swatch.warp { - display: grid; place-items: center; - background: linear-gradient(160deg, #e9f3f7 0 45%, #b9d3de 100%); - color: #22303a; -} -.palette-grid .cell.warp svg { width: 11px; height: 11px; } -.palette-grid .chip.warp svg { width: 18px; height: 18px; } -.swatch.warp svg { width: 10px; height: 10px; } .palette-grid .cell { position: relative; } .palette-grid .cell .badge { position: absolute; right: -2px; bottom: -2px;