pull/2/head
Andreas Gysin 2020-10-03 12:27:39 +02:00
rodzic 9bfbfd2aba
commit 05e017eb1b
13 zmienionych plików z 36 dodań i 36 usunięć

Wyświetl plik

@ -6,10 +6,10 @@
*/ */
// Global variables have scope in the whole module. // Global variables have scope in the whole module.
const chars = '▁▂▃▄▅▆▇▆▅▄▃▂▁ '.split('') const pattern = '▁▂▃▄▅▆▇▆▅▄▃▂▁ '.split('')
// Resize the browser window to modify the pattern. // Resize the browser window to modify the pattern.
export function main(coord, context, cursor, buffers){ export function main(coord, context, cursor, buffers){
const i = coord.index % chars.length const i = coord.index % pattern.length
return chars[i] return pattern[i]
} }

Wyświetl plik

@ -38,7 +38,7 @@ export function post(context, cursor, buffers){
txt += 'to change the aspect ratio:\n' txt += 'to change the aspect ratio:\n'
txt += 'aspectRatio = ' + ar + '\n' txt += 'aspectRatio = ' + ar + '\n'
// Box style // Custom box style
const style = { const style = {
x : 3, x : 3,
y : 2, y : 2,

Wyświetl plik

@ -6,7 +6,7 @@
*/ */
// Globals have module scope // Globals have module scope
const chars = 'ABCxyz01═|+:. '.split('') const pattern = 'ABCxyz01═|+:. '.split('')
// This is the main loop. // This is the main loop.
// Character coordinates are passed in coord {x, y, index}. // Character coordinates are passed in coord {x, y, index}.
@ -17,9 +17,9 @@ export function main(coord, context, cursor, buffers){
const x = coord.x const x = coord.x
const y = coord.y const y = coord.y
const o = Math.sin(y * Math.sin(t) * 0.2 + x * 0.04 + t) * 20 const o = Math.sin(y * Math.sin(t) * 0.2 + x * 0.04 + t) * 20
const i = Math.round(Math.abs(x + y + o)) % chars.length const i = Math.round(Math.abs(x + y + o)) % pattern.length
return { return {
char : chars[i], char : pattern[i],
weight : '100', // or 'light', 'bold', '400' weight : '100', // or 'light', 'bold', '400'
} }
} }

Wyświetl plik

@ -12,7 +12,7 @@ const cam = Camera.init()
// For a debug view uncomment the following line: // For a debug view uncomment the following line:
// cam.display(document.body, 10, 10) // cam.display(document.body, 10, 10)
const chars = sort(' .x?▂▄▆█'.split('')) const density = sort(' .x?▂▄▆█'.split(''))
export function pre(context, cursor, buffers){ export function pre(context, cursor, buffers){
cam.cover(context).normalize().mirrorX().write(buffers.data) cam.cover(context).normalize().mirrorX().write(buffers.data)
@ -21,8 +21,8 @@ export function pre(context, cursor, buffers){
export function main(coord, context, cursor, buffers){ export function main(coord, context, cursor, buffers){
// Coord also contains the index of each cell: // Coord also contains the index of each cell:
const color = buffers.data[coord.index] const color = buffers.data[coord.index]
const index = Math.floor(color.gray / 255.0 * (chars.length-1)) const index = Math.floor(color.gray / 255.0 * (density.length-1))
return chars[index] return density[index]
} }
import { drawInfo } from '/src/modules/drawbox.js' import { drawInfo } from '/src/modules/drawbox.js'

Wyświetl plik

@ -12,7 +12,7 @@ const cam = Camera.init()
// For a debug view uncomment the following line: // For a debug view uncomment the following line:
// cam.display(document.body, 10, 10) // cam.display(document.body, 10, 10)
const chars = ' .+=?X#ABC'.split('') const density = ' .+=?X#ABC'.split('')
// A custom palette used for color quantization: // A custom palette used for color quantization:
const pal = [] const pal = []
@ -34,9 +34,9 @@ export function main(coord, context, cursor, buffers){
// Coord also contains the index of each cell // Coord also contains the index of each cell
const color = buffers.data[coord.index] const color = buffers.data[coord.index]
// Add some chars to the output // Add some chars to the output
const index = Math.floor(color.gray / 255.0 * (chars.length-1)) const index = Math.floor(color.gray / 255.0 * (density.length-1))
return { return {
char : chars[index], char : density[index],
color : 'white', color : 'white',
// convert {r,g,b} obj to a valid CSS hex string // convert {r,g,b} obj to a valid CSS hex string
background : rgb2hex(color) background : rgb2hex(color)

Wyświetl plik

@ -7,7 +7,7 @@ https://twitter.com/ntsutae/status/1292115106763960327
[header] [header]
*/ */
const chars = "└┧─┨┕┪┖┫┘┩┙┪━".split('') const pattern = "└┧─┨┕┪┖┫┘┩┙┪━".split('')
export function main(coord, context, cursor, buffers){ export function main(coord, context, cursor, buffers){
const t1 = Math.floor(context.time * 0.01) const t1 = Math.floor(context.time * 0.01)
@ -16,8 +16,8 @@ export function main(coord, context, cursor, buffers){
const y = coord.y + t1 const y = coord.y + t1
const m = t2 * 2 % 30 + 31 const m = t2 * 2 % 30 + 31
const i = (x + y^x - y) % m & 1 const i = (x + y^x - y) % m & 1
const c = (t2 + i) % chars.length const c = (t2 + i) % pattern.length
return chars[c] return pattern[c]
} }
import { drawInfo } from "/src/modules/drawbox.js" import { drawInfo } from "/src/modules/drawbox.js"

Wyświetl plik

@ -5,7 +5,7 @@
[header] [header]
*/ */
const chars = [ const pattern = [
" _000111_ ".split(''), " _000111_ ".split(''),
".+abc+. ".split('') ".+abc+. ".split('')
] ]
@ -25,7 +25,7 @@ export function main(coord, context, cursor, buffers){
const i = f(Math.abs(x + y + o)) const i = f(Math.abs(x + y + o))
const c = (f(coord.x * 0.09) + f(coord.y * 0.09)) % 2 const c = (f(coord.x * 0.09) + f(coord.y * 0.09)) % 2
return { return {
char : chars[c][i % chars[c].length], char : pattern[c][i % pattern[c].length],
color : 'black', //col[c], color : 'black', //col[c],
background : 'white', //col[(c+1)%2], background : 'white', //col[(c+1)%2],
weight : weights[c], weight : weights[c],

Wyświetl plik

@ -5,15 +5,15 @@
[header] [header]
*/ */
const chars = '┌┘└┐╰╮╭╯'.split('') const pattern = '┌┘└┐╰╮╭╯'.split('')
export function main(coord, context, cursor, buffers){ export function main(coord, context, cursor, buffers){
const t = context.time * 0.0005 const t = context.time * 0.0005
const x = coord.x const x = coord.x
const y = coord.y const y = coord.y
const o = Math.sin(y * x * Math.sin(t) * 0.003 + y * 0.01 + t) * 20 const o = Math.sin(y * x * Math.sin(t) * 0.003 + y * 0.01 + t) * 20
const i = Math.round(Math.abs(x + y + o)) % chars.length const i = Math.round(Math.abs(x + y + o)) % pattern.length
return chars[i] return pattern[i]
} }
import { drawInfo } from '/src/modules/drawbox.js' import { drawInfo } from '/src/modules/drawbox.js'

Wyświetl plik

@ -8,7 +8,7 @@
import { map } from '/src/modules/num.js' import { map } from '/src/modules/num.js'
import { sdCircle, opSmoothUnion } from '/src/modules/sdf.js' import { sdCircle, opSmoothUnion } from '/src/modules/sdf.js'
const chars = '#ABC|/:÷×+-=?*· '.split('') const density = '#ABC|/:÷×+-=?*· '.split('')
const { PI, sin, cos, exp, abs } = Math const { PI, sin, cos, exp, abs } = Math
@ -41,8 +41,8 @@ export function main(coord, context, cursor, buffer){
let c = 1.0 - exp(-3 * abs(d)); let c = 1.0 - exp(-3 * abs(d));
//if (d < 0) c = 0 //if (d < 0) c = 0
const index = Math.floor(c * chars.length) const index = Math.floor(c * density.length)
return chars[index] return density[index]
} }
function transform(p, trans, rot){ function transform(p, trans, rot){

Wyświetl plik

@ -8,7 +8,7 @@
import { map } from '/src/modules/num.js' import { map } from '/src/modules/num.js'
import { sdBox, opSmoothUnion } from '/src/modules/sdf.js' import { sdBox, opSmoothUnion } from '/src/modules/sdf.js'
let chars = '▚▀abc|/:÷×+-=?*· '.split('') let density = '▚▀abc|/:÷×+-=?*· '.split('')
export function main(coord, context, cursor, buffers){ export function main(coord, context, cursor, buffers){
@ -33,8 +33,8 @@ export function main(coord, context, cursor, buffers){
} }
let c = 1.0 - Math.exp(-5 * Math.abs(d)) let c = 1.0 - Math.exp(-5 * Math.abs(d))
const index = Math.floor(c * chars.length) const index = Math.floor(c * density.length)
return chars[index] return density[index]
} }
function transform(p, trans, rot){ function transform(p, trans, rot){

Wyświetl plik

@ -8,7 +8,7 @@
import { sdCircle } from '/src/modules/sdf.js' import { sdCircle } from '/src/modules/sdf.js'
import { sort } from '/src/modules/sort.js' import { sort } from '/src/modules/sort.js'
const chars = sort('/\\MXYZabc!?=-. '.split('')) const density = sort('/\\MXYZabc!?=-. '.split(''))
export const settings = { fps : 60 } export const settings = { fps : 60 }
@ -24,10 +24,10 @@ export function main(coord, context, cursor, buffer){
const radius = (Math.cos(t)) * 0.4 + 0.5 const radius = (Math.cos(t)) * 0.4 + 0.5
const d = sdCircle(st, radius) const d = sdCircle(st, radius)
const c = 1.0 - Math.exp(-5 * Math.abs(d)) const c = 1.0 - Math.exp(-5 * Math.abs(d))
const index = Math.floor(c * chars.length) const index = Math.floor(c * density.length)
return { return {
char : coord.x % 2 ? '│' : chars[index], char : coord.x % 2 ? '│' : density[index],
background : 'black', background : 'black',
color : 'white' color : 'white'
} }

Wyświetl plik

@ -12,7 +12,7 @@ import { map } from '/src/modules/num.js'
export const settings = { fps : 60 } export const settings = { fps : 60 }
const chars = ' -=+abcdX'.split('') const density = ' -=+abcdX'.split('')
// Shorthands // Shorthands
const { vec3 } = v3 const { vec3 } = v3
@ -94,7 +94,7 @@ export function main(coord, context, cursor){
d = min(d, sdSegment(st, a, b, thickness)) d = min(d, sdSegment(st, a, b, thickness))
} }
const idx = floor(exp(expMul * abs(d)) * chars.length) const idx = floor(exp(expMul * abs(d)) * density.length)
if (idx == 0) { if (idx == 0) {
const x = coord.x % bgMatrixDim.x const x = coord.x % bgMatrixDim.x
@ -102,7 +102,7 @@ export function main(coord, context, cursor){
return d < 0 ? ' ' : bgMatrix[y][x] return d < 0 ? ' ' : bgMatrix[y][x]
} else { } else {
return { return {
char : chars[idx], char : density[idx],
color : 'blue' color : 'blue'
} }
} }

Wyświetl plik

@ -8,7 +8,7 @@
import { sdCircle, opSmoothUnion } from '/src/modules/sdf.js' import { sdCircle, opSmoothUnion } from '/src/modules/sdf.js'
import { sub, vec2 } from '/src/modules/vec2.js' import { sub, vec2 } from '/src/modules/vec2.js'
const charMap = '#WX?*:÷×+=-· '.split('') const density = '#WX?*:÷×+=-· '.split('')
export function main(coord, context, cursor, buffers){ export function main(coord, context, cursor, buffers){
const t = context.time const t = context.time
@ -35,9 +35,9 @@ export function main(coord, context, cursor, buffers){
// Calc index of the char map // Calc index of the char map
const c = 1.0 - Math.exp(-5 * Math.abs(d)) const c = 1.0 - Math.exp(-5 * Math.abs(d))
const index = Math.floor(c * charMap.length) const index = Math.floor(c * density.length)
return charMap[index] return density[index]
} }