Skip to content

Commit

Permalink
add keyword render modes to create-graphics. Also allow modes to be p…
Browse files Browse the repository at this point in the history
…assed as a constant in addition to their keyword shortcuts
  • Loading branch information
samaaron committed Jun 7, 2012
1 parent a513fbd commit f49b9eb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
28 changes: 14 additions & 14 deletions src/quil/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -963,38 +963,38 @@
([name size smooth ^chars charset]
(.createFont (current-applet) (str name) (float size) smooth charset)))

(def ^{:private true}
graphic-render-modes
(select-keys render-modes [:p2d :p3d :java2d :pdf]))

(defn
^{:requires-bindings true
:processing-name "createGraphics()"
:category "Rendering"
:subcategory nil
:added "1.0"}
create-graphics
"Creates and returns a new PGraphics object of the types P2D, P3D,
and JAVA2D. Use this class if you need to draw into an off-screen
graphics buffer. It's not possible to use create-graphics with
the OPENGL renderer, because it doesn't allow offscreen use. The
PDF renderer requires the filename parameter. The DXF renderer
should not be used with create-graphics, it's only built for use
with begin-raw and end-raw.
"Creates and returns a new PGraphics object of the types :p2d, :p3d,
:java2d, :pdf. Use this class if you need to draw into an off-screen
graphics buffer. It's not possible to use create-graphics with the
:opengl renderer, because it doesn't allow offscreen use. The :pdf
renderer requires the filename parameter.
It's important to call any drawing commands between begin-draw and
end-draw statements. This is also true for any commands that affect
drawing, such as smooth or colorMode.
drawing, such as smooth or color-mode.
Unlike the main drawing surface which is completely opaque, surfaces
created with create-graphics can have transparency. This makes it
possible to draw into a graphics and maintain the alpha channel. By
using save to write a PNG or TGA file, the transparency of the
graphics object will be honored. Note that transparency levels are
binary: pixels are either complete opaque or transparent. For the
time being (as of release 1.2.1), this means that text characters
will be opaque blocks. This will be fixed in a future release (Issue
80)."
binary: pixels are either complete opaque or transparent. This means
that text characters will be opaque blocks."
([w h renderer]
(.createGraphics (current-applet) (int w) (int h) renderer))
(.createGraphics (current-applet) (int w) (int h) (resolve-constant-key renderer graphic-render-modes)))
([w h renderer path]
(.createGraphics (current-applet) (int w) (int h) renderer (str path))))
(.createGraphics (current-applet) (int w) (int h) (resolve-constant-key renderer graphic-render-modes) (str path))))

(defn
^{:requires-bindings true
Expand Down
13 changes: 7 additions & 6 deletions src/quil/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
(= java.lang.Integer t))))

(defn resolve-constant-key
"Returns the val associated with key in mappings or key directly if it
is one of the vals in mappings. Otherwise throws an exception."
[key mappings]
(when-not (keyword? key)
(throw (Exception. (str "Expecting a keyword, got: " key))))

(if-let [const (get mappings key)]
const
(throw (Exception. (str "Mode constant not found matching key: " key ". Expected one of: " (vec (sort (keys mappings))))))))
(cond
(get mappings key) (get mappings key)
(some #{key} (vals mappings)) key
:else (throw (Exception.
(str "Expecting a keyword, got: " key ". Expected one of: " (vec (sort (keys mappings))))))))


(defn length-of-longest-key
Expand Down

0 comments on commit f49b9eb

Please sign in to comment.