A
A
AndRussia2020-06-17 15:30:09
JavaScript
AndRussia, 2020-06-17 15:30:09

Canvas. Is it right to do this and is it possible to continue drawing figures in this form?

Hello. Is it correct to "draw" lines using the following code?:

var
            canv = document.getElementById('canvas'),
            ctx  = canv.getContext('2d');

        canv.width = window.innerWidth;
        canv.height = window.innerHeight;

        ctx.strokeStyle = 'red';
        ctx.lineWidth = 5;

        ctx.beginPath();
        ctx.moveTo(50,50);
        ctx.lineTo(25,100);
        ctx.lineTo(75,100);
        ctx.lineTo(50,50);
        ctx.stroke();

        ctx.strokeStyle = 'red';
        ctx.lineWidth = 5;

        ctx.beginPath();
        ctx.moveTo(150,150);
        ctx.lineTo(125,200);
        ctx.lineTo(175,200);
        ctx.closePath();
        ctx.stroke();

Does this code load the page, and is there an easier way? Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
quiplunar, 2020-06-17
@AndRussia

Yes, this code loads the page like any other code =)
Well, by drawing lines, you are unlikely to be able to load the page so that it is noticeable at least somehow. And there is no easier way. On pure js, this is the only way, perhaps there are libraries that make it easier to write code.
Tyk

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question