Last active
May 12, 2025 12:30
-
-
Save zikajk/cb2ace293655fb72275ff3b24c1065ca to your computer and use it in GitHub Desktop.
FlowStorm: Debugging and Understanding Clojure Code on a New Level
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns user | |
(:require [quil.core :as q] | |
[flow-storm.api :as fsa])) | |
(defn setup [] | |
(q/frame-rate 1) ;; Set framerate to 1 FPS | |
(q/background 200) | |
(fsa/bookmark "Quil setup function complete")) ;; Set the background colour | |
(defn make-ellipse [x y diam] | |
(q/ellipse x y diam diam)) | |
(defn draw [] | |
(q/stroke (q/random 255)) ;; Set the stroke colour to a random grey | |
(q/stroke-weight (q/random 10)) ;; Set the stroke thickness randomly | |
(q/fill (q/random 255)) ;; Set the fill colour to a random grey | |
(let [diam (q/random 100) ;; Set the diameter to a value between 0 and 100 | |
x (q/random (q/width)) ;; Set the x coord randomly within the sketch | |
y (q/random (q/height))] ;; Set the y coord randomly within the sketch | |
(tap> {:event :circle-drawn, :x x, :y y, :diameter diam}) | |
(make-ellipse x y diam) ;; Draw a circle at x y with the correct diameter | |
)) | |
(q/defsketch fs-example ;; Define a new sketch named example | |
:title "Oh so many grey circles" ;; Set the title | |
:settings #(q/smooth 2) ;; Turn on anti-aliasing | |
:setup setup ;; Specify the setup fn | |
:draw draw ;; Specify the draw fn | |
:size [323 200]) ;; Set the sketch size | |
(require '[flow-storm.debugger.ui.data-windows.visualizers :as viz]) | |
(require '[flow-storm.runtime.values :as fs-values]) | |
(import '[javafx.scene.shape Line] | |
'[javafx.scene.paint Color]) | |
(viz/register-visualizer | |
{:id :stroke | |
:pred (fn [val] (and (map? val) (:quil/stroke val))) | |
:on-create (fn [{:keys [quil/stroke]}] | |
{:fx/node (let [gray (/ (first (:current-stroke stroke)) 255) | |
color (Color/gray gray) | |
line (doto (Line.) | |
(.setStartX 0.0) | |
(.setStartY 0.0) | |
(.setEndX 30) | |
(.setEndY 30) | |
(.setStrokeWidth 5.0) | |
(.setStroke color))] | |
line)})}) | |
(fs-values/register-data-aspect-extractor | |
{:id :stroke | |
:pred (fn [val _] (and (map? val) (:current-stroke val))) | |
:extractor (fn [stroke _] {:quil/stroke stroke})}) | |
(viz/add-default-visualizer (fn [val-data] (:stroke (:flow-storm.runtime.values/kinds val-data))) :stroke) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment