SHOW:
|
|
- or go back to the newest paste.
1 | # Create a special case of Truchet tiling, using three squares from | |
2 | # https://en.wikipedia.org/wiki/Black_Path_Game | |
3 | # => step 1: generate a fixed tiling of 6 rows x 8 columns, and display it | |
4 | # Copyright 2024 Roland Richter [Processing.py] | |
5 | ||
6 | from __future__ import division, print_function | |
7 | ||
8 | def setup(): | |
9 | # 8x6 tiles of size 100x100 pixels, plus all borders with two pixels each | |
10 | size(818, 614) | |
11 | - | # Black Path Game tiles from |
11 | + | |
12 | # Black Path Game tiles (PNG, 100x100 pixels) from | |
13 | # https://en.wikipedia.org/wiki/File:Square_(02)_12-34.svg, | |
14 | # https://en.wikipedia.org/wiki/File:Square_(20)_13-24.svg, and | |
15 | # https://en.wikipedia.org/wiki/File:Square_(02)_14-23.svg | |
16 | # by Mliu92, used under CC BY-SA 4.0 | |
17 | sq12 = loadImage("Square_12-34.png") | |
18 | sq13 = loadImage("Square_13-24.png") | |
19 | sq14 = loadImage("Square_14-23.png") | |
20 | ||
21 | global squares | |
22 | squares = [sq12, sq13, sq14] | |
23 | print("loaded", len(squares), "squares.") | |
24 | ||
25 | ||
26 | def draw(): | |
27 | background(255) | |
28 | ||
29 | # The tiling is generated randomly each time draw() is called; to ensure that | |
30 | # the same tiling is generated each time, initialize the random generator here. | |
31 | randomSeed(42) | |
32 | ||
33 | global squares | |
34 | ||
35 | - | for row in range(6): |
35 | + | |
36 | - | for col in range(8): |
36 | + | for r in range(6): |
37 | for c in range(8): | |
38 | - | image(squares[idx], 2 + col*102, 2 + row*102) |
38 | + | |
39 | image(squares[idx], 2 + c * 102, 2 + r * 102) | |
40 | ||
41 | ||
42 | # ---------------------------------------------------------------------- | |
43 | # This program is free software: you can redistribute it and/or modify | |
44 | # it under the terms of the GNU General Public License as published by | |
45 | # the Free Software Foundation, either version 3 of the License, or | |
46 | # (at your option) any later version. | |
47 | # | |
48 | # This program is distributed in the hope that it will be useful, | |
49 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
50 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
51 | # GNU General Public License for more details. | |
52 | # | |
53 | # You should have received a copy of the GNU General Public License | |
54 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |