Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9038481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:29:58+00:00 2026-06-16T09:29:58+00:00

I have implemented line drawing in canvas . But I faced a problem: when

  • 0

I have implemented line drawing in canvas. But I faced a problem:

when line width is small (3), curved line looks nice;

when line width is large (20), curved line looks not good because of breaks.

enter image description here

canvas.node.onmousemove = function (e) {
         if (!canvas.isDrawing) {
             return;
         }
         var x = e.pageX - this.offsetLeft;
         var y = e.pageY - this.offsetTop;
         ctx.beginPath();
         ctx.moveTo(canvas.lastX, canvas.lastY);
         ctx.strokeStyle = '#000000';
         ctx.lineWidth = self.lineWidth();
         ctx.lineTo(x, y);
         ctx.stroke();
         ctx.closePath();
         canvas.lastX = x;
         canvas.lastY = y;
};
canvas.node.onmousedown = function (e) {
         canvas.isDrawing = true;
         canvas.lastX = e.pageX - this.offsetLeft;
         canvas.lastY = e.pageY - this.offsetTop;
};
canvas.node.onmouseup = function (e) {
         canvas.isDrawing = false;
};

How can I avoid breaks in large lines and make my line solid?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:29:59+00:00Added an answer on June 16, 2026 at 9:29 am

    Have you tried setting the lineJoin property to your canvas context?

    Add the following line after you set your lineWidth.

    ctx.lineJoin = 'round';
    

    This will not work if you have closed your path before completing rendering all the lineTo‘s using ctx.closePath().

    You will have to open the path before you start drawing the line and close it after you have finished drawing the line.

    Also if you move the drawing cursor using moveTo during drawing the lineJoin doesn’t come into play.

    You can try the following modified code (I have also included a JSFiddle link in the end).

    EDIT 1: Updated the code as I forgot to add the lineJoin property to it.

    EDIT 2: Moved the moveTo line to the appropriate listener method.

    canvas.node.onmousemove = function (e) {
             if (!canvas.isDrawing) {
                 return;
             }
             var x = e.pageX - this.offsetLeft;
             var y = e.pageY - this.offsetTop;
    
             ctx.lineTo(x, y);
             ctx.stroke();
    
             canvas.lastX = x;
             canvas.lastY = y;
    };
    canvas.node.onmousedown = function (e) {
             canvas.isDrawing = true;
             canvas.lastX = e.pageX - this.offsetLeft;
             canvas.lastY = e.pageY - this.offsetTop;
    
             ctx.moveTo(canvas.lastX, canvas.lastY);
             ctx.beginPath();
             ctx.strokeStyle = '#000000';
             ctx.lineWidth = self.lineWidth();
             ctx.lineJoin = 'round';
    
    };
    canvas.node.onmouseup = function (e) {
             ctx.closePath();
             canvas.isDrawing = false;
    };
    

    Working JSFiddle here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented pagination to my data, but the problem is I only have
I have implemented a small command line interface using JewelCLI and it creates an
While working with Akka, I have implemented a simple command line app. But Akka
i have implemented a small viewDidLoad() to show an Picture with autoresizing, but it
I have implemented the sweep-line approach used by Domiter and Zalik to generate a
I have implemented Facebook into my app but now I find that whenever I
I have a Canvas on which I am drawing lines bewteen points in a
I want to implement a text drawing function. But I am not sure how
I have implemented Naive Bayes algorithm on a large data set of 410k rows.Now
I have implemented a test for self-intersection of a polygon. Because Performance is not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.