Flashlight
back
Source
/* @pjs preload="player.png"; */
PImage player;
PImage lightBitmap;
PGraphics buffer;
int LIGHT_RADIUS = 100;
int NUMBER_OF_PEOPLE = 20;
PVector[] people = new PVector[NUMBER_OF_PEOPLE];
// Setup the example
void setup(){
size(640, 480);
imageMode(CENTER);
player = loadImage("player.png");
lightBitmap = createImage(width, height, RGB);
buffer = createGraphics(width, height, JAVA2D);
for(int i = 0; i < people.length; i++){
people[i] = new PVector(random(100, width-100), random(100, height-100));
}
}
// The draw() method is called every frame
void draw(){
background(#4488cc);
PVector light = new PVector(mouseX, mouseY);
for(PVector person : people){
image(player, person.x, person.y);
}
buffer.beginDraw();
buffer.background(100);
buffer.fill(255);
buffer.noStroke();
buffer.ellipse(light.x, light.y, LIGHT_RADIUS * 2, LIGHT_RADIUS * 2);
buffer.endDraw();
lightBitmap = buffer.get(0, 0, buffer.width, buffer.height);
blend(lightBitmap, 0, 0, width, height, 0, 0, width, height, MULTIPLY);
text((int)frameRate + " FPS", 20, 20);
}