patterns.run

Collection of snippets to render logical patterns

arrow-bottom-left

Edit in playground
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
const line = i === size - j - 1;
const head = j < i + 1;
print(line || head ? "* " : " ");
}
newline();
}
Result
* *
* * *
* * *
* * * *
* * * * *

arrow-bottom-right

Edit in playground
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
const line = i === j;
const head = i > size - j - 2;
print(line || head ? "* " : " ");
}
newline();
}
Result
* *
* * *
* * *
* * * *
* * * * *

arrow-top-left

Edit in playground
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
const line = i === j;
const head = i < size - j;
print(line || head ? "* " : " ");
}
newline();
}
Result
* * * * *
* * * *
* * *
* * *
* *

arrow-top-right

Edit in playground
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
const line = i === size - j - 1;
const head = j > i - 1;
print(line || head ? "* " : " ");
}
newline();
}
Result
* * * * *
* * * *
* * *
* * *
* *

arrow-up-optimized

Edit in playground
Source code
for (let i = 0; i < size * 2 - 1; i++) {
const rt /* ↙ */ = size + i;
const rb /* ┌ */ = size;
const limit = i < size ? rt : rb;
for (let j = 0; j < limit; j++) {
const head = j >= size - i - 1 && i < size;
const line = j === size - 1;
print(head || line ? "* " : " ");
}
newline();
}
Result
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
*
*
*
*
Source code
for (let i = 0; i < size * 2 - 1; i++) {
for (let j = 0; j < size * 2 - 1; j++) {
const lt /* ↘ */ = j >= size - i - 1;
const rt /* ↙ */ = j <= size + i - 1;
const head = lt && rt && i < size;
const line = j === size - 1;
print(head || line ? "* " : " ");
}
newline();
}
Result
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
*
*
*
*
Source code
for (let i = 0; i < 2 * size - 1; i++) {
for (let j = 0; j < 2 * size - 1; j++) {
const h /* ─ */ = i === size - 1;
const v /* │ */ = j === size - 1;
const d1 /* ↘ */ = i === j;
const d2 /* ↙ */ = j === 2 * size - i - 2;
print(h || v || d1 || d2 ? "* " : " ");
}
newline();
}
Result
* * *
* * *
* * *
* * *
* * * * * * * * *
* * *
* * *
* * *
* * *

checkered-flag

Edit in playground
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
const odd = i % 2 !== 0 && j % 2 !== 0;
const even = i % 2 === 0 && j % 2 === 0;
print(odd || even ? "█ " : " ");
}
newline();
}
Result
█ █ █
█ █
█ █ █
█ █
█ █ █
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
const /* ↘ */ ltrb = i === j;
const /* ↙ */ rtlb = j === size - i - 1;
print(ltrb || rtlb ? "* " : " ");
}
newline();
}
Result
* *
* *
*
* *
* *

customizable-grid

Edit in playground
Source code
const hspacing = 2;
const vspacing = 2;
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
const horizontal = j < size && j % hspacing == 0;
const vertical = i < size && i % vspacing == 0;
print(horizontal && vertical ? "* " : " ");
}
newline();
}
Result
* * *
* * *
* * *

diamond-optimized

Edit in playground
Source code
for (let i = 0; i < size * 2 - 1; i++) {
const rt /* ↙ */ = size + i;
const rb /* ↖ */ = size * 3 - i - 2;
const limit = i < size ? rt : rb;
for (let j = 0; j < limit; j++) {
const lt /* ↘ */ = j >= size - i - 1;
const lb /* ↗ */ = j > i - size;
print(lt && lb ? "* " : " ");
}
newline();
}
Result
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
Source code
for (let i = 0; i < size * 2 - 1; i++) {
for (let j = 0; j < size * 2 - 1; j++) {
const lt /* ↘ */ = j >= size - i - 1;
const lb /* ↗ */ = j > i - size;
const rt /* ↙ */ = j <= size + i - 1;
const rb /* ↖ */ = j < size * 3 - i - 2;
print(lt && lb && rt && rb ? "* " : " ");
}
newline();
}
Result
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*

hourglass-empty

Edit in playground
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
const ltrb /* ↘ */ = i === j;
const rtlb /* ↙ */ = j === size - i - 1;
const top = i === 0;
const bottom = i === size - 1;
const clause = ltrb || rtlb || top || bottom;
print(clause ? "* " : " ");
}
newline();
}
Result
* * * * *
* *
*
* *
* * * * *
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
const ltrb /* ↘ */ = i === j;
const rtlb /* ↙ */ = j === size - i - 1;
const top = i === 0;
const bottom = i === size - 1;
const fillTop = i < j && j < size - i - 1;
const fillBottom = i > j && j > size - i - 1;
const outline = ltrb || rtlb || top || bottom;
const fill = fillTop || fillBottom;
print(outline || fill ? "* " : " ");
}
newline();
}
Result
* * * * *
* * *
*
* * *
* * * * *

square-hollow

Edit in playground
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
const top = i === 0;
const bottom = i === size - 1;
const left = j === 0;
const right = j === size - 1;
const clause = top || bottom || left || right;
print(clause ? "* " : " ");
}
newline();
}
Result
* * * * *
* *
* *
* *
* * * * *
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
const top = i === 0;
const bottom = i === size - 1;
const left = j === 0;
const right = j === size - 1;
const /* ↘ */ ltrb = i === j;
const /* ↙ */ rtlb = j === size - i - 1;
const square = top || bottom || left || right;
const x = ltrb || rtlb;
print(square || x ? "* " : " ");
}
newline();
}
Result
* * * * *
* * * *
* * *
* * * *
* * * * *
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
print("* ");
}
newline();
}
Result
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j <= i; j++) {
print("* ");
}
newline();
}
Result
*
* *
* * *
* * * *
* * * * *
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
print(j >= i ? "* " : " ");
}
newline();
}
Result
* * * * *
* * * *
* * *
* *
*
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size - i; j++) {
print("* ");
}
newline();
}
Result
* * * * *
* * * *
* * *
* *
*
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
print(j >= size - i - 1 ? "* " : " ");
}
newline();
}
Result
*
* *
* * *
* * * *
* * * * *

triangle-hollow-a

Edit in playground
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j <= i; j++) {
const diagonal = i === j;
const horizontal = i === size - 1;
const vertical = j === 0;
const clause = diagonal || horizontal || vertical;
print(clause ? "* " : " ");
}
newline();
}
Result
*
* *
* *
* *
* * * * *

triangle-hollow-b

Edit in playground
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
const diagonal = i === j;
const horizontal = i === 0;
const vertical = j === size - 1;
const clause = diagonal || horizontal || vertical;
print(clause ? "* " : " ");
}
newline();
}
Result
* * * * *
* *
* *
* *
*

triangle-hollow-c

Edit in playground
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size - i; j++) {
const diagonal = j === size - i - 1; // ↙
const horizontal = i === 0;
const vertical = j === 0;
const clause = diagonal || horizontal || vertical;
print(clause ? "* " : " ");
}
newline();
}
Result
* * * * *
* *
* *
* *
*

triangle-hollow-d

Edit in playground
Source code
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
const diagonal = j === size - i - 1; // ↙
const horizontal = i === size - 1;
const vertical = j === size - 1;
const clause = diagonal || horizontal || vertical;
print(clause ? "* " : " ");
}
newline();
}
Result
*
* *
* *
* *
* * * * *