summaryrefslogtreecommitdiff
path: root/doc/picture-language.texi
blob: d4196f1b53d547d5516277aee09a3949c4812c7e (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
\input texinfo
@c -*-texinfo-*-

@c %**start of header
@setfilename picture-language.info
@documentencoding UTF-8
@settitle Guile Picture Language Reference Manual
@c %**end of header

@include version.texi

@copying
Copyright @copyright{} 2019 Ricardo Wurmus@*

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.  A
copy of the license is included in the section entitled ``GNU Free
Documentation License''.
@end copying

@dircategory The Algorithmic Language Scheme
@direntry
* Guile Picture Language: (picture-language).   Compose pictures with Guile.
@end direntry

@titlepage
@title Guile Picture Language Reference Manual
@subtitle Composing pictures with Guile
@author Ricardo Wurmus

@page
@vskip 0pt plus 1filll
Edition @value{EDITION} @*
@value{UPDATED} @*

@insertcopying
@end titlepage

@contents

@c *********************************************************************
@node Top
@top Guile Picture Language

This document describes the Guile Picture Language version
@value{VERSION}, a simple language to compose shapes and pictures using
vector graphics.

@menu
* Introduction::                What is this all about?
* Installation::                Installing the picture language.
* A Picture Vocabulary::        Learning to speak the language.

* Acknowledgments::             Thanks!
* GNU Free Documentation License::  The license of this manual.
* Concept Index::               Concepts.
* Programming Index::           Data types, functions, and variables.
@end menu

@c *********************************************************************
@node Introduction
@chapter Introduction

This package provides a Guile library containing simple procedures to
generate primitive shapes, to manipulate them, and to compose them to
build complex pictures.  While this library could be used to
procedurally generate images, it is really meant to be used
interactively.

Pictures in this language are first class values like numbers or
strings, so they are displayed as actual pictures, not as text.  We
suggest using Guile Studio to play with the picture language, as it
comes with everything you need to play with the picture language
interactively.  You can jump straight to @xref{A Picture Vocabulary} and
follow along.

If you aren't using Guile Studio you will probably want to use a
graphical instance of Emacs and set up Geiser for use with Guile.


@c *********************************************************************
@node Installation
@chapter Installation

The easiest way to install the Picture Language is through GNU Guix.

@example
guix install guile-picture-language
@end example

If you cannot use Guix or want to build it manually from a release
tarball, just unpack it and run the usual GNU build system commands:

@example
./configure
make
make install
@end example

If you want to build the sources from the source repository you need to
bootstrap the build system first.  Run the @code{bootstrap.sh} script
first and then perform the above steps.

Once installed you should make sure that the @code{GUILE_LOAD_PATH}
includes the directory containing this library.  Start a Guile REPL with
Geiser and load up the module with @code{,use(pict)}.  If everything
went well read on to learn how to use the picture language.

If you're getting errors feel free to write email to the Guile user
mailing list @email{guile-user@@gnu.org}, or ask for help on the
@code{#guile} IRC channel on the Freenode network.

@c *********************************************************************
@node A Picture Vocabulary
@chapter A Picture Vocabulary

The goal of the picture language is to allow you to interactively work
with pictures as you would with any other seemingly primitive data type,
such as numbers or strings of text.  To compose numbers in an we use the
digits 0 to 9.  Similarly, strings of text compose of a wide range of
characters enclosed in double quotes.  What, then, are the building
blocks of pictures?

One approach is to think of a picture as an arrangement of little
colored dots or pixels.  Building pictures from dots, however, would be
rather tedious and dull.  It would not be a very expressive language.
Another approach is to start with a small set of simple shapes that can
be modified and combined.  Let's first take a look at the different
kinds of simple shapes that make up the ``nouns'' of our picture
language vocabulary.

@menu
* Simple shapes::  The ``nouns'' of our picture language.
* Modifiers::      Procedures for modifying pictures.
* Combinators::    Build large pictures from smaller pictures.
@end menu

@c *********************************************************************
@node Simple shapes
@section Simple shapes

@cindex line, simple shape
@deffn {Scheme Procedure} line @
  @var{x1} @var{y1} @var{x2} @var{y2} @
  [@var{maxw} @var{maxh} @
  #:color @var{"black"} #:stroke-width @var{1}]

Return a straight line connecting the start point described by the
numbers @var{X1} and @var{Y1} and the end point described by the numbers
@var{X2} and @var{Y2}.  Optionally, the numbers @var{MAXW} and
@var{MAXH} can be provided to limit the width or height, respectively,
of the resulting picture.  The keys @var{COLOR} (a string) and
@var{STROKE-WIDTH} (a number) are accepted to override the line color
and line thickness, respectively.
@end deffn

@cindex line, example
@example
@verbatiminclude images/line.svg.scm
@image{images/line.svg.scm,,,A straight line.}
@end example


@cindex hline, simple shape
@deffn {Scheme Procedure} hline @
  @var{w} @var{h} @
  [#:color @var{"black"} #:stroke-width @var{1}]
  
Return a horizontal line segment of width @var{W}.  The bounding box
height is @var{H} and the line is drawn in the vertical center of the
bounding box.  The keys @var{COLOR} (a string) and @var{STROKE-WIDTH} (a
number) are accepted to override the line color and line thickness.
@end deffn

@cindex hline, example
@example
@verbatiminclude images/hline.svg.scm
@image{images/hline.svg.scm,,,A horizontal line.}
@end example


@cindex vline, simple shape
@deffn {Scheme Procedure} vline @
  @var{w} @var{h} @
  [#:color @var{"black"} #:stroke-width @var{1}]

Return a vertical line segment of height @var{H}.  The bounding box
width is @var{W} and the line is drawn in the horizontal center of the
bounding box.  The keys @var{COLOR} (a string) and @var{STROKE-WIDTH} (a
number) are accepted to override the line color and line thickness.
@end deffn

@cindex vline, example
@example
@verbatiminclude images/vline.svg.scm
@image{images/vline.svg.scm,,,A vertical line.}
@end example


@cindex polyline, simple shape
@deffn {Scheme Procedure} polyline @
  @var{points} @
  [#:color @var{"black"} #:stroke-width @var{1}]

A polyline is a multi-segment line that is drawn through any number of
points.  This procedure draws a polyline from @var{POINTS}, a list of x
and y coordinate pairs.  The keys @var{COLOR} (a string) and
@var{STROKE-WIDTH} (a number) are accepted to override the line color
and line thickness.
@end deffn

@cindex polyline, example
Here is a simple zig zag line:
@example
@verbatiminclude images/polyline.svg.scm
@image{images/polyline.svg.scm,,,A zig zag polyline.}
@end example

Of course, you could also compute the points.  Here we use @code{iota}
and @code{list-tabulate} of the @code{(srfi srfi-1)} module to generate
a list for increasing X coordinates and a list for alternating Y
coordinates before merging them to a single list of coordinate pairs
with @code{map} and @code{cons}:

@example
@verbatiminclude images/polyline2.svg.scm
@image{images/polyline2.svg.scm,,,A longer zig zag polyline.}
@end example


@cindex polygon, simple shape
@deffn {Scheme Procedure} polygon @
  @var{points} @
  [#:color @var{"black"} #:stroke-width @var{1}]

The @code{polygon} procedure has almost the exact same behavior as
@code{polyline}, except that it connects the first point and the last
point with a line segment.  @code{polyline}, on the other hand, leaves
the two points unconnected.

This procedure draws a line through @var{POINTS}, a list of x and y
coordinate pairs, connecting the first and last points.  The keys
@var{COLOR} (a string) and @var{STROKE-WIDTH} (a number) are accepted to
override the line color and line thickness.
@end deffn

@cindex polygon, example
Here is a simple polygon:
@example
@verbatiminclude images/polygon.svg.scm
@image{images/polygon.svg.scm,,,A polygon.}
@end example

There are more primitive shapes that still need to be documented:
@code{triangle}, @code{filled-triangle}, @code{octagon},
@code{filled-octagon}, @code{circle}, @code{disk}, @code{ellipse},
@code{filled-ellipse}, @code{rectangle}, @code{filled-rectangle}, and
@code{text}.

@c *********************************************************************
@node Modifiers
@section Modifiers

Imagine you have a list of ten identical triangles: all with the same
size and the same color.  Boring, isn't it?  Perhaps it was easier to
produce them all alike.  Perhaps it was done like this:

@example
@verbatiminclude images/boring-triangles.svg.scm
@image{images/boring-triangles.svg.scm,,,A boring list of triangles.}
@end example

Luckily, we have a wide range of modifiers to change the properties of
existing pictures, including the fill color, the border color, the
orientation, the transparency, and even the properties of the bounding
box.

@cindex modifiers, example
Here's a preview of what we can do to the boring triangles:

@example
@verbatiminclude images/modifiers.svg.scm
@image{images/modifiers.svg.scm,,,A less boring list of triangles.}
@end example

Much better!

The following modifiers exist and still need to be documented:
@code{fill}, @code{colorize}, @code{remove-outline}, @code{rotate},
@code{scale}, @code{expand}, @code{grow}, @code{shrink}, @code{blur},
@code{cellophane}, @code{frame}, and @code{ghost}.

@c *********************************************************************
@node Combinators
@section Combinators

Now that we have learned about simple shapes we can generate lines and
shapes with different colors and dimensions, and with modifiers we can
scale them up or rotate them, but we still cannot compose complex
pictures that consist of more than just one shape.  To compose and
arrange shapes we need combinators: procedures that operate on pictures
and return new pictures.

Combinators cannot only be used on simple shapes but also on complex
pictures.  This is what makes them very powerful.  For example, we can
combine circles, lines, and ellipses to build a picture of a flower.  We
can then take this picture of a flower, duplicate and scale it a hundred
times, and then combine these pictures to a new picture of a meadow.
This picture of a meadow can be duplicated, the duplicates tinted and
arranged as a pop art print.  The picture of a pop art print can be
duplicated and arranged as a wall in an art gallery...

The following combinators exist and still need to be documented:
@code{append-align}, @code{ht-append}, @code{hc-append},
@code{hb-append}, @code{vl-append}, @code{vc-append}, @code{vr-append},
@code{lt-superimpose}, @code{lc-superimpose}, @code{lb-superimpose},
@code{ct-superimpose}, @code{cc-superimpose}, @code{cb-superimpose},
@code{rt-superimpose}, @code{rc-superimpose}, @code{rb-superimpose},
@code{pin-over}, and @code{pin-under}.

@c *********************************************************************
@node Acknowledgments
@chapter Acknowledgments

Thanks to the following people who contributed to the Picture Language
through bug reports, patches, ideas, encouragement, or suggestions:

@itemize @bullet
@item Ludovic Courtès @email{ludo@@gnu.org}
@item Christopher Lemmer Webber @email{cwebber@@dustycloud.org}
@end itemize

Thank you.

@c *********************************************************************
@node GNU Free Documentation License
@appendix GNU Free Documentation License

@include fdl-1.3.texi

@page

@c *********************************************************************
@node Concept Index
@unnumbered Concept Index

@printindex cp

@node Programming Index
@unnumbered Programming Index
@syncodeindex tp fn
@syncodeindex vr fn
@printindex fn

@bye