Clear the stage with HYPE framework

edited December 2016 in Library Questions

Hi guys,

I'm new to the forum and hope one of you can help me. I started working with processing after quite some time and love the ease of use. Also started with the HYPE framework and am amazed at the possibilities.

I want to know how to clear the stage before a draw loop. I have a perlin noise field and want to rotate the arrows, based on the z value of the perlin noise. It draws the stage, but with every loop, it keeps adding more lines. I somewhat understand what's going on, since I keep on adding more and more objects to H with each loop. But I can't find how to remove all objects or clear the stage for that matter.

Hopefully one of you can help me out, since I'm not finding anything in the documentation so far. Thanks!

import hype.*;

float inc = 0.05;
float scl = 10;
int cols,rows;
float zOff, xOff, yOff = 0;
HRect d;


void setup() {
    size(500,500);

    smooth();

    cols = floor(width/scl);
    rows = floor(height/scl);

    H.init(this).background(#ffffff).autoClear(true);


}

void draw(){

    yOff = 0;

    for (int y = 0; y < rows; ++y) {

        xOff = 0;

        for (int x = 0; x < cols; ++x) {

            float r = noise(xOff, yOff, zOff) * 255;

            d = new HRect();
            d
                .loc(x*scl, y*scl)
                .fill(#000000)
                .size(1,scl)
                .strokeWeight(0)
                .rotate(r);
            ;

            xOff += inc;

            H.add(d);

        }

        yOff += inc;
    }

    H.drawStage();



    zOff +=0.1;

}

Answers

  • edited January 2017

    @premiumBlend --

    I'm not very familiar with Hype framework specifically -- are you using it with Processing, or with ProcessingJS?

    In Processing what you call "clearing the stage" is the background() command, am I right?

    So here is the Processing "continuous lines" demo sketch: https://processing.org/examples/continuouslines.html

    void setup() {
      size(640, 360);
      background(102);
    }
    
    void draw() {
      stroke(255);
      if (mousePressed == true) {
        line(mouseX, mouseY, pmouseX, pmouseY);
      }
    }
    

    ...and here it is again, but this time with the background(COLOR) command added at the top of draw to "clear the stage" each draw loop:

    void setup() {
      size(640, 360);
      background(102);
    }
    
    void draw() {
      background(102);
      stroke(255);
      if (mousePressed == true) {
        line(mouseX, mouseY, pmouseX, pmouseY);
      }
    }
    
  • your lines 25 to 52 belong into setup() and not into draw() ?

  • edited May 2017

    Enjoy this solution, that works (no one never answers this easy solution: delete objects from the stage). First you have to save that objects somewhere (an array is the easiest one that works):

    import hype.*;
    
    float inc = 0.05;
    float scl = 10;
    int cols,rows;
    float zOff, xOff, yOff = 0;
    HRect d;
    
    HRect [] objectsInStage;
    int indexInStage;
    
    
    void setup() {
        size(500,500);
    
        smooth();
    
        cols = floor(width/scl);
        rows = floor(height/scl);
    
        H.init(this).background(#ffffff).autoClear(true);
    
        objectsInStage=new HRect[cols*rows];
    
    
    }
    
    void draw(){
    
        indexInStage=0;
    
        yOff = 0;
    
    
    
        for (int y = 0; y < rows; ++y) {
    
            xOff = 0;
    
            for (int x = 0; x < cols; ++x) {
    
                float r = noise(xOff, yOff, zOff) * 255;
    
                d = new HRect();
                d
                    .loc(x*scl, y*scl)
                    .fill(#000000)
                    .size(1,scl)
                    .strokeWeight(0)
                    .rotate(r);
                ;
    
                xOff += inc;
    
                H.add(d);
    
                objectsInStage[indexInStage++]=d;
    
            }
    
            yOff += inc;
        }
    
        H.drawStage();
    
    
    
        zOff +=0.1;
    
        for (int i=0;i<indexInStage;i++)
        {
          H.remove(objectsInStage[i]);
        }
    
    }
    
Sign In or Register to comment.