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

  • Home
  • SEARCH
  • 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 8749203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:39:18+00:00 2026-06-13T12:39:18+00:00

I am developing an application with HTML5 Canvas that displays a collection of shapes.

  • 0

I am developing an application with HTML5 Canvas that displays a collection of shapes. On each shape I want one of the shape sides to have a stroke, but cannot do this without giving all sides a stroke or by using seperate lines and breaking the shape, stopping it from having a fill.

How would i draw a shape with a stroke on one side and a fill?

Thanks in advance.

  • 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-13T12:39:19+00:00Added an answer on June 13, 2026 at 12:39 pm

    One way is to call stroke when you aren’t fully done with the path, thus only stroking what you have already plotted out. Obviously though if you don’t draw the side first you want stroked this wont work, so there’s another option below.

    ​var canvas = document.getElementById("canvas"),
        ctx = canvas.getContext("2d");
    
    canvas.width = canvas.height = 256;
    
    ​ctx.fillStyle = "red";
    ctx.strokeStyle = "black";
    ctx.lineWidth = 2;
    
    ctx.beginPath();
    ctx.moveTo(50,50);
    ctx.lineTo(100,100);
    ctx.stroke();
    ctx.lineTo(100,200);
    ctx.lineTo(50,100);
    ctx.lineTo(50,50);
    ctx.fill();
    

    ​Live Demo

    This is just a quick dirty proof of concept function as another way to achieve what you’re looking for.

    Live Demo 2

    var shape = [{x:50,y:50}, {x:100, y:100}, {x:100, y:200}, {x:50,y:100}, {x:50, y:50}];
    
    function drawShape(shape, strokeIndex){
        ctx.beginPath();
        ctx.moveTo(shape[0].x, shape[0].y);
    
        for(var i = 1; i < shape.length; i++){
            ctx.lineTo(shape[i].x, shape[i].y);   
        }
        ctx.closePath();
        ctx.fill();
    
        // stroke
        ctx.beginPath();
        ctx.moveTo(shape[strokeIndex-1].x, shape[strokeIndex-1].y);
        ctx.lineTo(shape[strokeIndex].x, shape[strokeIndex].y);
        ctx.stroke();
    }
    
    drawShape(shape, 3);
    

    ​

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

Sidebar

Related Questions

I'm developing an HTML5 application. I want to parse an XML like this one:
I am developing HTML5 based paint application using canvas, and now I want to
I am working on developing a sketching application on HTML5 Canvas . I have
I'm developing a HTML5 application that uses jQuery. I want to make it multi
I'm developing a web game application with a, HTML5 canvas that has to react
I am currently developing a little sketching application based on HTML5 Canvas element. There
I am developing one application. In that app I am getting the html content
I am developing a mobile application with jquery mobile and html5. One Part of
I'm developing an application where users draw euclidean constructions on the HTML5 canvas. As
I am developing one web application in HTML5 and js. And I am using

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.