如何仅在语音draw()中执行一次功能;但仍会在整个动画中显示它

问题描述 投票:0回答:1

我在这里遇到麻烦。

基本上,我制作了具有多个功能的动画。除了要保持静止的功能外,我还希望对功能进行动画处理。

如果指定noLoop,则动画不会生效,如果我告诉该函数运行指定的次数,则在该次数之后它将停止显示。我想要的是让它运行一次,然后仍然显示。

你们是否知道我该怎么做?

这里是代码:

int r1,r2,r3 = 0;
int i1, i2,i3;

void setup(){
    size(800,800);
    background(255,0);
    //noLoop();
}

void draw(){
    background(255,0);
    rosace();

    croix();
    sillon1();
    sillon2();
}

void rosace(){
    for (i1 = 0;i1<230; i1++){

        rectMode(CENTER);

        noFill();
        stroke(20);
        strokeWeight(1);


        pushMatrix();
        translate(width/2,height/2);
        translate(400,400);
        rotate(radians(r1));
        rect(0,0,400,400);
        r1 +=1;
        //println(r);

        popMatrix();
        println("rosace ex");
    }
}

void croix(){

    pushMatrix();
    strokeWeight(2);
    stroke(0);
    translate(width/2, height/2);
    rotate(radians(45));
    line(-10,0,10,0);
    line(0,-10,0,10);
    popMatrix();
}

void sillon1(){
    for (i2 =0; i2<360; i2++){
        pushMatrix();

        translate(width/2,height/2);
        strokeWeight(int(random(0,7)));

        rotate(radians(r2));

        point(-330,0);

        popMatrix();
        r2 +=1;
    }
}

void sillon2(){
    for (i2 =0; i2<2000; i2++){
        pushMatrix();

        translate(width/2,height/2);
        strokeWeight(int(random(1,3)));

        rotate(radians(r2));

        point(-360,0+(random(-2,2)));

        popMatrix();
        r2 +=1;
    }
}

[void rosace();是我不想被动画化的那个。

processing
1个回答
0
投票

问题是您将r1存储为全局变量。这意味着它在每次迭代后都保持其价值。

相反,使其成为局部变量:

void rosace() {
    int r1 = 0;

    for (i1 = 0; i1<230; i1++) {
        rectMode(CENTER);

        noFill();
        stroke(20);
        strokeWeight(1);

        pushMatrix();
        translate(width/2, height/2);
        translate(400, 400);
        rotate(radians(r1));
        rect(0, 0, 400, 400);
        r1 +=1;

        popMatrix();
        println("rosace ex");
    }
}

0
投票

每帧都使用[Juse set r1 = 0

void rosace(){
    r1 = 0;

    for (i1 = 0;i1<230; i1++){
        // [...]
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.