handwriting.js icon indicating copy to clipboard operation
handwriting.js copied to clipboard

Congratulations! Amazing script!

Open inglesuniversal opened this issue 3 years ago • 4 comments

I will be teaching some children how to write their first words and this script is exactly what I was looking for.

Thank you so much!

Quick question: How to change the pen or ink color from black (current color) to white?

Thanks

inglesuniversal avatar Aug 24 '21 00:08 inglesuniversal

You can set stroke style before stroke(), i.e., https://github.com/ChenYuHo/handwriting.js/blob/6d41109d3293295a7d7678d0cb97f483d28f47ec/handwriting.canvas.js#L93 and https://github.com/ChenYuHo/handwriting.js/blob/6d41109d3293295a7d7678d0cb97f483d28f47ec/handwriting.canvas.js#L140

e.g.,

this.cxt.strokeStyle = '#ff0000'; // make the following stroke red
this.cxt.stroke(); 

You may also add a color selector and set this.cxt.strokeStyle so that one can control the color of every stroke.

ChenYuHo avatar Aug 24 '21 00:08 ChenYuHo

Great... It worked like a charm. Now, how can I make the canvas responsive to:

width: calc(100vh - 20px); height: 400px

It works visually but pen location and erase button works awkwardly.

var canvas = new handwriting.Canvas(document.getElementById('canvas'), 5); var width = document.getElementById("demo").clientWidth canvas.cxt.canvas.width = width < 400 ? width : 400; canvas.cxt.canvas.height = width < 400 ? width : 400;

inglesuniversal avatar Aug 26 '21 05:08 inglesuniversal

Great... It worked like a charm. Now, how can I make the canvas responsive to:

width: calc(100vh - 20px); height: 400px

It works visually but pen location and erase button works awkwardly.

var canvas = new handwriting.Canvas(document.getElementById('canvas'), 5); var width = document.getElementById("demo").clientWidth canvas.cxt.canvas.width = width < 400 ? width : 400; canvas.cxt.canvas.height = width < 400 ? width : 400;

You can use javascript to set the width and height before calling handwriting.Canvas:

    const vw = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0) - 20;
    const vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0);
    document.getElementById("can").width = vw;
    document.getElementById("can").height = vh;
    var can1 = new handwriting.Canvas(document.getElementById("can"));

lojik-ng avatar Nov 22 '22 22:11 lojik-ng

@ChenYuHo you did it again!

LOVE IT

I works beautifully

inglesuniversal avatar Mar 30 '23 11:03 inglesuniversal