Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : Cannot figure out why alpha is acting strange here!

$
0
0
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.
  1. int numHeatPoints = 5;
  2. HeatPoint[] heatPoints = new HeatPoint[numHeatPoints];
  3.  
  4. void setup(){
  5.   size(1280,800);
  6.   smooth();
  7.   for (int i=0;i<numHeatPoints;i++){
  8.     heatPoints[i] = new HeatPoint(random(0,width),random(0,height)); 
  9.   }
  10.   noStroke();
  11.   rectMode(CENTER);
  12. }
  13.  
  14. float[] colorPixel(float x,float y){
  15.   float[] c = new float[4];
  16.   for (int i=0;i<numHeatPoints;i++){
  17.     float d = dist(x,y,heatPoints[i].x,heatPoints[i].y); // CPU intensive, better compute it once
  18.     if (d < 200){
  19.       float alph = map(d,0,200,175,0);
  20.       c[0] = heatPoints[i].rgba[0];
  21.       c[1] = heatPoints[i].rgba[1];
  22.       c[2] = heatPoints[i].rgba[2];
  23.       c[3] = alph;
  24.     }
  25.   }
  26.   return c;
  27. }
  28.  
  29. void draw(){
  30.   background(0);
  31.   //loadPixels();
  32.   for (int i=0;i<numHeatPoints;i++){
  33.     heatPoints[i].drawHeatPoint();
  34.   }
  35.   for (int x=0;x<width;x+=4){
  36.       for (int y=0;y<height;y+=4){
  37.           //pixels[y*width+x] = colorPixel(x,y);
  38.           float[] c = colorPixel(x,y);
  39.           fill(c[0],c[1],c[2],c[3]);
  40.           rect(x,y,8,8);
  41.       }
  42.   }
  43.   //updatePixels();
  44. }
  45.  
  46. class HeatPoint{
  47.   float x,y;
  48.   float val;
  49.   float[] rgba = new float[4];
  50.   
  51.   HeatPoint(float myX, float myY){
  52.     x = myX;
  53.     y = myY;
  54.     updateHeatPointVal(random(0.0,1.0));
  55.     println(val);
  56.   }
  57.  
  58.   void updateHeatPointVal(float v){
  59.     val = v;
  60.     rgba[0] = map(val,0,1,0,255);
  61.     rgba[1] = map(val,0,1,255,0);
  62.     rgba[2] = 0;
  63.     rgba[3] = 255;
  64.   }
  65.  
  66.   void drawHeatPoint(){
  67.     fill(rgba[0],rgba[1],rgba[2],rgba[3]);
  68.     //fill(red(c),green(c),0,alpha(c));
  69.     ellipse(x,y,255,255);
  70.   }
  71. }


Viewing all articles
Browse latest Browse all 1768

Trending Articles