Skip to content

Commit

Permalink
[#54] Implement save-frame
Browse files Browse the repository at this point in the history
  • Loading branch information
jfacorro committed Oct 26, 2023
1 parent 2c9024e commit 1c54c8f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/doodler/core.clje
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,22 @@
[filename]
(p/save *canvas* (str filename)))

(declare frame-count)

(defn save-frame
"Saves an image identical to the current display window as a
file. May be called multple times - each file saved will have a
unique name. Name and image formate may be modified by passing a
string parameter of the form \"foo-####.ext\" where foo- can be any
arbitrary string, #### will be replaced with the current frame id
and .ext is one of .tiff, .targa, .png, .jpeg or .jpg

Examples:
(save-frame)
(save-frame \"pretty-pic-####.jpg\")"
([] (p/save-frame *canvas* (frame-count)))
([name] (p/save-frame *canvas* (frame-count) (str name))))

;; Stroke & fill

(defn- save-current-stroke
Expand Down
14 changes: 10 additions & 4 deletions src/doodler/examples/image.clje
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@
(let [img (d/load-image "resources/pacman.png")
img (d/resize img 20 20)]
(d/image img 50 50)
;; println :color-panel (d/get-pixel 10 10)
;; :color-img (d/get-pixel img 5 5)
;; :subimage-pane (d/get-pixel 5 5 5 5)
;; :subimage-img (d/get-pixel img 5 5 5 5))
(when (< 20 (d/frame-count) 30)
(println :color-panel (d/get-pixel 10 10)
:color-img (d/get-pixel img 5 5)
:subimage-pane (d/get-pixel 5 5 5 5)
:subimage-img (d/get-pixel img 5 5 5 5)))
;; Test save-image
(when (< 10 (d/frame-count) 20)
(d/save-frame)
(d/save-frame "screen-#######.jpg"))
;; Test save
(when (= (d/frame-count) 200)
(println "Saving files...")
(d/save "foo.jpg")
Expand Down
3 changes: 2 additions & 1 deletion src/doodler/protocols.clje
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
(get-pixel [this] [this img] [this x y] [this img x y] [this x y w h] [this img x y w h])
(pixels [this] [this img])
(resize [this img w h])
(save [this filename]))
(save [this filename])
(save-frame [this frame-count] [this frame-count name]))

(defprotocol IPrimitives
(arc [this x y w h start end])
Expand Down
11 changes: 11 additions & 0 deletions src/doodler/wx/panel.clje
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@
(println "Unsupported extension" ext ", using TIFF")
gui/bitmap-type-tif))]
(wxBitmap/saveFile bitmap filename bitmap-type)))
(save-frame [this frame-count]
(p/save-frame this frame-count "screen-####.tif"))
(save-frame [this frame-count name]
(let [pounds (re-find #"#+" name)
frame-count (str frame-count)
pad-left (repeat (- (count pounds)
(count frame-count))
"0")
n (str (apply str pad-left) frame-count)
filename (str/replace name #"#+" n)]
(p/save this filename)))

p/IPrimitives
(arc [_this x y w h start end]
Expand Down

0 comments on commit 1c54c8f

Please sign in to comment.