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 6704291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:16:17+00:00 2026-05-26T07:16:17+00:00

strange issue with HTML5 canvas: I am trying to draw one shape inside another.

  • 0

strange issue with HTML5 canvas: I am trying to draw one shape inside another. The outer shape is blue and the inner one red, but the end result is that both shapes end up red. If I step through the code, I can see the blue shape rendered correctly, but then the red shape renders over the blue one, even though it’s smaller. Probably a problem with BeginPath/EndPath stuff, but I’ve seemingly tried every combination with no luck. I have lots more shapes to draw after this one, so I need to figure out how to correctly begin/end a shape before I resume work. Any help is appreciated.

     <script type="text/javascript">
            window.onload = function () {
                var drawingCanvas = document.getElementById('canvas1');

                // Is element in the DOM and does browser support canvas
                if (drawingCanvas && drawingCanvas.getContext) {
                    // Init drawing context
                    var InfieldColor = "#BDB76B";
                    var OutfieldColor = "#F5F5F5";

                    var iGrassLen = Math.min(drawingCanvas.width, drawingCanvas.height) * 0.7;
                    var iRad = iGrassLen * 1.475;
                    var iAng = -60 * Math.PI / 180;
                    var iptInfBez0x = iRad * Math.cos(iAng);
                    var iptInfBez0y = -(iRad * Math.sin(iAng));

                    iAng = -30 * Math.PI / 180;
                    var iptInfBez1x = iRad * Math.cos(iAng);
                    var iptInfBez1y = -(iRad * Math.sin(iAng));
                    var iInfieldLen = (iGrassLen * (88 / 124));

                    var iBaseLen = iInfieldLen / 12;

                    //this is the relative offset between Dixon infield and outfield
                    var iOutfieldLen = iGrassLen * (282 / 124)

                    //bezier control points for outfield circle
                    iRad = iOutfieldLen * 1.31;
                    iAng = -60 * Math.PI / 180;
                    var iptOutBez0x = iRad * Math.cos(iAng);
                    var iptOutBez0y = -(iRad * Math.sin(iAng));

                    iAng = -30 * Math.PI / 180;
                    var iptOutBez1x = iRad * Math.cos(iAng);
                    var iptOutBez1y = -(iRad * Math.sin(iAng));

                    var iHRLen0 = (340 * iInfieldLen / 90) * 1.025;      //iInfieldLen = 90 feet. (plus a fudge factor)
                    var iHRLen1 = (370 * iInfieldLen / 90) * 1.025;
                    var iHRLen2 = (400 * iInfieldLen / 90) * 1.025;

                    var iMoundWid = iInfieldLen / 10;

                    var context = drawingCanvas.getContext('2d');

                    context.fillStyle = "#FFFF00";
                    context.fillRect(0, 0, drawingCanvas.width, drawingCanvas.height);

                    context.beginPath;
                    context.moveTo(0, 0);
                    context.lineTo(iGrassLen, 0);
                    context.bezierCurveTo(iptInfBez1x, iptInfBez1y, iptInfBez0x, iptInfBez0y, 0, iGrassLen); // bezier curve
                    context.lineTo(0, 0);
                    context.closePath();
                    context.fillStyle = "blue";
                    context.fill();
                    context.lineWidth = 1;
                    context.strokeStyle = "black";
                    context.stroke();

                    //infield rectangle
                    context.beginPath;
                    context.rect(0, 0, iInfieldLen - (iBaseLen / 4), iInfieldLen - (iBaseLen / 4));
                    context.closePath;
                    context.fillStyle = "red";
                    context.fill();
                    context.lineWidth = 1;
                    context.strokeStyle = "black";
                    context.stroke();

                }
            }
        </script>
  • 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-05-26T07:16:18+00:00Added an answer on May 26, 2026 at 7:16 am
    context.beginPath;
    ...
    context.closePath;
    

    You forgot (). Without that, these are just discarded references to a function, not calls to it.

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

Sidebar

Related Questions

I have a strange issue: I am using SPContext.Current.Web in a .aspx page, but
I'm facing a strange issue, I'm trying to localize a website, so i converted
This is a really strange issue. One day my project started to do a
this issue is kinda strange, and happens only in Firefox (v. 3.6.6 but also
Have following strange issue, have 7 lines (same classes) but after 2 lines it's
I'm having a rather strange issue with the Google Maps javascript API and HTML5
I am having a strange issue with trying to style a link as a
I'm having a bit of a strange issue with Nokogiri in Rails. I'm trying
I'm experiencing a strange issue where my Visual Studio 2005 C++ program crashes the
I am facing strange issue on Windows CE: Running 3 EXEs 1)First exe doing

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.