Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 8b0fd5800f
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 172 lines (145 sloc) 5.953 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
(ns dali.test
  (:use [dali.core]
        [dali.style]
        [dali.math]
        [dali.backend]
        [dali.backend.java-2d])
  (:require [dali.dev :as dev])
  (:import [java.awt.geom CubicCurve2D$Double Path2D$Double AffineTransform]))

#_(dev/watch-image #(test-dali))
(def img (ref (buffered-image [500 500])))

(defn mark-point [backend point]
  (draw backend (circle point 5)))

(defn test-dali [& args]
  (let [triangle (polygon [50 150] [75 90] [100 150])
        my-line (line [110 100] [170 80])

        line1 (line [10 70] [90 80])
        line2 (line [10 120] [90 60])
        line3 (line [20 120] [20 60])

        cloud-icon (load-image (image-data :file "data/cloud_icon.png"))
        texture (load-image (image-data :file "data/texture.png"))

        backend (image-backend @img)]
    ;(.setPaint (.graphics backend) java.awt.Color/WHITE)
    (.setRenderingHint (.graphics backend)
                       java.awt.RenderingHints/KEY_ANTIALIASING
                       java.awt.RenderingHints/VALUE_ANTIALIAS_ON)

    #_(println
       (.getStringBounds
        dali.backend.java-2d/*DEFAULT-FONT*
        "Stathis"
        (.getFontRenderContext (.graphics backend))))

    #_(println (text-bounds backend (text [100 100] "Stathis")))
    
    (doto backend
      (set-paint (color 0 0 0))
      (fill (rectangle [0 0] [(.getWidth @img) (.getHeight @img)]))
      (set-paint (color 0 220 0)))

    (doto backend
      (render-text (text {:fill (color 150 0 150)
                          :transform [:translate (dynamic
                                                  (minus (center
                                                          (text-bounds backend this))))
                                      :rotate 10
                                      :translate (dynamic (center
                                                           (text-bounds backend this)))]}
                         [185 25] "Testing the dali library"))
      (render (arrow
               {:stroke {:width 2
                         :color (color 255 255 255)}
                :fill (color 150 20 20)}
               [200 50] [300 80] 20 40 30))

      (draw line1)
      (draw line2)
      (draw line3)
      (mark-point (line-intersection line1 line2))
      (mark-point (line-intersection line1 line3))
      (mark-point (line-intersection line2 line3))

      (draw my-line)
      (draw (parallel my-line 20 :right))

      ;(mark-point (interpolate [110 100] [170 110] 0.5))

      (draw (line [0 0] [50 50]))
      (draw (circle [0 0] 50))
      (draw (point 120 120))
      (draw (circle [0 0] 55))
      (render
       (rectangle {:stroke {:width 8
                            :color (color 0 130 0)
                            :join :miter}
                   :transform [:translate (dynamic (minus (center this)))
                               :skew [0.2 0.2]
                               :scale 0.8
                               :rotate 30
                               :translate (dynamic (center this))]}
                  [330 170] [100 70]))

      (draw (rotate-around (rectangle [160 100] [60 60])
                           60
                           (center (rectangle [160 100] [60 60]))))

      (draw (circle [70 300] 50))
      (render
       (circle
        {:stroke {:color (color 0 0 0)}
         :fill (radial-gradient [60 290] 35
                                0.2 (color 100 230 100)
                                1.0 (color 0 60 0))}
        [70 300] 30))

      (fill (rotate-around triangle 15 (center triangle)))

      (draw (polyline [400 50] [420 30] [440 50] [460 30]))
      (draw (parallel (polyline [400 50] [420 30] [440 50] [460 30]) 5 :right))
      (draw (parallel (polyline [400 50] [420 30] [440 50] [460 30]) 10 :left))

      (draw (polygon [430 100] [420 150] [460 150]))
      (draw (parallel (polygon [430 100] [420 150] [460 150]) 5 :right))
      (draw (parallel (polygon [430 100] [420 150] [460 150]) 10 :left))
      
      (draw (curve [100 200] [100 0] [100 40] [50 40]))
      (render
       (group {:stroke {:color (color 255 255 255)
                        :width 3}
               :fill (color 120 120 200)
               }
        (rounded-rect
         {:stroke {:dash [10 15]}
          :fill (linear-gradient
                 [155 305] [170 395]
                 0.2 (color 100 230 100)
                 0.5 (color 0 170 0)
                 0.9 (color 0 60 0))}
         [175 290] [140 90] 20)
        (rounded-rect
         {;:fill (fn [_] (let [r (int (rand 160))] (color r 0 0)))
          }
         [370 290] [40 90] 10)

        (arrow {:stroke {:width 2}}
               (translate
                (center (right-bound (rectangle [175 290] [140 90])))
                [10 0])
               (translate
                (center (left-bound (rectangle [370 290] [40 90])))
                [-10 0])
               12 28 20)))

      (render
       (path {:stroke {:color (color 220 220 220)
                       :width 2}
              :fill (image-texture texture)}
             :move-to [175 415]
             :quad-by [0 -20] [20 -20]
             :line-by [100 0]
             :quad-by [20 0] [20 20]
             :line-by [0 50]
             :quad-by [0 20] [-20 20]
             :line-by [-100 0]
             :quad-by [-20 0] [-20 -20]
             :close))

      (render (image cloud-icon [40 410])))

      ;(draw (path :move-to [20 200] :line-to [50 200]))
      ;(set-paint (color 0 100 0))


    (let [r (rectangle [200 200] [100 50])
          l1 (line [220 180] [280 270])
          l2 (line [180 210] [320 240])
          intersections1 (line-rectangle-intersection l1 r)
          intersections2 (line-rectangle-intersection l2 r)]
      (doto backend
        (set-paint (color 0 220 0))
        (draw r)
        (draw l1)
        (draw l2))
      (doseq [i (concat intersections1 intersections2)]
        (mark-point backend i))))
  @img)
Something went wrong with that request. Please try again.