当前位置:  开发笔记 > 编程语言 > 正文

在JS中以螺旋形式存储像素的算法是什么?

如何解决《在JS中以螺旋形式存储像素的算法是什么?》经验,为你挑选了1个好方法。

在JS中以螺旋形式存储像素的算法是什么?



1> tvanfosson..:

http://www.mathematische-basteleien.de/spiral.htm

var Spiral = function(a) {
    this.initialize(a);
}

Spiral.prototype = {
    _a: 0.5,

    constructor: Spiral,

    initialize: function( a ) {
       if (a != null) this._a = a;
    },


    /* specify the increment in radians */
    points: function( rotations, increment ) {
       var maxAngle = Math.PI * 2 * rotations;
       var points = new Array();

       for (var angle = 0; angle <= maxAngle; angle = angle + increment)
       {
          points.push( this._point( angle ) );
       }

       return points;
    },

    _point: function( t ) {
        var x = this._a * t * Math.cos(t);
        var y = this._a * t * Math.sin(t);
        return { X: x, Y: y };
    }
}


var spiral = new Spiral(0.3);
var points = spiral.points( 2, 0.01 );

plot(points);

http://myweb.uiowa.edu/timv/spiral.htm上的示例实施

推荐阅读
郑谊099_448
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有