You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppose we want to use SVG Tiler without a CLI or CLI-inspired ideas (like svgtiler()), just raw API calls from a Node/Coffee script. In this case we should gain huge flexibility in terms of using/combining multiple drawings (#97), or generating lots of SVG files from various tweaks of a single drawing (as in animations #72), etc. But we need the API to make it easy to do the main render loop in multiple ways.
Here's a sketch:
render=newRenderdrawing1=svgtiler.require'drawing1.asc'drawing2=svgtiler.require'drawing2.asc'# All in one:render.render layout, drawing1, mapping1
render.render layout, drawing2, mapping2
# Or perhaps make it easy to share layouts (but still allow changing):render.setLayout layout
render.render drawing1, mapping1
render.render drawing2, mapping2
# The `render` method would be shorthand for an explicit for loop over cells.# Note that this style doesn't require any actual mappings;# the code itself is acting as the mapping function.render.setLayout layout
drawing1.forEach ({key, i, j}) -># argument is Contextrender.addTile i, j, <symbolz-index="5">...</symbol>
drawing2.forEach ({key, i, j}) ->render.addTile i, j, ...svg content...# And finally write current content to SVG:render.writeSVG'filename.svg'
This whole thing could be in a for loop over an svgtiler.glob array, to render multiple files in a similar way. It's like a Maketile and a mapping in one. (In fact this could be a Maketile, provided it's wrapped in an export make = ->.) And because you can call render or forEach many times, it's far more powerful.
To make it even more interesting, Yev suggests pattern matching alternatives to forEach. For example:
# Constant-size patterndrawing.match [['o', 'x']
['x', 'o']], (context) ->...# Match horizontal patterns starting with a, b and ending with y, zdrawing.matchRow ['a', 'b'], ['y', 'z'], (context) -># Match vertical patterns starting with a, b and ending with y, zdrawing.matchColumn ['a', 'b'], ['y', 'z'], (context) -># Maybe also diagonal and antidiagonal patterns.# Strings could also be regular expressions or functions detecting match.
Context would be given more information now, like a range of is and js for the match, total bounding box, etc.
For example, the chess graph could get rendered as follows. I'm not sure this is really cleaner for this application, but it's an interesting alternative to have available.
Suppose we want to use SVG Tiler without a CLI or CLI-inspired ideas (like
svgtiler()
), just raw API calls from a Node/Coffee script. In this case we should gain huge flexibility in terms of using/combining multiple drawings (#97), or generating lots of SVG files from various tweaks of a single drawing (as in animations #72), etc. But we need the API to make it easy to do the main render loop in multiple ways.Here's a sketch:
This whole thing could be in a
for
loop over ansvgtiler.glob
array, to render multiple files in a similar way. It's like a Maketile and a mapping in one. (In fact this could be a Maketile, provided it's wrapped in anexport make = ->
.) And because you can callrender
orforEach
many times, it's far more powerful.To make it even more interesting, Yev suggests pattern matching alternatives to
forEach
. For example:Context would be given more information now, like a range of
i
s andj
s for the match, total bounding box, etc.For example, the chess graph could get rendered as follows. I'm not sure this is really cleaner for this application, but it's an interesting alternative to have available.
Related to #34.
forEach
addTile
match
The text was updated successfully, but these errors were encountered: