4 Jan 2022, 13:58

@z3dev it's the tiniest set of numbers that I use on designs that renders lots of them to minimize their impact, it's not very good looking but it enables my script to render with models having lots of triangles that would hang using nice character sets, but I could certainly make it look a little better. Here's code to render numbers that way :

const jscad = require('@jscad/modeling')
const { line, cube, rectangle, circle, polygon, sphere } = jscad.primitives
const { measureBoundingBox, measureDimensions, measureAggregateBoundingBox, measureCenter } = jscad.measurements
const { rotateZ, translate, translateX, scale, center, align } = jscad.transforms
const { colorize, colorNameToRgb } = jscad.colors
const { toPolygons } = jscad.geometries.geom3
const { union } = jscad.booleans
const { vec3 } = jscad.maths
const { radToDeg, degToRad } = jscad.utils

const c_red   = [1  , 0, 0],
      c_blue  = [0  , 0, 1],
      c_green = [0  , 1, 0],
      c_maroon= [0.5, 0, 0],
      c_yellow= [1  , 1, 0],
      c_black = [0  , 0, 0]


function main() {
var r = []
r.push(colorize(c_black, number('01234',1, 0, 0)))
r.push(colorize(c_black, number('56789',1, 0, -20)))

return r
}

function number(n, s, x, y){ // number,scale, coordinates
 var ch = n.toString().split("").map(Number), r = [], dkX = 0
 for(var i = 0; i < ch.length; i++){
   var nl = line(digit(ch[i], s).map(v => [
     v[0]+dkX+x-(6*s)*ch.length, 
     v[1]+y-1.25*s
    ]))
   r.push(nl)
   var b = measureBoundingBox(nl)
   dkX += b[1][0] - b[0][0] + 4 * s
 }
 
 return r
}

function digit(num, scale = 1){
  var np = [
[[0,0],[0,16],[8,16],[8,0],[0,0]],
[[0,8],[8,16],[8,0]],
[[0,12],[0,16],[8,16],[8,8],[0,8],[0,0],[8,0]],
[[0,13],[0,16],[8,16],[8,11],[4,8],[8,5],[8,0],[0,0],[0,3]],
[[8,8],[0,8],[6,16],[6,0]],
[[8,16],[0,16],[0,8],[8,8],[8,0],[0,0]],
[[8,16],[0,8],[0,0],[8,0],[8,8],[0,8]],
[[0,16],[8,16],[0,0]],
[[4,9],[1,12],[1,16],[7,16],[7,12],[4,9],[8,7],[8,0],[0,0],[0,7],[4,9]],
[[8,8],[0,8],[0,16],[8,16],[8,0],[0,0]]
]
  return np[num].map(x => x.map(y => y * scale))
}



module.exports ={ main }