Lila
YaBB Newbies
Offline
Posts: 3
x,y coordinates from a specific color?
Apr 20th , 2010, 11:57am
Hi, I am new to Processing, so please be easy on me :) I don't even know if it's possible but I would like my Class to start at the pixel that is the closest to cyan (0,255,255) of my background image. Is there a way I can do that? I assume, I have to replace the x,y of my class starting point definition - How could this look like? Thanks a lot! This is where I'm at so far: DLA[] dla; int amount=1; PImage img; void setup() { size(1700,900,JAVA2D); img = loadImage("backgroundimage.jpg"); background(img); loadPixels(); dla=new DLA[amount]; for(int i=0;i<amount;i++){ dla[i]=new DLA(x,y,round(random(1,10)),round(random(1,10)),round(random(1,10))); //I would like to insert the x,y of the cyan pixel here.... } } void draw() { for(int i=0;i<amount;i++){ dla[i].aggregate(); } } class DLA{ float[] pX, pY; float startRadius = 10; int maxP = 1000; int pCount = 3; float pSize = 6; int stickDist = 9; int sx,sy; float weight; DLA(int _sx, int _sy, int pCount, float pSize, int stickDist){ sx=_sx; sy=_sy; pX = new float[maxP]; pY = new float[maxP]; pX[0] = 0; pY[0] = 0; weight = 3; } void aggregate(){ pushMatrix(); strokeWeight( weight); float arrayDist, arraySize; float maxJumpDist = width; int closestElement = 0; translate(sx,sy); float theta = random(TWO_PI); float newElementX=startRadius*sin(theta); float newElementY=startRadius*cos(theta); while (true) { for (int i=0; i<pCount; i++) { arrayDist = dist(pX[i],pY[i],newElementX,newElementY); if (arrayDist<maxJumpDist) { maxJumpDist = arrayDist; closestElement = i; } } if (maxJumpDist<=stickDist) { theta = atan2(newElementY-pY[closestElement], newElementX-pX[closestElement]); pX[pCount] = pX[closestElement] + pSize*cos(theta); pY[pCount] = pY[closestElement] + pSize*sin(theta); stroke(255,150); line(pX[pCount],pY[pCount],pX[closestElement],pY[closestElement]); for (int i=0; i<pCount; i++) { arraySize = dist(pX[i],pY[i],0,0); if (arraySize>startRadius) { startRadius = arraySize; } } weight=weight*0.995; pCount++; if (pCount == maxP) { noLoop(); } break; } theta = random(TWO_PI); newElementX+=random(maxJumpDist)*sin(theta); newElementY+=random(maxJumpDist)*cos(theta); if (dist(0,0,newElementX,newElementY)>startRadius*2) { newElementX=startRadius*sin(theta); newElementY=startRadius*cos(theta); } } popMatrix(); } }