root / processing / blacklight / Lightminion.pde @ 18
Histórico | Ver | Anotar | Download (3,95 KB)
| 1 |
/* |
|---|---|
| 2 |
BLACKLIGHT v1.0 |
| 3 |
Project made for Mestrado de Comunicação Multimédia, Ramo Multimédia Interactivo at Departamento de Comunicação e Arte at Universidade de Aveiro. |
| 4 |
|
| 5 |
Author: Nuno Simaria - nsimaria@ua.pt - #23652 |
| 6 |
Other workgroup members: Ana Filipa Lacerda, Daniela Rei, Renato Costa, Julien Cuenin |
| 7 |
*/ |
| 8 |
|
| 9 |
import JMyron.*; |
| 10 |
|
| 11 |
class Lightminion |
| 12 |
{
|
| 13 |
Lightlord lightlord = null; |
| 14 |
Detector detector = null; |
| 15 |
ArrayList lighted = null; |
| 16 |
|
| 17 |
void setup () |
| 18 |
{
|
| 19 |
this.detector = _detector_; |
| 20 |
} |
| 21 |
|
| 22 |
void draw () |
| 23 |
{
|
| 24 |
int[] img = this.detector.image (); |
| 25 |
|
| 26 |
int w = _game_.width;//this.lightlord.level.battlefield.width; |
| 27 |
int h = _game_.height;//this.lightlord.level.battlefield.height; |
| 28 |
|
| 29 |
float r, g, b; |
| 30 |
|
| 31 |
this.lighted = new ArrayList (); |
| 32 |
|
| 33 |
for(int y = 0; y < this.detector.height; y += 10) |
| 34 |
{
|
| 35 |
for(int x = 0; x < this.detector.width; x += 10) |
| 36 |
{
|
| 37 |
float av = (red(img[y*this.detector.width+x])+green(img[y*this.detector.width+x])+blue(img[y*this.detector.width+x]))/3.0; |
| 38 |
|
| 39 |
if (av > 200) |
| 40 |
{
|
| 41 |
r = red (img[y * this.detector.width + x]); |
| 42 |
g = green (img[y * this.detector.width + x]); |
| 43 |
b = blue (img[y * this.detector.width + x]); |
| 44 |
|
| 45 |
fill (r, g, b, 100); |
| 46 |
noStroke (); |
| 47 |
|
| 48 |
int[] l = new int[2]; |
| 49 |
|
| 50 |
// println (_game_.width + " > " + this.detector.width + " = " + int (/*_game_.width - */(x * float(_game_.width / this.detector.width)))); |
| 51 |
|
| 52 |
l[0] = int (x * (float (_game_.width) / float(this.detector.width)));/*_game_.width - */ |
| 53 |
l[1] = int (y * (float (_game_.height) / float(this.detector.height))); |
| 54 |
|
| 55 |
|
| 56 |
this.lighted.add (l); |
| 57 |
|
| 58 |
ellipse (l[0], l[1], 50, 50); |
| 59 |
//ellipse (l[0], l[1], this.lightlord.level.battlefield.videoScale, this.lightlord.level.battlefield.videoScale); |
| 60 |
// point (x, y, 0); |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
/* |
| 68 |
|
| 69 |
float r,g,b; |
| 70 |
for(int y=0;y<height;y+=1){ //loop through all the pixels
|
| 71 |
for(int x=0;x<width;x+=1){ //loop through all the pixels
|
| 72 |
float av = (red(img[y*width+x])+green(img[y*width+x])+blue(img[y*width+x]))/3.0; |
| 73 |
|
| 74 |
|
| 75 |
if (av > 200) |
| 76 |
{
|
| 77 |
|
| 78 |
r = red(img[y*width+x]); |
| 79 |
g = green(img[y*width+x]); |
| 80 |
b = blue(img[y*width+x]); |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
stroke(r, g, b); |
| 85 |
point(x,y, - 400); |
| 86 |
} |
| 87 |
/* if (av < 200) |
| 88 |
{
|
| 89 |
|
| 90 |
} |
| 91 |
else //if (av > 200) |
| 92 |
{
|
| 93 |
//fill(av); |
| 94 |
// fill(r, g, b, av/2 + 10); |
| 95 |
// noStroke (); |
| 96 |
// ellipse(x,y, av/8, av/8); |
| 97 |
// translate (x, y, 0); |
| 98 |
// box(10,10,2* av); |
| 99 |
// translate (-x, -y, 0); |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
for (int i = 0; i < w; i++) |
| 105 |
{
|
| 106 |
for (int j = 0; j < h; j++) |
| 107 |
{
|
| 108 |
|
| 109 |
for (int raster_y = 0; raster_y < this.detector.sample_height; raster_y++) |
| 110 |
{
|
| 111 |
for (int raster_x = 0; raster_x < this.detector.sample_width; raster_x++) |
| 112 |
{
|
| 113 |
int sample_x = (i * this.detector.sample_width) + raster_x; |
| 114 |
int sample_y = (j * this.detector.sample_height) + raster_y; |
| 115 |
|
| 116 |
float r = red (img [int (sample_y * this.lightlord.source_size [0] + sample_x)]); |
| 117 |
float g = green (img [int (sample_y * this.lightlord.source_size [0] + sample_x)]); |
| 118 |
float b = blue (img [int (sample_y * this.lightlord.source_size [0] + sample_x)]); |
| 119 |
|
| 120 |
int average = int ((r + g + b) / 3); |
| 121 |
if (average > 200) |
| 122 |
{
|
| 123 |
rect (sample_x, sample_y, 1, 1); |
| 124 |
} |
| 125 |
//this.lightlord.level.battlefield.cells [i][j].sample (img [int (sample_y * this.lightlord.source_size [0] + sample_x)]); |
| 126 |
|
| 127 |
// |
| 128 |
|
| 129 |
// |
| 130 |
//this.lightlord.level.battlefield.cells [i][j].sample (img [int (sample_y * this.lightlord.source_size [0] + sample_x)]); |
| 131 |
} |
| 132 |
} |
| 133 |
// this.cells [i][j].draw (); |
| 134 |
|
| 135 |
} |
| 136 |
} |
| 137 |
*/ |
| 138 |
|
| 139 |
|
| 140 |
|