Skip to content

nekocirno/weir

 
 

Repository files navigation

WEIR-A System for Making Generative Systems

About

This library is specifically written to be useful for a broad range of ways in which I create art using various generative algorithms. It is the next iteration of snek. I made a new version because I wanted to make some significant changes.

Main components:

  1. A simple graph data structure (weir) for working with vertices and edges This structure is combined with a programming pattern for applying changes to the structure. The pattern relies on alterations, see below. You can also manipulate the structure directly.

  2. A series of useful data structures and tools. E.g. 2D/3D vectors vec, a package for generating different kinds of random numbers: rnd, as well as tools for handling colors (pigment), splines (bzspl), and various vector an path functionality (eg. math, lin-path).

  3. Orthogonal projection (ortho).

  4. Some simple raytracing functionality for meshes (mesh) and point clouds (point-cloud).

  5. A tool for drawing, called sandpaint. sandpaint uses random sampling to draw. This creates a fairly distinct and gritty look in many cases.

  6. A tool for drawing svg files (draw-svg). Mainly files that are good for plotting.

Alterations

An alteration is a change that will be applied to the structure at the end of a given context. In many ways this is similar to map/reduce.

Here is and example of manipulating a weir instance called wer using alterations. Alteration constructors are postfixed with ?.

; context start
(weir:with (wer %)
  ; iterate vertices
  (weir:itr-verts (wer v)
    ; move alteration
    ; (% ...) is used to accumulate alterations
    (% (weir:move-vert? v (rnd:in-circ 1d0)))
    ; w will be an arbitrary
    ; vertex in wer
    (weir:with-rnd-vert (wer w)
      ; join v and w if they are closer than d
      (if (< (weir:edge-length wer v w) d)
        ; join vertices alteration
        (% (weir:add-edge? v w)))))
; context end. alterations have been applied

You can also manipulate the state directly. These functions are postfixed with !. Eg. (weir:move-vert! ...). This convention is used in other parts of the code as well.

You can define your own arbitrary alterations. There is an example of this in ex/custom-alt.lisp.

Writing

I have written about things related to this code (when it was called snek) at

Usage

I use weir for most of the work that I post online (https://inconvergent.net/, https://img.inconvergent.net/, https://twitter.com/inconvergent). Both for raster images, as well as vector images for plotter drawings.

Here are some plotted examples:

Installation and Dependencies

This code requires Quicklisp to install dependencies (which are listed in weir.asd). To install and load Weir, do:

(ql:quickload :weir)

If this does not work, Weir may not be in a place Quicklisp or ASDF can see them. To fix this, either

(load "weir.asd")

or for a longer term solution, push the directory in which Weir sits to the variable quicklisp:*local-project-directories*:

;; in your .sbclrc, for example:
#+quicklisp
(push "/path/to/dir/containing/weir" ql:*local-project-directories*)

The fn package (for generating file names) depends on the fn command from https://github.com/inconvergent/fn, but this is not necessary to use any of the other packages.

The code has only been tested in Ubuntu 18.04 LTS with SBCL 2.0.1.

Tests

Run:

(asdf:test-system :weir)

In Case of QL Version Issues

See https://blog.quicklisp.org/2011/08/going-back-in-dist-time.html

Summary:

(use-package :ql-dist)
(available-versions (dist "quicklisp"))
(install-dist
  "https://beta.quicklisp.org/dist/quicklisp/2019-03-07/distinfo.txt"
  :replace t)

Stability, Changes and Versioning

This code is highly experimental on my part. It is likely to change with no warning or explanation. I will keep a note of the version number in weir.asd, but even minor version bumps may contain breaking changes.

On Use and Contributions

This code is written for my personal use. I release it publicly in case people find it useful. It is not however intended as a collaboration/Open Source project. As such I am unlikely to accept PRs, reply to issues, or take requests.

Thanks

I would like to thank:

Who have provided me with useful hints and code feedback.

The ASDF config and test setup was kindly suggested and implemented by Robert Smith (https://twitter.com/stylewarning). The remaining weirdness in the test system is my fault. Hope to fix it properly later.

Also, many thanks to https://twitter.com/xach for making Quicklisp.

About

A system for making generative systems

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Common Lisp 99.8%
  • Other 0.2%