https://github.com/mastersign/pencil
A lightweight 2D graphics library for Clojure and ClojureScript.
https://github.com/mastersign/pencil
Last synced: 10 months ago
JSON representation
A lightweight 2D graphics library for Clojure and ClojureScript.
- Host: GitHub
- URL: https://github.com/mastersign/pencil
- Owner: mastersign
- License: epl-1.0
- Created: 2016-09-05T14:51:07.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-07-22T08:59:29.000Z (about 9 years ago)
- Last Synced: 2025-07-25T00:53:05.280Z (about 1 year ago)
- Language: Clojure
- Size: 68.4 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# pencil
[![Clojars Project][clojars-img]][clojars-url]
> A lightweight 2D graphics library for Clojure and ClojureScript.
## Usage
This library can be used with _Clojure_ for `java.awt.Graphics2D`
and with _ClojureScript_ for `CanvasRenderingContext2D`.
At first, add `[pencil "0.1.0"]` to the dependencies in your `project.clj`.
Then implement a sketch function:
```clj
(ns my-namespace.sketch
(:require [net.kiertscher.draw.pencil :as pencil]))
(defn my-sketch
[ctx]
(doto ctx
(pencil/draw-rect 10 10 80 60)
(pencil/set-fill-style (p/fill-style (p/color 0.0 0.3 1.0)))
(pencil/fill-arc 50 40 15)))
```
### Clojure
Call `render-in-file` to render the sketch into an image file.
```clj
(ns my-namespace
(:require [net.kiertscher.draw.pencil.jvm-awt :as pencil-awt]
[my-namespace.sketch :as s]))
(defn -main
[]
(pencil-awt/render-in-file
"/target/path/my-sketch.png" "PNG"
100 80 s/my-sketch))
```
### ClojureScript
Prepare your HTML5 page with a canvas element:
```html
My Sketch
My Sketch
```
Call the `render` function, passing the id of the canvas element:
```clj
(ns my-namespace
(:require [net.kiertscher.draw.pencil.js-canvas :as pencil-jsc]
[my-namespace.sketch :as s]))
(pencil-jsc/render "my-sketch" s/my-sketch)
```
## License
Copyright © 2016 Tobias Kiertscher
Distributed under the Eclipse Public License either version 1.0 or
(at your option) any later version.
[clojars-img]: https://img.shields.io/clojars/v/pencil.svg
[clojars-url]: https://clojars.org/pencil
[latest release]: https://github.com/mastersign/pencil/releases/latest