Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Draw random 'X' and remain drawing to same location.

$
0
0

Hi there, My issue is with the drawX() function. At the moment it draws an 'X' in a random place which then disappears as the next frame of 'myVid' refreshes the screen. I want to be able to draw each individual 'X' to its random location but then continue draw to that same location throughout the sketch. Thus resulting in an ever growing number of 'X's across the screen. I think i need to assign each individual 'X' to an array as it is drawn in order for it to maintain its (x,y) position. But i am not sure how to go about this. Hope this is clear. Any help would be greatly appreciated:

PFont font;
import processing.video.*;
Movie myVid;
String letter = "X";
float x;
float y;
float interval  = 1200;
float currentTime;
int offset = 100;

void setup() {
  size(540, 540);
  background(254);
  myVid = new Movie(this, "seaClip_001.mp4");
  myVid.loop();
  //frameRate(0.5);
}

void draw() {
  image(myVid, 0, 0-offset, 540, 540);
  drawFrame();
  drawX();
}

void drawFrame() {
  shapeMode(CENTER);
  fill(1);
  rect(width/2, 0, 10, height);
  shapeMode(LEFT);
  rect(0, 390, width, 10);
  //fill(color'ffa7e8');
  fill(255, 167, 232);
  rect(0, 400, width, 140);
}

void drawX() {
  fill(0);
  font = createFont("Arial", 1);
  textFont(font);
   x = random(width);
   y = random(height);
  if (currentTime > 1000)
    textSize(random(120, 500));
  text(letter, x, y);
  currentTime = millis() % interval; //
}

void movieEvent(Movie m) {
  m.read();
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles