Make an arrow appear at a certain time and then disappear...

Hi

Very new to processing and I'm trying to get an arrow to appear at a certain time and then disappear shortly lately. Not sure if there's an easy fix or I'm missing something completely obvious. Any help or pointers in the right direction will be greatly appreciated.

` int startTime; int circleSize = 0;

void setup() {
  surface.setTitle("PAIN");
  size(800, 800);
  smooth();
  startTime = millis();
}

void draw() {
  background(225);
  fill(255, 255, 255);
  if (millis() - startTime > 500) {
    grid();
  }
  fill(255, 255, 0);

  if (millis() - startTime > 1000) {
    growCircle(50, 50);
    growCircle(50, 450);
    growCircle(450, 50);
    growCircle(450, 450);
  }

  if (millis() - startTime > 2000) {
    drawArrow(50, 50, 240, 45);
    drawArrow(50, 450, 240, 315);
    drawArrow(450, 50, 240, 135);
    drawArrow(450, 450, 240, 225);
    growCircle(250, 250);
    if (millis() - startTime > 2200) {
      background(226);
    }
  }
}

void grid() {
  for (int row = 0; row < 5; row++) {
    for (int column = 0; column < 5; column++) {
      ellipse(50+column*100, 50+row*100, 80, 80);
    }
  }
}

void growCircle(float posX, float posY) {
  ellipse(posX, posY, circleSize, circleSize);
  if (circleSize < 80) {
    circleSize = circleSize + 1;
  } else {
    circleSize = 80;
  }
}

void drawArrow(int cx, int cy, int len, float angle) {
  pushMatrix();
  translate(cx, cy);
  rotate(radians(angle));
  line(0, 0, len, 0);
  line(len, 0, len - 8, -8);
  line(len, 0, len - 8, 8);
  popMatrix();
}

`

Answers

  • Answer ✓

    No, your approach is fine. Here the arrows stop appearing after a second:

    int startTime; int circleSize = 0;
    
    void setup() {
      surface.setTitle("PAIN");
      size(800, 800);
      smooth();
      startTime = millis();
    }
    
    void draw() {
      background(225);
      fill(255, 255, 255);
      if (millis() - startTime > 500) {
        grid();
      }
      fill(255, 255, 0);
    
      if (millis() - startTime > 1000) {
        growCircle(50, 50);
        growCircle(50, 450);
        growCircle(450, 50);
        growCircle(450, 450);
      }
    
      if (millis() - startTime > 2000 && millis()-startTime<3000 ) {
        drawArrow(50, 50, 240, 45);
        drawArrow(50, 450, 240, 315);
        drawArrow(450, 50, 240, 135);
        drawArrow(450, 450, 240, 225);
        growCircle(250, 250);
      }
    }
    
    void grid() {
      for (int row = 0; row < 5; row++) {
        for (int column = 0; column < 5; column++) {
          ellipse(50+column*100, 50+row*100, 80, 80);
        }
      }
    }
    
    void growCircle(float posX, float posY) {
      ellipse(posX, posY, circleSize, circleSize);
      if (circleSize < 80) {
        circleSize = circleSize + 1;
      } else {
        circleSize = 80;
      }
    }
    
    void drawArrow(int cx, int cy, int len, float angle) {
      pushMatrix();
      translate(cx, cy);
      rotate(radians(angle));
      line(0, 0, len, 0);
      line(len, 0, len - 8, -8);
      line(len, 0, len - 8, 8);
      popMatrix();
    }
    
  • I feel so silly. Just worked this out. Thank you so much though.

Sign In or Register to comment.