Anima
A Processing-style microframework for drawing, backed by Cairo.
Sketches receive a Cairo context to draw into. Anima tracks fill and stroke colors as module-level state, and each shape function applies them automatically (fill first, then stroke).
(load "anima.carp")
(use Anima)
(defn setup [cr]
(framerate 0))
(defn draw [cr]
(do
(stroke-color 255)
(line cr 0.0 0.0 800.0 800.0)))
(defsketch "One line" 800 800
setup
draw)
arc
(Fn [(Ptr CairoContext), Double, Double, Double, Double, Double] ())
(arc cr cx cy r a1 a2)
Draw an arc centered at (cx, cy) with radius r from a1 to a2 radians. Stroke only.
bezier
(Fn [(Ptr CairoContext), Double, Double, Double, Double, Double, Double, Double, Double] ())
(bezier cr x1 y1 cx1 cy1 cx2 cy2 x2 y2)
Draw a cubic Bezier curve from (x1, y1) through control points
(cx1, cy1) and (cx2, cy2) to (x2, y2). Stroke only.
circle
(Fn [(Ptr CairoContext), Double, Double, Double] ())
(circle cr cx cy r)
Draw a circle centered at (cx, cy) with radius r.
ellipse
(Fn [(Ptr CairoContext), Double, Double, Double, Double] ())
(ellipse cr cx cy rx ry)
Draw an ellipse centered at (cx, cy) with radii rx and ry.
framerate
(Fn [Int] ())
(framerate n)
Set the framerate to n frames per second.
This will set a maximum, but cannot guarantee that exactly n frames can be
produced per second. Set to 0 for a static sketch that draws once.
hsb-to-rgb
(Fn [Int, Int, Int] (Array Int))
(hsb-to-rgb ih is ib)
Convert a three-component HSB color to an RGB color array.
line
(Fn [(Ptr CairoContext), Double, Double, Double, Double] ())
(line cr x1 y1 x2 y2)
Draw a line from (x1, y1) to (x2, y2). Stroke only.
point
(Fn [(Ptr CairoContext), Double, Double] ())
(point cr x y)
Draw a single point at (x, y). Uses a 1-pixel filled circle.
push
(Fn [(Ptr CairoContext)] ())
(push cr)
Save the current Cairo state (transforms, clip, source, line style).
rect
(Fn [(Ptr CairoContext), Double, Double, Double, Double] ())
(rect cr x y w h)
Draw a rectangle at (x, y) with width w and height h.
rotate
(Fn [(Ptr CairoContext), Double] ())
(rotate cr angle)
Rotate the coordinate system by angle radians.
save-png
(Fn [(Ptr CairoSurface), (Ref String a)] ())
(save-png surf filename)
Write the Cairo surface to a PNG file.
scale
(Fn [(Ptr CairoContext), Double, Double] ())
(scale cr sx sy)
Scale the coordinate system by (sx, sy).
set-background
(Fn [(Ptr CairoContext), Int, Int, Int, Int] ())
(set-background cr r g b a)
Clear the surface with an RGBA color (0..255 components).
set-fill
(Fn [Int, Int, Int, Int] ())
(set-fill r g b a)
Set the fill color using RGBA components in 0..255.
set-stroke
(Fn [Int, Int, Int, Int] ())
(set-stroke r g b a)
Set the stroke color using RGBA components in 0..255.
text
(Fn [(Ptr CairoContext), (Ref String a), Double, Double] ())
(text cr s x y)
Draw s at position (x, y) using the current fill color.
text-font
(Fn [(Ptr CairoContext), (Ref String a)] ())
(text-font cr family)
Set the font face by family name (e.g. "monospace").
text-size
(Fn [(Ptr CairoContext), Double] ())
(text-size cr size)
Set the font size in points.
translate
(Fn [(Ptr CairoContext), Double, Double] ())
(translate cr x y)
Translate the coordinate origin by (x, y).
triangle
(Fn [(Ptr CairoContext), Double, Double, Double, Double, Double, Double] ())
(triangle cr x1 y1 x2 y2 x3 y3)
Draw a triangle with vertices (x1, y1), (x2, y2), (x3, y3).