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

Double buffering?? But how do I do this!? - Programmers please assist!

$
0
0

Working in Processing, I have a generative program that creates a random colorful image.

An ellipse randomizes its direction each frame and draws on the canvas, leaving it's trail, creating the art canvas. furthermore, everytime the ellipse hits the edge of the screen, it returns to the middle, with a new color, and begins again.

I want to have this giphy of bob ross follow the same location of the randomized x and y, of the ellipse that draws. yet, I don't want bobross also to leave a trail on the screen, for it ruins the art.

this is my code:

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;

PImage[] bobross = new PImage[78];
int counter = 0;

Minim minim;
AudioSample boop;
AudioSample boopp;
AudioPlayer bg;


float ex = 0;
float ey = 0;
float direction = random(-3, 3);
float ddirection = random(-3, 3);
String str = "01234";
int p0 = str.indexOf("0");
int p1 = str.indexOf("1");
int p2 = str.indexOf("2");
int p3 = str.indexOf("3");
int p4 = str.indexOf("4");



void setup() {
  size(1200, 600);
  ex = width/2;
  ey = height/2;
  background(255);

  imageMode(CENTER);
  for (int i = 0; i < bobross.length; i++) {
    bobross[i]= loadImage("data/bobross" + nf(i, 1) + ".png");
  }

  frameRate(140);
  minim  = new Minim(this);
  boop = minim.loadSample("boop.mp3", 512);
  bg = minim.loadFile("bach.mp3", 1024);
  bg.loop();
}

void draw() {
    if (frameCount % 6 == 0) {
    if (counter >= 77) {
      counter = 0;
    } else {
      counter++;
    }
  }


  image(bobross[counter], ex, ey);


  ellipse(ex, ey, 12, 12);
  ex += direction;
  ey += ddirection;
  direction = random(-10, 10);
  ddirection = random(-10, 10);

  if ( ex > width || ex < 0) {

    textSize(32);
    text(p0++, random(100,1100), random(100,500));
    fill(0, 102, 153);
    ex = 600;
    ey = 300;
    ex += direction;
    ey += ddirection;
    boop.trigger();
    stroke(random(0,255),random(0,255),random(0,255));

  }

  if (ey > height || ey < 0) {

    textSize(32);
    text(p0++, random(100,1100), random(100,500));
    fill(0, 102, 153);

    ex = 600;
    ey = 300;
    ex += direction;
    ey += ddirection;
    direction = random(-10, 10);
    ddirection = random(-10, 10);
    boop.trigger();
    stroke(random(0,255),random(0,255),random(0,255));



    fill(random(0, 255), random(0, 255), random(0, 255));
  }
}

void keyPressed() {
  if (key=='s')
    saveFrame();
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles