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

defn

(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

defn

(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

defn

(Fn [(Ptr CairoContext), Double, Double, Double] ())

                        (circle cr cx cy r)
                    

Draw a circle centered at (cx, cy) with radius r.

ellipse

defn

(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.

fill-a

def

Double

fill-b

def

Double

fill-g

def

Double

fill-on

def

Bool

fill-r

def

Double

fr

def

Int

framerate

defn

(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

defn

(Fn [Int, Int, Int] (Array Int))

                        (hsb-to-rgb ih is ib)
                    

Convert a three-component HSB color to an RGB color array.

line

defn

(Fn [(Ptr CairoContext), Double, Double, Double, Double] ())

                        (line cr x1 y1 x2 y2)
                    

Draw a line from (x1, y1) to (x2, y2). Stroke only.

no-fill

defn

(Fn [] ())

                        (no-fill)
                    

Disable filling for subsequent shapes.

no-stroke

defn

(Fn [] ())

                        (no-stroke)
                    

Disable stroking for subsequent shapes.

point

defn

(Fn [(Ptr CairoContext), Double, Double] ())

                        (point cr x y)
                    

Draw a single point at (x, y). Uses a 1-pixel filled circle.

pop

defn

(Fn [(Ptr CairoContext)] ())

                        (pop cr)
                    

Restore the most recently pushed Cairo state.

push

defn

(Fn [(Ptr CairoContext)] ())

                        (push cr)
                    

Save the current Cairo state (transforms, clip, source, line style).

rand

defn

(Fn [Int] Int)

                        (rand i)
                    

Generate a random integer from 0 to i.

rect

defn

(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

defn

(Fn [(Ptr CairoContext), Double] ())

                        (rotate cr angle)
                    

Rotate the coordinate system by angle radians.

save-png

defn

(Fn [(Ptr CairoSurface), (Ref String a)] ())

                        (save-png surf filename)
                    

Write the Cairo surface to a PNG file.

scale

defn

(Fn [(Ptr CairoContext), Double, Double] ())

                        (scale cr sx sy)
                    

Scale the coordinate system by (sx, sy).

set-background

defn

(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

defn

(Fn [Int, Int, Int, Int] ())

                        (set-fill r g b a)
                    

Set the fill color using RGBA components in 0..255.

set-stroke

defn

(Fn [Int, Int, Int, Int] ())

                        (set-stroke r g b a)
                    

Set the stroke color using RGBA components in 0..255.

stroke-a

def

Double

stroke-b

def

Double

stroke-g

def

Double

stroke-on

def

Bool

stroke-r

def

Double

stroke-w

def

Double

stroke-weight

defn

(Fn [Double] ())

                        (stroke-weight w)
                    

Set the stroke width in pixels.

text

defn

(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

defn

(Fn [(Ptr CairoContext), (Ref String a)] ())

                        (text-font cr family)
                    

Set the font face by family name (e.g. "monospace").

text-size

defn

(Fn [(Ptr CairoContext), Double] ())

                        (text-size cr size)
                    

Set the font size in points.

translate

defn

(Fn [(Ptr CairoContext), Double, Double] ())

                        (translate cr x y)
                    

Translate the coordinate origin by (x, y).

triangle

defn

(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).