Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Congratulations! Amazing script! #4

Open
inglesuniversal opened this issue Aug 24, 2021 · 4 comments
Open

Congratulations! Amazing script! #4

inglesuniversal opened this issue Aug 24, 2021 · 4 comments

Comments

@inglesuniversal
Copy link

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

@ChenYuHo
Copy link
Owner

You can set stroke style before stroke(), i.e.,

this.cxt.stroke();
and
this.cxt.stroke();

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.

@inglesuniversal
Copy link
Author

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;

@lojik-ng
Copy link

lojik-ng commented Nov 22, 2022

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"));

@inglesuniversal
Copy link
Author

@ChenYuHo you did it again!

LOVE IT

I works beautifully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants