Search code examples
loopsprocessingdrawshapesframes

Processing: PAppletClass causes loop, thus makes alpha dark


I'm using processing, just for test purposes in a trainings program.

When I use fill(alpha) it becomes dark the more frames there are, since (I assume) Processing creates more and more of the shapes, overlapping everytime a bit more. After executing draw() it goes back to PApplet and then back to draw() again.

Can I tell Programming to only execute draw() once without inventing some weird bypass?

half circles supposed to overlap on the edges

 public void draw(){

    int winkel=0;
    translate(300,300);
    fill(150, 15);

    for (int i =0;i<8;i++){

        rotate(radians(winkel));
       kreisschnitt(100,0,200,200,0, PI);
       winkel=winkel+45;
    }
}

public void kreisschnitt(int x, int y, int breite, int hoehe,float anfang, float ende){
    noStroke();

    arc(x,y,breite,hoehe,anfang,ende);

}

IDEA 2018.2 Java 8


Solution

  • Yes, the draw() loop is called 60 times per second by default.

    You can disable this by calling noLoop() which stops calling draw() until you call loop() again.

    Or you could move all of your code inside the setup() function, which is only called once.

    For simple sketches, you can get rid of all of your functions and write your code directly, like this:

    size(500, 500);
    background(32);
    ellipse(250, 250, 100, 100);