Created
April 20, 2020 05:07
-
-
Save vigevenoj/3b787c701409de220a6461667e1a0938 to your computer and use it in GitHub Desktop.
javafx semicircle using cljfx
This file contains 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 semicircle.core | |
(:require | |
[cljfx.api :as fx] | |
(:import | |
[javafx.application Platform] | |
[javafx.scene.paint Color] | |
[javafx.scene.canvas Canvas]) | |
(:gen-class)) | |
(def *state | |
(atom {})) | |
;; https://stackoverflow.com/questions/11719005/draw-a-semi-ring-javafx | |
(defn semicircle [centerx centery radius inner-radius bgcolor stroke-color] | |
(let [move-to {:fx/type :move-to | |
:x (+ centerx inner-radius) | |
:y centery} | |
inner-arc {:fx/type :arc-to | |
:x (- centerx inner-radius) | |
:y centery | |
:radius-x inner-radius | |
:radius-y inner-radius} | |
move-to-2 {:fx/type :move-to | |
:x (- centerx inner-radius) | |
:y centery} | |
hline-to-right-leg {:fx/type :h-line-to | |
:x (+ centerx radius)} | |
outer-arc {:fx/type :arc-to | |
:x (- centerx radius) | |
:y centery | |
:radius-x radius | |
:radius-y radius} | |
hline-to-left-leg {:fx/type :h-line-to | |
:x (- centerx inner-radius)} | |
path {:fx/type :path | |
:fill bgcolor | |
:stroke stroke-color | |
:fill-rule :even-odd | |
:elements [move-to inner-arc move-to-2 hline-to-right-leg outer-arc hline-to-right-leg]}] | |
; return it | |
path)) | |
(defn root-view | |
"This defines the root view" | |
[] | |
{:fx/type :stage | |
:width 200 | |
:height 200 | |
:showing true | |
:scene {:fx/type :scene | |
:root {:fx/type :v-box | |
:children [(semicircle 120 120 100 50 :lightgreen :transparent)]}}}) | |
(def renderer | |
(fx/create-renderer | |
:middleware (fx/wrap-map-desc (fn [state] | |
{:fx/type root-view | |
:state state})))) | |
(defn -main [] | |
(Platform/setImplicitExit(true)) | |
(fx/mount-renderer *state renderer) | |
(println "Hello, World!")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment