console-patterns

Collection of snippets to render logical patterns

Request new patterns or find some bugs? Submit an issue on GitHub.

Crossn = 5
Result
*       * 
  *   *   
    *     
  *   *   
*       * 
Snippet
function Cross(n) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
const clause = i === j || j === n - i - 1
out += clause ? '* ' : ' '
}
out += '\n'
}
return out
}
Squaren = 5
Result
* * * * * 
*       * 
*       * 
*       * 
* * * * * 
Snippet
function Square(n) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
const topAndBottom = i === 0 || i === n - 1
const leftAndRight = j === 0 || j === n - 1
const clause = topAndBottom || leftAndRight
out += clause ? '* ' : ' '
}
out += '\n'
}
return out
}
Triangle An = 5
Result
* 
* * 
* * * 
* * * * 
* * * * * 
Snippet
function TriangleA(n) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j <= i; j++) {
out += '* '
}
out += '\n'
}
return out
}
Triangle Bn = 5
Result
* * * * * 
  * * * * 
    * * * 
      * * 
        * 
Snippet
function TriangleB(n) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
out += j >= i ? '* ' : ' '
}
out += '\n'
}
return out
}
Triangle Cn = 5
Result
* * * * * 
* * * * 
* * * 
* * 
* 
Snippet
function TriangleC(n) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j < n - i; j++) {
out += '* '
}
out += '\n'
}
return out
}
Triangle Dn = 5
Result
        * 
      * * 
    * * * 
  * * * * 
* * * * * 
Snippet
function TriangleD(n) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
out += j >= n - i ? '* ' : ' '
}
out += '\n'
}
return out
}
Triangle Hollow An = 5
Result
* 
* * 
*   * 
*     * 
* * * * * 
Snippet
function TriangleHollowA(n) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j <= i; j++) {
const clause = i === j || i === n - 1 || j === 0
out += clause ? '* ' : ' '
}
out += '\n'
}
return out
}
Triangle Hollow Bn = 5
Result
* * * * * 
  *     * 
    *   * 
      * * 
        * 
Snippet
function TriangleHollowB(n) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
const clause = i === j || i === 0 || j === n - 1
out += clause ? '* ' : ' '
}
out += '\n'
}
return out
}
Triangle Hollow Cn = 5
Result
* * * * * 
*     * 
*   * 
* * 
* 
Snippet
function TriangleHollowC(n) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j < n - i; j++) {
const clause = j === n - i - 1 || i === 0 || j === 0
out += clause ? '* ' : ' '
}
out += '\n'
}
return out
}
Triangle Dn = 5
Result
        * 
      * * 
    *   * 
  *     * 
* * * * * 
Snippet
function TriangleHollowD(n) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
const clause = j === n - i - 1 || i === n - 1 || j === n - 1
out += clause ? '* ' : ' '
}
out += '\n'
}
return out
}