mapmeld / crossword-unicode

Crossword generator that supports multiple languages
http://mapmeld.github.io/crossword-unicode/
7 stars 5 forks source link

Help with displaying resulting crossword riddle #6

Open s5m4 opened 5 years ago

s5m4 commented 5 years ago

Hi, this project looks very cool and I'd like to generate some crossword riddles for young students! Is there a full usage example that also includes rendering the canvas? Maybe this is not part of what this package can do? I would like to export or at least be able to see the resulting crossword riddle. What I have so far (and I'm running it in the powershell under windows): `var Canvas = require('canvas'); var Crossword = require('crossword');

var width = 20; var height = 15; var canv = new Canvas(40 width, 40 height);

var game = new Crossword(canv, width, height); // right-to-left scripts (Arabic, Hebrew, Divehi) // in these cases down = top->down, across = right->left game.setDirection('ltr'); game.clearCanvas(true);

var words = [];

words.push("schultuete") words.push("turnsackerl") words.push("lehrerin") words.push("tafel") words.push("jause") words.push("bleistift") words.push("turnsaal") words.push("buecher") words.push("kreide") words.push("lineal") words.push("schultasche") words.push("schere") words.push("fuellfeder") words.push("landkarte")

words.forEach(element => { game.addWord(element, function(err, clueAnchor, direction) { if(err){console.log(err)} console.log(element) console.log(direction) // direction = 'down' or 'across' }); });`

Thanks for any hints!

Kind regards, Stefan

mapmeld commented 5 years ago

Hi Stefan! You can get a PNG data URL from a JavaScript canvas or the node module canvas: canv.toDataURL() that you can use as the source of an img tag, or load in your browser.

With node-canvas, you optionally use a callback function canv.toDataURL((err, png) => { }) // defaults to PNG

mapmeld commented 5 years ago

The gh-pages branch at https://mapmeld.com/crossword-unicode/ is an example of how I would display the clues on the same page

mapmeld commented 5 years ago

@s5m4 did this work for you? There is some randomization, so it can take a few tries to get everything on the puzzle connected.

s5m4 commented 5 years ago

@mapmeld thanks for your kind response. I didn't get to it yet but I hope to find the time within the next few days. I will let you know how it turns out. Thank you!