javascript - 如何使用html5将网格绘制成圆形

标签 javascript math html5-canvas physics game-physics

我正在尝试使用 html5 将网格绘制成圆形,如下所示使用 paper js: enter image description here

但我不明白,这个解决方案在 JavaScript 中的正确逻辑是什么。按照我的脚本:

for (var _q=0,_qmax=(2*Math.PI),_qstep=(Math.PI/20); _q<_qmax; _q+=_qstep)
        {

            _sx = x+Math.sin(_q)*_radius;
            _sy = y+Math.cos(_q)*_radius;

             var path=new Path();
            path.strokeColor='white';
            path.strokeWidth=2;             
            path.moveTo(_sx,_sy);
            path.lineTo(_sy,_sx);
        }

最佳答案

终于我明白了,那里出了什么问题。很多人在没有正确答案的情况下给我投反对票。感谢他们“让我成长”。使用 Canvas x,y 坐标以下结构。

_draw_grid:function(_radius,_step,_color, _width)
    {
           var _group=new APP.RADAR.Group();
            for (var _q=0,_qmax=(2*Math.PI),_qstep=(Math.PI/_step); _q<_qmax; _q+=_qstep){
              _sx = APP.POSITION.x+Math.sin(_q)*_radius;
              _sy = APP.POSITION.y+Math.cos(_q)*_radius;

                var path=new APP.RADAR.Path();
                path.strokeColor=_color;
                path.strokeWidth=_width;
                path.moveTo(_sx,APP.POSITION.y*2-_sy);
                path.lineTo(_sx,_sy);
                _group.addChild(path);

            }
            for (var _q=0,_qmax=(2*Math.PI),_qstep=(Math.PI/_step); _q<_qmax; _q+=_qstep){
              _sx = APP.POSITION.x+Math.sin(_q)*_radius;
              _sy = APP.POSITION.y+Math.cos(_q)*_radius;

                var path=new APP.RADAR.Path();
                path.strokeColor=_color;
                path.strokeWidth=_width;
                path.moveTo(APP.POSITION.y*2-_sy,_sx);
                path.lineTo(_sy,_sx);
                _group.addChild(path);

            }
        return _group;
    },

关于javascript - 如何使用html5将网格绘制成圆形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25952916/

相关文章:

go - 为什么这个围棋结果一样呢?

javascript - Canvas 在调整屏幕大小时出现问题

javascript - HTML5 Canvas

javascript - 在 Canvas 中创建像动画一样嘈杂的混沌波

javascript - 如何获取特定表单FormData

javascript - Drupal Bootstrap 滚动与 Readmore 插件冲突

javascript - 使用 JavaScript API 的 Tableau 全屏 View

ios - 颜色计算 : increase alpha but maintain the same color appearance over a white background

javascript - 如何将总计添加到 amcharts 中的堆积条形图中

algorithm - 一种使用位翻转迭代所有 k 位数字的算法