🚧 WIP Step 19 New scenes, use camera

This commit is contained in:
Miguel de Benito Delgado 2026-10-02 12:08:20 +02:00
parent 0eeba84af6
commit 494abd17dd
4 changed files with 141 additions and 6 deletions

View File

@ -40,6 +40,9 @@
(:require
[app.common.schema :as sm]
[benches.render-wasm.scenes.core :as core]
benches.render-wasm.scenes.masks
benches.render-wasm.scenes.paths
benches.render-wasm.scenes.plus
benches.render-wasm.scenes.rects
[clojure.string :as str]))

View File

@ -0,0 +1,60 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS SUBSIDIARY SL
(ns benches.render-wasm.scenes.masks
"Fixed grid of masked groups with circle masks and ordered descendants."
(:require
[benches.render-wasm.scenes.builder :as sb :include-macros true]
[benches.render-wasm.scenes.camera :as camera]
[benches.render-wasm.scenes.core :as core :include-macros true]))
(def ^:private default-params
{:width 1920 :height 1080})
(def ^:private schema:params
[:map {:closed true}
[:width [:int {:min 1920}]]
[:height [:int {:min 1080}]]])
(defn build
[params]
(let [params (merge default-params params)]
(sb/scene {:seed (:seed params)
:root {:x 0 :y 0 :width (:width params) :height (:height params)}}
(doseq [i (range 24)]
(let [x (+ 25 (* 310 (mod i 6)))
y (+ 25 (* 255 (quot i 6)))]
(sb/group [:mask i] {:masked-group true}
(sb/circle {:x x :y y :width 180 :height 180
:fills [{:fill-color "#ffffff"}]})
(doseq [j (range 8)]
(sb/rect {:x (+ x (* 28 j) -22)
:y (- y 12)
:width 25
:height 205
:fills [{:fill-color (if (even? j) "#1254b8" "#ff8b38")}]}))))))))
(core/defscene :masks
{:version 1
:description "Twenty-four circle masks with ordered striped descendants"
:params-schema schema:params}
build)
(def ^:private base-view {:scale 1 :x 0 :y 0})
(core/defcase :masks/load :masks
{:params default-params :view base-view :context :fresh}
(fn [rtx] (camera/load! rtx)))
(core/defcase :masks/pan :masks
{:params default-params :view base-view :context :reuse
:operation {:steps 20 :dx 120 :dy 40 :settle-ms 100}}
(fn [rtx] (camera/pan! rtx)))
(core/defcase :masks/zoom :masks
{:params default-params :view base-view :context :reuse
:operation {:steps 20 :factor 1.6 :settle-ms 100}}
(fn [rtx] (camera/zoom! rtx)))

View File

@ -0,0 +1,67 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS SUBSIDIARY SL
(ns benches.render-wasm.scenes.plus
"Plus signs made of two open line subpaths"
(:require
[app.common.types.path :as path]
[benches.render-wasm.scenes.builder :as sb :include-macros true]
[benches.render-wasm.scenes.camera :as camera]
[benches.render-wasm.scenes.core :as core :include-macros true]))
(def ^:private default-params
{:count 1000 :width 1920 :height 1080})
(def ^:private schema:params
[:map {:closed true}
[:count [:int {:min 1 :max 100000}]]
[:width [:int {:min 100}]]
[:height [:int {:min 100}]]])
(defn- plus-content
[{:keys [width height]}]
(fn [rng]
(let [x (sb/rng-int rng 20 width)
y (sb/rng-int rng 20 height)
r (sb/rng-int rng 10 40)]
(path/from-plain
[{:command :move-to :params {:x (- x r) :y y}}
{:command :line-to :params {:x (+ x r) :y y}}
{:command :move-to :params {:x x :y (- y r)}}
{:command :line-to :params {:x x :y (+ y r)}}]))))
(defn build
[params]
(let [params (merge default-params params)]
(sb/scene {:seed (:seed params)
:root {:x 0 :y 0 :width (:width params) :height (:height params)}
:defaults {:path {:content (plus-content params)
:fills []
:strokes (sb/gen-vector (sb/gen-stroke 4))}}}
(doseq [_ (range (:count params))]
(sb/path)))))
(core/defscene :plus
{:version 1
:description "Plus signs made of two open line subpaths"
:params-schema schema:params}
build)
(def ^:private base-view {:scale 1 :x 0 :y 0})
(core/defcase :plus/load :plus
{:params default-params :view base-view :context :fresh}
(fn [rtx] (camera/load! rtx)))
(core/defcase :plus/pan :plus
{:params default-params :view base-view :context :reuse
:operation {:steps 20 :dx 140 :dy 60 :settle-ms 100}}
(fn [rtx] (camera/pan! rtx)))
(core/defcase :plus/zoom :plus
{:params default-params :view base-view :context :reuse
:operation {:steps 20 :factor 1.4 :settle-ms 100}}
(fn [rtx] (camera/zoom! rtx)))

View File

@ -11,12 +11,12 @@
fills and centered strokes, all drawn from the scope's seeded generator.
`build` produces the scene snapshot; `defscene` and `defcase` declare
the scene and its standard cases. The three cases share parameters, so
they render the same scene. The path and effect scenes arrive in
tickets 07/08. The bridge supplies the current pan and zoom gestures;
scene case bodies arrive with ticket 14."
they render the same scene. Each case body runs through the compiled
browser executor; collection keeps only plain descriptors."
(:require
[app.common.schema :as sm]
[benches.render-wasm.scenes.builder :as sb :include-macros true]
[benches.render-wasm.scenes.camera :as camera]
[benches.render-wasm.scenes.core :as core :include-macros true]))
;; This namespace is also loaded by Node discovery. Keep operation helpers
@ -86,16 +86,21 @@
(core/defcase :rects/load :rects
{:params default-params
:view base-view
:context :fresh})
:context :fresh}
(fn [rtx] (camera/load! rtx)))
(core/defcase :rects/pan :rects
{:params default-params
:view base-view
:context :reuse
:completion :render-full})
:completion :render-full
:operation {:steps 20 :dx 200 :dy 0 :settle-ms 100}}
(fn [rtx] (camera/pan! rtx)))
(core/defcase :rects/zoom :rects
{:params default-params
:view base-view
:context :reuse
:completion :render-full})
:completion :render-full
:operation {:steps 20 :factor 1.5 :settle-ms 100}}
(fn [rtx] (camera/zoom! rtx)))