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

发布于 2024-07-09 06:01:27 字数 26 浏览 11 评论 0原文

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

What is the algorithm for storing the pixels in a spiral in JS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仙气飘飘 2024-07-16 06:01:27

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

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);

Sample implementation at http://myweb.uiowa.edu/timv/spiral.htm

倒数 2024-07-16 06:01:27

这个问题有几个问题。 首先,你并没有真正具体说明你在做什么。

1) Javascript 并不是真正的存储介质,除非您希望使用 JSON 传输像素,在这种情况下您可能需要重新措辞以明确说明这一点。

2)没有提到你期望的螺旋是什么样子——我们是在谈论松散的螺旋还是紧密的螺旋? 单色、渐变或一系列颜色? 您正在寻找弯曲的螺旋形还是矩形的螺旋形?

3)这里的最终目标是什么? 你是想直接使用JS绘制螺旋还是将其传输到其他地方?

There are a couple of problems with this question. The first is that you're not really being specific about what you're doing.

1) Javascript isn't really a storage medium, unless you're looking to transmit the pixels using JSON, in which case you may want to rephrase to explicitly state that.

2) There's no mention of what you expect the spiral to look like - are we talking about a loose spiral or a tight spiral? Monocolor or a gradient or a series of colors ? Are you looking at a curved spiral or a rectangular one?

3) What is the final aim here? Are you looking to draw the spiral directly using JS or are you transmitting it to some other place?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文