Shaper - a crude DSL for basic image creation
Shaper is a DSL that can be used to produce images containing simple shapes.
The provided compiler produces square shaped images. An image contains several rows of different shapes (triangles, circles, squares). The resulting image looks like a table of shapes.
Shaper language is very basic and does not have safeguards. It should be used as it is intended.
- The source code must be a one-linear that begins with a positive integer denoting the resolution of the output image (Eg:
- The size of the shapes follows (Eg:
- The image description starts after the begin sequence
- Individual rows are separated by pipe
|. There is no pipe after
>>>or in front of
- Individual shapes are separated by coma
,. A row must not begin with a coma or end with a coma.
- The row is then made up of a list of shapes(
- The code finishes with the end sequence
How to use it
- Clone the repo
You'll find the uber-jar in
Generate a file like this:
java -cp shaper.jar com.cosminsanda.shaper.compiler.Shaper2Image --source-code "img_dim:180,shp_dim:32>>>circle,square|triangle<<<" --out-filename test.png
java -cp shaper.jar com.cosminsanda.shaper.compiler.Shaper2Image --source-file /Users/cosmin/test.shape
This will create an image
java -cp shaper.jar com.cosminsanda.shaper.compiler.Shaper2Image --source-dir /Users/cosmin/shapes
This will create images with a file name pattern similar to the one for single file above.
test002.shape file content:
Kotlin code that useses the external
test002.shape file to produce a
val code = FileInputStream(File("test001.shape")) val res = Shaper2Image().compile(code) val img = ImageIO.read(ByteArrayInputStream(res)) val outputfile = File("myshape.png") ImageIO.write(img, "png", outputfile)