mirror of
https://github.com/penpot/penpot.git
synced 2026-11-05 17:40:39 +00:00
- Improve readme - Migrate scene cases to measured commands and remove obsolete descriptors. - Preserve exact camera targets, including very small positive scales. AI-assisted-by: gpt-6.1-sol
69 lines
2.3 KiB
Clojure
69 lines
2.3 KiB
Clojure
;; 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.builder :as sb]
|
|
[benches.render-wasm.declarations :as decl]
|
|
[benches.render-wasm.random :refer [rng-int]]
|
|
[benches.render-wasm.runtime.camera :as camera]))
|
|
|
|
(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 (rng-int rng 20 width)
|
|
y (rng-int rng 20 height)
|
|
r (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)}}]))))
|
|
|
|
|
|
(decl/defscene :plus
|
|
{:description "Plus signs made of two open line subpaths"
|
|
:params-schema schema:params}
|
|
[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)))))
|
|
|
|
(def ^:private base-view {:scale 1 :x 0 :y 0})
|
|
|
|
(decl/defcase :plus/load
|
|
{:params default-params :view base-view :context :fresh :preparation {:render :none}}
|
|
[rtx]
|
|
(camera/load* rtx))
|
|
|
|
(decl/defcase :plus/pan
|
|
{:params default-params :view base-view :context :reuse
|
|
:reset #(camera/restore % (get-in % [:case :view]))}
|
|
[rtx]
|
|
(camera/pan* rtx {:steps 20 :dx 140 :dy 60 :settle-ms 100}))
|
|
|
|
(decl/defcase :plus/zoom
|
|
{:params default-params :view base-view :context :reuse
|
|
:reset #(camera/restore % (get-in % [:case :view]))}
|
|
[rtx]
|
|
(camera/zoom* rtx {:steps 20 :factor 1.4 :settle-ms 100}))
|