kopia lustrzana https://github.com/ertdfgcvb/play.core
Clean examples
rodzic
9bfbfd2aba
commit
05e017eb1b
|
@ -6,10 +6,10 @@
|
|||
*/
|
||||
|
||||
// Global variables have scope in the whole module.
|
||||
const chars = '▁▂▃▄▅▆▇▆▅▄▃▂▁ '.split('')
|
||||
const pattern = '▁▂▃▄▅▆▇▆▅▄▃▂▁ '.split('')
|
||||
|
||||
// Resize the browser window to modify the pattern.
|
||||
export function main(coord, context, cursor, buffers){
|
||||
const i = coord.index % chars.length
|
||||
return chars[i]
|
||||
const i = coord.index % pattern.length
|
||||
return pattern[i]
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ export function post(context, cursor, buffers){
|
|||
txt += 'to change the aspect ratio:\n'
|
||||
txt += 'aspectRatio = ' + ar + '\n'
|
||||
|
||||
// Box style
|
||||
// Custom box style
|
||||
const style = {
|
||||
x : 3,
|
||||
y : 2,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
// Globals have module scope
|
||||
const chars = 'ABCxyz01═|+:. '.split('')
|
||||
const pattern = 'ABCxyz01═|+:. '.split('')
|
||||
|
||||
// This is the main loop.
|
||||
// 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 y = coord.y
|
||||
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 {
|
||||
char : chars[i],
|
||||
char : pattern[i],
|
||||
weight : '100', // or 'light', 'bold', '400'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ const cam = Camera.init()
|
|||
// For a debug view uncomment the following line:
|
||||
// cam.display(document.body, 10, 10)
|
||||
|
||||
const chars = sort(' .x?▂▄▆█'.split(''))
|
||||
const density = sort(' .x?▂▄▆█'.split(''))
|
||||
|
||||
export function pre(context, cursor, buffers){
|
||||
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){
|
||||
// Coord also contains the index of each cell:
|
||||
const color = buffers.data[coord.index]
|
||||
const index = Math.floor(color.gray / 255.0 * (chars.length-1))
|
||||
return chars[index]
|
||||
const index = Math.floor(color.gray / 255.0 * (density.length-1))
|
||||
return density[index]
|
||||
}
|
||||
|
||||
import { drawInfo } from '/src/modules/drawbox.js'
|
||||
|
|
|
@ -12,7 +12,7 @@ const cam = Camera.init()
|
|||
// For a debug view uncomment the following line:
|
||||
// cam.display(document.body, 10, 10)
|
||||
|
||||
const chars = ' .+=?X#ABC'.split('')
|
||||
const density = ' .+=?X#ABC'.split('')
|
||||
|
||||
// A custom palette used for color quantization:
|
||||
const pal = []
|
||||
|
@ -34,9 +34,9 @@ export function main(coord, context, cursor, buffers){
|
|||
// Coord also contains the index of each cell
|
||||
const color = buffers.data[coord.index]
|
||||
// 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 {
|
||||
char : chars[index],
|
||||
char : density[index],
|
||||
color : 'white',
|
||||
// convert {r,g,b} obj to a valid CSS hex string
|
||||
background : rgb2hex(color)
|
||||
|
|
|
@ -7,7 +7,7 @@ https://twitter.com/ntsutae/status/1292115106763960327
|
|||
[header]
|
||||
*/
|
||||
|
||||
const chars = "└┧─┨┕┪┖┫┘┩┙┪━".split('')
|
||||
const pattern = "└┧─┨┕┪┖┫┘┩┙┪━".split('')
|
||||
|
||||
export function main(coord, context, cursor, buffers){
|
||||
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 m = t2 * 2 % 30 + 31
|
||||
const i = (x + y^x - y) % m & 1
|
||||
const c = (t2 + i) % chars.length
|
||||
return chars[c]
|
||||
const c = (t2 + i) % pattern.length
|
||||
return pattern[c]
|
||||
}
|
||||
|
||||
import { drawInfo } from "/src/modules/drawbox.js"
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
[header]
|
||||
*/
|
||||
|
||||
const chars = [
|
||||
const pattern = [
|
||||
" _000111_ ".split(''),
|
||||
".+abc+. ".split('')
|
||||
]
|
||||
|
@ -25,7 +25,7 @@ export function main(coord, context, cursor, buffers){
|
|||
const i = f(Math.abs(x + y + o))
|
||||
const c = (f(coord.x * 0.09) + f(coord.y * 0.09)) % 2
|
||||
return {
|
||||
char : chars[c][i % chars[c].length],
|
||||
char : pattern[c][i % pattern[c].length],
|
||||
color : 'black', //col[c],
|
||||
background : 'white', //col[(c+1)%2],
|
||||
weight : weights[c],
|
||||
|
|
|
@ -5,15 +5,15 @@
|
|||
[header]
|
||||
*/
|
||||
|
||||
const chars = '┌┘└┐╰╮╭╯'.split('')
|
||||
const pattern = '┌┘└┐╰╮╭╯'.split('')
|
||||
|
||||
export function main(coord, context, cursor, buffers){
|
||||
const t = context.time * 0.0005
|
||||
const x = coord.x
|
||||
const y = coord.y
|
||||
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
|
||||
return chars[i]
|
||||
const i = Math.round(Math.abs(x + y + o)) % pattern.length
|
||||
return pattern[i]
|
||||
}
|
||||
|
||||
import { drawInfo } from '/src/modules/drawbox.js'
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { map } from '/src/modules/num.js'
|
||||
import { sdCircle, opSmoothUnion } from '/src/modules/sdf.js'
|
||||
|
||||
const chars = '#ABC|/:÷×+-=?*· '.split('')
|
||||
const density = '#ABC|/:÷×+-=?*· '.split('')
|
||||
|
||||
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));
|
||||
//if (d < 0) c = 0
|
||||
|
||||
const index = Math.floor(c * chars.length)
|
||||
return chars[index]
|
||||
const index = Math.floor(c * density.length)
|
||||
return density[index]
|
||||
}
|
||||
|
||||
function transform(p, trans, rot){
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { map } from '/src/modules/num.js'
|
||||
import { sdBox, opSmoothUnion } from '/src/modules/sdf.js'
|
||||
|
||||
let chars = '▚▀abc|/:÷×+-=?*· '.split('')
|
||||
let density = '▚▀abc|/:÷×+-=?*· '.split('')
|
||||
|
||||
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))
|
||||
const index = Math.floor(c * chars.length)
|
||||
return chars[index]
|
||||
const index = Math.floor(c * density.length)
|
||||
return density[index]
|
||||
}
|
||||
|
||||
function transform(p, trans, rot){
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { sdCircle } from '/src/modules/sdf.js'
|
||||
import { sort } from '/src/modules/sort.js'
|
||||
|
||||
const chars = sort('/\\MXYZabc!?=-. '.split(''))
|
||||
const density = sort('/\\MXYZabc!?=-. '.split(''))
|
||||
|
||||
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 d = sdCircle(st, radius)
|
||||
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 {
|
||||
char : coord.x % 2 ? '│' : chars[index],
|
||||
char : coord.x % 2 ? '│' : density[index],
|
||||
background : 'black',
|
||||
color : 'white'
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import { map } from '/src/modules/num.js'
|
|||
|
||||
export const settings = { fps : 60 }
|
||||
|
||||
const chars = ' -=+abcdX'.split('')
|
||||
const density = ' -=+abcdX'.split('')
|
||||
|
||||
// Shorthands
|
||||
const { vec3 } = v3
|
||||
|
@ -94,7 +94,7 @@ export function main(coord, context, cursor){
|
|||
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) {
|
||||
const x = coord.x % bgMatrixDim.x
|
||||
|
@ -102,7 +102,7 @@ export function main(coord, context, cursor){
|
|||
return d < 0 ? ' ' : bgMatrix[y][x]
|
||||
} else {
|
||||
return {
|
||||
char : chars[idx],
|
||||
char : density[idx],
|
||||
color : 'blue'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { sdCircle, opSmoothUnion } from '/src/modules/sdf.js'
|
||||
import { sub, vec2 } from '/src/modules/vec2.js'
|
||||
|
||||
const charMap = '#WX?*:÷×+=-· '.split('')
|
||||
const density = '#WX?*:÷×+=-· '.split('')
|
||||
|
||||
export function main(coord, context, cursor, buffers){
|
||||
const t = context.time
|
||||
|
@ -35,9 +35,9 @@ export function main(coord, context, cursor, buffers){
|
|||
|
||||
// Calc index of the char map
|
||||
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]
|
||||
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue