Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create a special case of Truchet tiling, using three squares from
- # https://en.wikipedia.org/wiki/Black_Path_Game
- # => step 1: generate a fixed tiling of 6 rows x 8 columns, and display it
- # Copyright 2024 Roland Richter [Processing.py]
- from __future__ import division, print_function
- def setup():
- # 8x6 tiles of size 100x100 pixels, plus all borders with two pixels each
- size(818, 614)
- # Black Path Game tiles (PNG, 100x100 pixels) from
- # https://en.wikipedia.org/wiki/File:Square_(02)_12-34.svg,
- # https://en.wikipedia.org/wiki/File:Square_(20)_13-24.svg, and
- # https://en.wikipedia.org/wiki/File:Square_(02)_14-23.svg
- # by Mliu92, used under CC BY-SA 4.0
- sq12 = loadImage("Square_12-34.png")
- sq13 = loadImage("Square_13-24.png")
- sq14 = loadImage("Square_14-23.png")
- global squares
- squares = [sq12, sq13, sq14]
- print("loaded", len(squares), "squares.")
- def draw():
- background(255)
- # The tiling is generated randomly each time draw() is called; to ensure that
- # the same tiling is generated each time, initialize the random generator here.
- randomSeed(42)
- global squares
- # Generate and draw the tiling in six rows, and eight columns
- for r in range(6):
- for c in range(8):
- idx = int(random(len(squares)))
- image(squares[idx], 2 + c * 102, 2 + r * 102)
- # ----------------------------------------------------------------------
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement