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
}
Top Left Arrow - Filledn = 5
Result
* * * * * 
* * * *   
* * *     
* *   *   
*       * 
Snippet
function ArrowTopLeftFilled(n) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
const diagonal = i === j
const arrowhead = i < n - j
const clause = diagonal || arrowhead
out += clause ? '* ' : ' '
}
out += '\n'
}
return out
}
Top Right Arrow - Filledn = 5
Result
* * * * * 
  * * * * 
    * * * 
  *   * * 
*       * 
Snippet
function ArrowTopRightFilled(n) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
const diagonal = i===n-j-1
const arrowhead = j>i-1
const clause = diagonal || arrowhead
out += clause ? '* ' : ' '
}
out += '\n'
}
return out
}
Arrow - Bottom Right - Filledn = 5
Result
*       * 
  *   * * 
    * * * 
  * * * * 
* * * * * 
Snippet
function ArrowBottomRightFilled(n) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
const diagonal = i===j
const arrowhead = i>n-j-2
const clause = diagonal || arrowhead
out += clause ? '* ' : ' '
}
out += '\n'
}
return out
}
Arrow - Bottom Left - Filledn = 5
Result
*       * 
* *   *   
* * *     
* * * *   
* * * * * 
Snippet
function ArrowBottomLeftFilled(n) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
const diagonal = i===n-j-1
const arrowhead = j<i+1
const clause = diagonal || arrowhead
out += clause ? '* ' : ' '
}
out += '\n'
}
return out
}
Diamond Filledn = 5
Result
        *         
      * * *       
    * * * * *     
  * * * * * * *   
* * * * * * * * * 
  * * * * * * *   
    * * * * *     
      * * *       
        *         
Snippet
function DiamondFilled(n) {
let out = ''
for (let i = 0; i < 2 * n - 1; i++) {
let k = i
if (i>=n) { k = 2 * n - i - 2 }
for (let j = 0; j < 2 * n - 1; j++) {
const clause = ( j >= n - k - 1 && j <= n + k - 1 )
out += clause ? '* ' : ' '
}
out += '\n'
}
return out
}
Up Arrow - Filledn = 5
Result
        *         
      * * *       
    * * * * *     
  * * * * * * *   
* * * * * * * * * 
        *         
        *         
        *         
        *         
Snippet
function ArrowUpFilled(n) {
let out = ''
for (let i = 0; i < 2*n-1; i++) {
let k = i
if i>=n {k = n-i}
for (let j = 0; j < 2*n-1; j++) {
const verticalCenter = j===n-1
const clause = (j>=n-k-1 && j<=n+k-1) || verticalCenter
out += clause ? '* ' : ' '
}
out += '\n'
}
return out
}
Hourglass - Vertical - Emptyn = 5
Result
* * * * * 
  *   *   
    *     
  *   *   
* * * * * 
Snippet
function HourglassEmptyVertical(n) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
const diag1 = i === j
const diag2 = j === n - i - 1
const bottom = i === n - 1
const clause = diag1 || diag2 || bottom || i === 0
out += clause ? '* ' : ' '
}
out += '\n'
}
return out
}
Asteriskn = 5
Result
*       *       * 
  *     *     *   
    *   *   *     
      * * *       
* * * * * * * * * 
      * * *       
    *   *   *     
  *     *     *   
*       *       * 
Snippet
function Asterisk(n) {
let out = ''
for (let i = 0; i < 2 * n - 1; i++) {
for (let j = 0; j < 2 * n - 1; j++) {
const horizontalCenter = i === n-1
const verticalCenter = j === n-1
const diagonal1 = j === i
const diagonal2 = j === 2 * n - i -2
const clause = verticalCenter || diagonal1 || diagonal2 || horizontalCenter
out += clause ? '* ' : ' '
}
out += '\n'
}
return out
}
Hourglass - Vertical - Filledn = 5
Result
* * * * * 
  * * *   
    *     
  * * *   
* * * * * 
Snippet
function HourglassFilledVertical(n) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
const diag1 = i === j
const diag2 = j === n - i - 1
const fillTopHalf = i < j && j < n - i - 1
const fillBottomHalf = i > j && j > n - i - 1
const top = i === 0
const bottom = i === n-1
const clause = diag1 || diag2 || bottom || top || fillTopHalf || fillBottomHalf
out += clause ? '* ' : ' '
}
out += '\n'
}
return out
}
Grid - Customizablen = 5
Result
*   *   * 
          
*   *   * 
          
*   *   * 
Snippet
function Grid(n,hspacing,vspacing) {
let out = ''
if (hspacing === undefined) { hspacing = 2 }
if (vspacing === undefined) { vspacing = 2 }
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
const v = i < n && i % vspacing == 0
const h = j < n && j % hspacing == 0
const clause = v && h
out += clause ? '* ' : ' '
}
out += '\n'
}
return out
}
Checkered Flagn = 5
Result
█   █   █ 
  █   █   
█   █   █ 
  █   █   
█   █   █ 
Snippet
function CheckeredFlag(n,hspacing,vspacing) {
let out = ''
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
const even = i % 2 == 0 && j % 2 == 0
const odd = i % 2 != 0 && j % 2 != 0
const clause = even || odd
out += clause ? '█ ' : ' '
}
out += '\n'
}
return out
}