Hey, my idea is to make a kind of game where different coloured bubbles appear, grow and are burst once a bright area (e.g. a phone torch) is shined over them.
I have my bubbles appearing and growing. Although I do want them to appear at random times not all at once, and I want a maximum of say 10 on the screen at once and a new one appears once one is 'popped'.
Also I'm having trouble linking up the co-ordinates of the bubbles and the bright area. I tried using super in my bubble class to pass the coordinates through but processing wasn't having any of it.
Here's my main code:
- import processing.video.*;
- Capture myCaptureDevice;
- int imageWidth = 640;
- int imageHeight = 480;
- Bubble bubble1;
- void setup()
- {
- size(imageWidth, imageHeight, P2D);
- myCaptureDevice = new Capture(this, imageWidth, imageHeight);
- background(0);
- smooth();
- bubble1 = new Bubble();
- }
- void draw()
- {
- myCaptureDevice.read();
- myCaptureDevice.loadPixels();
- float brightestValue = 0;
- int brightestX = 0;
- int brightestY = 0;
- int[] pixels = myCaptureDevice.pixels;
- int index = 0;
- for (int y = 0; y < myCaptureDevice.height; y++) {
- for (int x = 0; x < myCaptureDevice.width; x++) {
- int pixelValue = myCaptureDevice.pixels[index];
- float pixelBrightness = brightness(pixelValue);
- if (pixelBrightness > brightestValue) {
- brightestValue = pixelBrightness;
- brightestY = y;
- brightestX = x;
- }
- index++;
- }
- }
- for (int i = 0; i < 100; i++) {
- if (brightestX == xArray[i] && brightnessY == yArray[i]) {
- println("Dick");
- }
- }
- /*for (int i=0; i<pixels.length ;i++) {
- int pixelValue = myCaptureDevice.pixels[i];
- float pixelBrightness = brightness(pixelValue);
- if (pixelBrightness > brightestVal) {
- brightestVal = pixelBrightness;
- //brightestY = y;
- brightestX = i;
- if (brightness(pixels[i]) > 220) {
- }
- }*/
- image(myCaptureDevice, 0, 0, imageWidth, imageHeight);
- bubble1.drawBubble();
- }
And my bubble class under a new tab:
- public class Bubble
- {
- float bubbleIncrement[] = new float[100];
- float bubbleSize[] = new float[100];
- float r[] = new float[100];
- float g[] = new float[100];
- float b[] = new float[100];
- int currentBubbles = 0;
- float[] xArray = new float[(imageWidth*imageHeight)];
- float[] yArray = new float[(imageWidth*imageHeight)];
- public Bubble()
- {
- }
- void drawBubble()
- {
- if (currentBubbles < 100)
- {
- for (int i=0; i<100; i++)
- {
- xArray[i] = (random(imageWidth));
- yArray[i] = (random(imageHeight));
- bubbleIncrement[i] = random(50);
- r[i] = random(255);
- g[i] = random(255);
- b[i] = random(255);
- ellipse(xArray[i], yArray[i], bubbleIncrement[i]*bubbleSize[i], bubbleIncrement[i]*bubbleSize[i]);
- currentBubbles++;
- }
- }
- for (int j=0; j<10; j++) {
- if (bubbleSize[j] < 100.0) {
- bubbleSize[j] = bubbleSize[j] + 0.005;
- }
- noStroke();
- fill(r[j], g[j], b[j], 150);
- ellipse(xArray[j], yArray[j], bubbleIncrement[j]*bubbleSize[j], bubbleIncrement[j]*bubbleSize[j]);
- }
- }
- }
Any pointers would be greatly appreciated!
Thanks
1