Reading your code, taking notes...
- distanceBetween() duplicates the dist() function in Processing! Beside, no need for abs(), since you square the value anyway.
- You can use x += 4 as increment of the loop (instead of x++), that would avoid your x % 4 trick: you do 3/4 of the loops for nothing!
It is strange, because the halo's transparency works over the HeatPoint themselves, but not over the other halos.
I will think about a solution.
I tweaked your file before playing with it.
- distanceBetween() duplicates the dist() function in Processing! Beside, no need for abs(), since you square the value anyway.
- You can use x += 4 as increment of the loop (instead of x++), that would avoid your x % 4 trick: you do 3/4 of the loops for nothing!
It is strange, because the halo's transparency works over the HeatPoint themselves, but not over the other halos.
I will think about a solution.
I tweaked your file before playing with it.
- int numHeatPoints = 5;
- HeatPoint[] heatPoints = new HeatPoint[numHeatPoints];
- void setup(){
- size(1280,800);
- smooth();
- for (int i=0;i<numHeatPoints;i++){
- heatPoints[i] = new HeatPoint(random(0,width),random(0,height));
- }
- noStroke();
- rectMode(CENTER);
- }
- float[] colorPixel(float x,float y){
- float[] c = new float[4];
- for (int i=0;i<numHeatPoints;i++){
- float d = dist(x,y,heatPoints[i].x,heatPoints[i].y); // CPU intensive, better compute it once
- if (d < 200){
- float alph = map(d,0,200,175,0);
- c[0] = heatPoints[i].rgba[0];
- c[1] = heatPoints[i].rgba[1];
- c[2] = heatPoints[i].rgba[2];
- c[3] = alph;
- }
- }
- return c;
- }
- void draw(){
- background(0);
- //loadPixels();
- for (int i=0;i<numHeatPoints;i++){
- heatPoints[i].drawHeatPoint();
- }
- for (int x=0;x<width;x+=4){
- for (int y=0;y<height;y+=4){
- //pixels[y*width+x] = colorPixel(x,y);
- float[] c = colorPixel(x,y);
- fill(c[0],c[1],c[2],c[3]);
- rect(x,y,8,8);
- }
- }
- //updatePixels();
- }
- class HeatPoint{
- float x,y;
- float val;
- float[] rgba = new float[4];
- HeatPoint(float myX, float myY){
- x = myX;
- y = myY;
- updateHeatPointVal(random(0.0,1.0));
- println(val);
- }
- void updateHeatPointVal(float v){
- val = v;
- rgba[0] = map(val,0,1,0,255);
- rgba[1] = map(val,0,1,255,0);
- rgba[2] = 0;
- rgba[3] = 255;
- }
- void drawHeatPoint(){
- fill(rgba[0],rgba[1],rgba[2],rgba[3]);
- //fill(red(c),green(c),0,alpha(c));
- ellipse(x,y,255,255);
- }
- }