-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchessboard.lua
More file actions
35 lines (32 loc) · 1.12 KB
/
Copy pathchessboard.lua
File metadata and controls
35 lines (32 loc) · 1.12 KB
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
-- Title: Chessboard Pattern
-- Path: Patterns
-- Description: This script draws a chessboard pattern.
-- Author: Eduardo Castillo (hellocodelinux@gmail.com)
-- This script uses parameters defined in the LUA_PARAMETERS.txt file.
-- https://github.com/hellocodelinux/plugins_icy_draw
-- Define the characters for black and white squares
-- '█' is a full block, ' ' is an empty space
local black_block = '█'
local white_block = ' '
-- Ensure coordinates are in correct order (start < end)
-- This swaps the values if they're in wrong order
if start_x > end_x then
start_x, end_x = end_x, start_x
end
if start_y > end_y then
start_y, end_y = end_y, start_y
end
-- Draw the chessboard pattern
-- Loop through each row and column in the selected area
for y = start_y, end_y do
for x = start_x, end_x do
-- Use modulo operator to alternate between black and white
-- When (x + y) is even, place a black block
-- When (x + y) is odd, place a white block
if (x + y) % 2 == 0 then
buf:set_char(x, y, black_block)
else
buf:set_char(x, y, white_block)
end
end
end