You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorials/computational-poetry.md
+77-57Lines changed: 77 additions & 57 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ In this tutorial, you'll learn how to create generative visual poetry using L5,
10
10
11
11
## Learning Objectives
12
12
13
-
By the end of this tutorial, students will be able to:
13
+
By the end of this tutorial, students should be able to:
14
14
15
15
- Understand the basics of L5 and how it relates to p5.js/Processing
16
16
- Draw text and shapes to the screen using code
@@ -19,59 +19,87 @@ By the end of this tutorial, students will be able to:
19
19
- Build a grid-based layout system
20
20
- Combine text, randomness, and interaction to create computational poetry
21
21
22
-
## Setup
22
+
## What is L5?
23
+
24
+
L5 is a creative coding library that brings the simplicity and approachability of p5.js and Processing to the Lua programming language. If you've used p5.js or Processing before, you'll find L5 familiar - it uses the same basic structure with `setup()` and `draw()` functions, and similar function names for drawing shapes, working with color, and handling interaction.
25
+
26
+
L5 uses Lua syntax, which is known for being clean and beginner-friendly. Lua uses simple keywords like `function`, `end`, and `for` that make code easy to read.
27
+
28
+
L5 is heavily inspired by [permacomputing](https://permacomputing.net/), a growing movement responding to environmental and social conditions in computing. L5 is designed to be able to work on a wide variety of computers, to help prevent issues like needing to constantly upgrade, to work against "planned obsolescence", to consider constraints on consumption. The goal is for L5 to be a convivial tool that you can continue to use for years, with programs continuing to work long into the future.
29
+
30
+
While this is the goal, L5 is *alpha* software. The first version was released in December 2025. It has bugs, and does not fully implement all of Processing/p5. A number of people are working on the language to improve it.
31
+
32
+
## Installation
23
33
24
34
To get started with L5, you'll need to set it up on your computer:
25
35
26
36
-**Mac users:**[L5 Setup for Mac](https://l5lua.org/download/install-mac)
27
37
-**Windows users:**[L5 Setup for Windows](https://l5lua.org/download/install-windows)
28
38
29
-
Once you have L5 installed, you're ready to begin.
39
+
Next you need a code editor to write your code. If you already use a code editor, use the one you're familiar with. If you have never used a code editor on your own computer, you can pick one like Visual Studio Code, SublimeText, or a dedicated Lua IDE like ZeroBrane Studio.
40
+
If you don't have any IDE installed on your computer you can even use your built-in plaintext editor TextEdit on macOS in plain text mode, or Notepad on Windows. But keep in mind they are barebones environments without additional features like syntax highlighting that make it easier to write code.
30
41
31
-
## What is L5?
42
+
Once you have 1) Love2d installed 2) L5-Starter downloaded and unzipped 3) and you've tested launching Love2d and making sure you've given your computer approval to launch it, then you're ready to go.
32
43
33
-
L5 is a creative coding library that brings the simplicity and approachability of p5.js and Processing to the Lua programming language. If you've used p5.js or Processing before, you'll find L5 familiar - it uses the same basic structure with `setup()` and `draw()` functions, and similar function names for drawing shapes, working with color, and handling interaction.
34
-
35
-
The main difference is that L5 uses Lua syntax, which is known for being clean and beginner-friendly. Lua uses simple keywords like `function`, `end`, and `for` that make code easy to read.
44
+
To test it all out: Try dragging **the folder** L5-Starter on top of the Love2d application file. It should launch and you should see a gold window appear. If it doesn't launch, you either didn't drag the folder or you need to give your computer permission to run an *un-signed application*, meaning that the developer didn't pay Apple to pre-approve this software (on macOS), or that you're giving Windows permission to run this downloaded program.
36
45
37
46
## Getting Started: Your First L5 Sketch
38
47
39
-
Every L5 sketch starts with requiring the library. Create a new file and type:
48
+
Every L5 sketch starts with requiring the L5 library file, which you'll see in the first line. We can start by looking at the L5-Starter sketch. Inside the folder, open up the *main.lua* file.
49
+
50
+
You can open it in your favorite code editor like Visual Studio Code or SublimeText, or use the built-in Notepad on Windows or TextEdit on macOS.
40
51
41
52
```lua
42
-
require'L5'
53
+
require("L5")
43
54
44
55
functionsetup()
45
-
-- Your setup code goes here
56
+
size(400, 400)
57
+
58
+
-- Set the program title
59
+
windowTitle("Basic sketch")
60
+
61
+
describe('Draws a yellow background')
62
+
end
63
+
64
+
functiondraw()
65
+
-- Fills the background with the color yellow
66
+
background(255, 215, 0)
46
67
end
47
68
```
48
69
49
-
The `setup()` function runs once when your program starts. This is where we'll put code that only needs to happen at the beginning.
70
+
The `setup()` function runs once when your program starts. This is where we'll put code that only needs to happen at the beginning.`windowTitle()` specifies the nae for the title bar. `describe()` is an optional function for a text description of your program.
50
71
51
-
## Step 1: Drawing a Background
72
+
The lines beginning with `--` are comments: notes to yourself or anyone reading your code, but they will be ignored by the compiler when you ask it to run your program.
52
73
53
-
Let's start by setting a background color. Add this inside your `setup()` function:
74
+
## Step 1: Changing the Background
54
75
55
-
```lua
56
-
require'L5'
76
+
Run your sketch by dragging and dropping the L5-starter folder on top of the Love application. You should see a window open and a golden yellow background.
77
+
78
+
Now let's go back to our code. Let's start by changing the background color. Modify the background inside your `draw()` function. You can use RGB values:
79
+
Try changing `'gold'` to other colors like `'lightblue'`, `'pink'`, or `'lavender'`. You can use any of the [HTML Color Names](https://www.w3schools.com/colors/colors_names.asp), or RGB numbers like `background(255, 0, 255)` or hexadecimal: `background('#7FFFD4')`.
57
80
58
-
functionsetup()
59
-
background('white')
60
-
end
61
-
```
62
81
63
-
Run your sketch. You should see a white canvas. Try changing `'white'` to other colors like `'lightblue'`, `'pink'`, or `'lavender'`. You can use any of the [HTML Color Names](https://www.w3schools.com/colors/colors_names.asp), or RGB numbers like `background(255, 0, 255)` or hexadecimal: `background('#7FFFD4')`.
82
+
```lua
83
+
background('purple')
84
+
```
64
85
65
86
## Step 2: Drawing Basic Shapes
66
87
67
88
L5 can draw shapes just like p5.js. Let's add a circle:
68
89
90
+
Add this code inside your draw:
91
+
69
92
```lua
70
-
require'L5'
93
+
fill('gold')
94
+
circle(100, 100, 50)
95
+
```
71
96
72
-
functionsetup()
73
-
background('white')
74
-
fill('black')
97
+
So your draw() function should now look like:
98
+
99
+
```lua
100
+
functiondraw()
101
+
-- Fills the background with the color yellow
102
+
fill('gold')
75
103
circle(100, 100, 50)
76
104
end
77
105
```
@@ -83,16 +111,20 @@ Try drawing other shapes:
83
111
-`ellipse(x, y, width, height)` - draws an ellipse
84
112
-`line(x1, y1, x2, y2)` - draws a line
85
113
114
+
If you have any previous experience wih Processing or p5.js you should feel right at home.
115
+
86
116
## Step 3: Drawing Text on Screen
87
117
88
-
Now let's draw some text instead of shapes:
118
+
**Let's remove our older code and replace it with this small program, where everything is written inside just the setup() function:**
119
+
120
+
We'll draw some text instead of shapes:
89
121
90
122
```lua
91
-
require'L5'
123
+
require('L5')
92
124
93
125
functionsetup()
94
-
background('white')
95
-
fill('black')
126
+
background('mintcream')
127
+
fill('lawngreen')
96
128
textSize(32)
97
129
text('hello', 100, 100)
98
130
end
@@ -111,7 +143,7 @@ Try changing:
111
143
Instead of just one word, let's create a collection of words we can choose from. In Lua, we use curly braces `{}` to create arrays (called "tables" in Lua):
112
144
113
145
```lua
114
-
require'L5'
146
+
require('L5')
115
147
116
148
words= {"eye", "nose", "mouth", "ear", "brain"}
117
149
@@ -132,7 +164,7 @@ Try displaying different words by changing `words[1]` to `words[2]`, `words[3]`,
132
164
Instead of always showing the same word, let's pick one randomly:
133
165
134
166
```lua
135
-
require'L5'
167
+
require('L5')
136
168
137
169
words= {"eye", "nose", "mouth", "ear", "brain"}
138
170
@@ -146,12 +178,14 @@ end
146
178
147
179
The `random()` function can pick a random item from an array when you pass it an array. Run your sketch multiple times - you should see different words!
148
180
181
+
Question: What would happen if this code was inside *draw()* instead of *setup()*, and how could you fix it?
182
+
149
183
## Step 6: Creating a Grid
150
184
151
185
Now we'll use loops to create a grid of positions where words could appear. We'll use two variables to control the grid spacing:
152
186
153
187
```lua
154
-
require'L5'
188
+
require('L5')
155
189
156
190
words= {"eye", "nose", "mouth", "ear", "brain"}
157
191
@@ -184,7 +218,7 @@ This creates a grid of words across your entire canvas.
184
218
Right now we're showing a word at every grid position. Let's make it more interesting by only sometimes showing a word:
@@ -265,29 +299,22 @@ Now that you have the basic structure, try customizing it:
265
299
266
300
5.**Add color:** Try `fill('red')` or use RGB values like `fill(255, 0, 0)`
267
301
268
-
## Extension Ideas
269
-
270
-
Ready to go further? Try these challenges:
302
+
## Ways to extend
271
303
272
-
### Adding Animation
273
-
274
-
Instead of only drawing in `setup()`, you can use the `draw()` function to create continuous animation:
304
+
* Incorporate animation in `draw()` to change your sketch over time
275
305
276
306
```lua
277
307
functiondraw()
278
-
background('white')
279
-
--your grid code here
308
+
x=millis() /5
309
+
text(specialName, x, 200) --Text will move to the right
280
310
end
281
311
```
282
312
283
-
This will create a constantly changing composition!
284
-
285
-
### Using Mouse Interaction
286
-
287
-
Make your composition respond to the mouse position:
313
+
* Make your composition respond to the mouse position
288
314
289
315
```lua
290
-
textSize(mouseX/10) -- Text size changes with mouse X position
316
+
-- Text size changes with mouse X position
317
+
--textSize(mouseX / 10) -- Don't run this yet!
291
318
```
292
319
293
320
This can cause freezing if mouseX is 0 at the beginning of the sketch, so we can constrain it to have a minimum value.
@@ -342,21 +369,14 @@ pop()
342
369
343
370
-**Generative:** Art or designs created by following a set of rules or algorithms, often involving randomness
344
371
-**Computational Poetry:** Using code and algorithms to create, arrange, or manipulate text as a form of poetic expression
345
-
-**Array/Table:** A collection of values stored together (in Lua, called a "table")
346
-
-**Algorithm:** A set of step-by-step instructions to solve a problem or create something
372
+
-**Array/Table:** A collection of values stored together. In most languages this is called an array. In Lua, we say it is an *ordered* table. Each item in the table has a number (an order), starting at 1.
347
373
-**Parameter:** A value you pass into a function to customize how it works
348
374
-**Random:** Unpredictable; choosing something without a pattern
349
-
-**Grid:** A layout system based on evenly-spaced rows and columns
350
375
-**Iteration:** Repeating a process multiple times (like in a loop)
351
376
352
377
## Going Further
353
378
354
-
Computational poetry is a rich field with many approaches. Research these artists and techniques:
355
-
356
-
-**Concrete poetry:** Poetry where the visual arrangement is as important as the words
357
-
-**Blackout poetry:** Creating new poems by selectively revealing words from existing text
358
-
-**Erasure poetry:** Similar to blackout poetry, removing words to create new meaning
359
-
-**Artists to explore:** Allison Parrish, Nick Montfort, Lillian-Yvonne Bertram
379
+
-**Artists to explore:**[Allison Parrish](https://www.decontextualize.com/), [Nick Montfort](https://nickm.com/), [Lillian-Yvonne Bertram](https://www.lillianyvonnebertram.com/)
360
380
-**Online computational poetry:**[Taper](https://taper.badquar.to/), [The HTML Review](https://thehtml.review), [Random Walk](https://randomwalk.club/)
361
381
362
382
## Resources
@@ -367,7 +387,7 @@ Computational poetry is a rich field with many approaches. Research these artist
367
387
368
388
## Share Your Work!
369
389
370
-
Created something interesting? Share it with the [L5 category](https://discourse.processing.org/c/l5/29) on the Processing Discourse forum or with #L5 on social media. We'd love to see what you make.
390
+
Created something interesting? Need help polishing your code? Check out the new [L5 category](https://discourse.processing.org/c/l5/29) on the Processing Discourse forum.
0 commit comments