<bdo id='pNP5H'></bdo><ul id='pNP5H'></ul>

<small id='pNP5H'></small><noframes id='pNP5H'>

<legend id='pNP5H'><style id='pNP5H'><dir id='pNP5H'><q id='pNP5H'></q></dir></style></legend>

    1. <i id='pNP5H'><tr id='pNP5H'><dt id='pNP5H'><q id='pNP5H'><span id='pNP5H'><b id='pNP5H'><form id='pNP5H'><ins id='pNP5H'></ins><ul id='pNP5H'></ul><sub id='pNP5H'></sub></form><legend id='pNP5H'></legend><bdo id='pNP5H'><pre id='pNP5H'><center id='pNP5H'></center></pre></bdo></b><th id='pNP5H'></th></span></q></dt></tr></i><div id='pNP5H'><tfoot id='pNP5H'></tfoot><dl id='pNP5H'><fieldset id='pNP5H'></fieldset></dl></div>
    2. <tfoot id='pNP5H'></tfoot>

      1. 中间有洞的多边形,带有 HTML5 的画布

        时间:2023-06-20

          <bdo id='yGaIK'></bdo><ul id='yGaIK'></ul>
          <tfoot id='yGaIK'></tfoot>

          <small id='yGaIK'></small><noframes id='yGaIK'>

          <i id='yGaIK'><tr id='yGaIK'><dt id='yGaIK'><q id='yGaIK'><span id='yGaIK'><b id='yGaIK'><form id='yGaIK'><ins id='yGaIK'></ins><ul id='yGaIK'></ul><sub id='yGaIK'></sub></form><legend id='yGaIK'></legend><bdo id='yGaIK'><pre id='yGaIK'><center id='yGaIK'></center></pre></bdo></b><th id='yGaIK'></th></span></q></dt></tr></i><div id='yGaIK'><tfoot id='yGaIK'></tfoot><dl id='yGaIK'><fieldset id='yGaIK'></fieldset></dl></div>
          <legend id='yGaIK'><style id='yGaIK'><dir id='yGaIK'><q id='yGaIK'></q></dir></style></legend>

                <tbody id='yGaIK'></tbody>

                • 本文介绍了中间有洞的多边形,带有 HTML5 的画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  使用 <canvas> 标签我需要能够在多边形中绘制一个洞.

                  Using the <canvas> tag I need to be able to draw a hole in a polygon.

                  现在我有一些非常简单的方法,它使用 beginPath() 然后为每个点执行 lineTo().然后用 fill() 填充.

                  Right now I have something very simple that uses beginPath() then does lineTo() for each point. It is then filled with fill().

                  我看不出有什么方法可以让一个填充的多边形中间没有填充,就像一个甜甜圈.我不是在做甜甜圈,但它适合这个例子.

                  I cannot see any way to have a filled polygon with a unfilled middle though, like a donut. I'm not making a donut but it is suitable for this example.

                  我有什么遗漏吗?我宁愿不把它画满,然后不得不重画中间.

                  Is there something I am missing? I would rather not draw it fully filled then have to redraw the middle.

                  推荐答案

                  这是我做的:

                  var ctx = canvas.getContext("2d");     
                  ctx.beginPath();
                  
                  //polygon1--- usually the outside polygon, must be clockwise
                  ctx.moveTo(0, 0);
                  ctx.lineTo(200, 0);
                  ctx.lineTo(200, 200);
                  ctx.lineTo(0, 200);
                  ctx.lineTo(0, 0);
                  ctx.closePath();
                  
                  //polygon2 --- usually hole,must be counter-clockwise 
                  ctx.moveTo(10, 10);
                  ctx.lineTo(10,100);
                  ctx.lineTo(100, 100);
                  ctx.lineTo(100, 10);
                  ctx.lineTo(10, 10);
                  ctx.closePath();
                  
                  //  add as many holes as you want
                  ctx.fillStyle = "#FF0000";
                  ctx.strokeStyle = "rgba(0.5,0.5,0.5,0.5)";
                  ctx.lineWidth = 1;
                  ctx.fill();
                  ctx.stroke();
                  

                  这里的主要思想是你只能使用一次 beginPath;外部多边形必须是顺时针方向,孔必须是逆时针方向.

                  The main idea here is you can only use beginPath once; the outside polygon must be clockwise and holes must be counter-clockwise.

                  这篇关于中间有洞的多边形,带有 HTML5 的画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在带有背景的画布上书写文本 下一篇:缩放 HTML5 画布宽度保留 w/h 纵横比

                  相关文章

                  <tfoot id='wh3co'></tfoot>

                  <small id='wh3co'></small><noframes id='wh3co'>

                • <i id='wh3co'><tr id='wh3co'><dt id='wh3co'><q id='wh3co'><span id='wh3co'><b id='wh3co'><form id='wh3co'><ins id='wh3co'></ins><ul id='wh3co'></ul><sub id='wh3co'></sub></form><legend id='wh3co'></legend><bdo id='wh3co'><pre id='wh3co'><center id='wh3co'></center></pre></bdo></b><th id='wh3co'></th></span></q></dt></tr></i><div id='wh3co'><tfoot id='wh3co'></tfoot><dl id='wh3co'><fieldset id='wh3co'></fieldset></dl></div>
                  • <bdo id='wh3co'></bdo><ul id='wh3co'></ul>

                • <legend id='wh3co'><style id='wh3co'><dir id='wh3co'><q id='wh3co'></q></dir></style></legend>