如何进行螺旋旋转?

时间:2017-11-07 20:15:02

标签: rotation processing increment spiral

我已成功使用线条编码静态螺旋,现在我应该使螺旋逐帧旋转。我尝试用每个帧递增用于行尾xy位置的角度,但螺旋线根本不移动。

void draw() {
    for (int i = 0; i < 15 * NUM_LINES; i++) {
        float lineEndX = width / 2 + radius * cos(angle + startAngle);
        float lineEndY = height / 2 + radius * sin(angle + startAngle);
        line (lineStartX, lineStartY, lineEndX, lineEndY);
        lineStartX = lineEndX;
        lineStartY = lineEndY;

        radius = radius + 0.047;
        angle += 0.01 % (TWO_PI * NUM_TURNS);
    }
    startAngle += START_ANGLE_CHANGE;
    angle = 0;
}

1 个答案:

答案 0 :(得分:0)

background(255);添加到您的draw功能中。同时定义lineStartXlineStartYradius,以便在每次调用函数时重置它们的值。

void draw() {
    background(255);
    float lineEndX = width / 2;
    float lineEndY = height / 2;
    float radius = 5;

    for (int i = 0; i < 15 * NUM_LINES; i++) {
        float lineEndX = width / 2 + radius * cos(angle + startAngle);
        float lineEndY = height / 2 + radius * sin(angle + startAngle);
        line (lineStartX, lineStartY, lineEndX, lineEndY);
        lineStartX = lineEndX;
        lineStartY = lineEndY;

        radius = radius + 0.047;
        angle += 0.01 % (TWO_PI * NUM_TURNS);
    }
    startAngle += START_ANGLE_CHANGE;
    angle = 0;
}

Working example here