class Branch { int _x,_y,_col; Vector branches; int[] myPixels; int[] drawingPixels; TreeRect leftRect; int _level; float myBrightness; Branch(int $x, int $y, color $c, int[] $pixels, TreeRect $leftRect, int $level){ _x=$x; _y=$y; _col=$c; myPixels=$pixels; leftRect=$leftRect; _level=$level; if(_level>nLevels) nLevels=_level*1.0; branches=new Vector(); _col=colors[_level%colors.length]; } void addBranch(int $x, int $y, color $c, int[] $p, TreeRect $leftRect){ branches.addElement(new Branch($x,$y,$c,$p,$leftRect,_level+1)); } void drawMe(){ int len=branches.size(); if(len>0){ ((Branch) branches.get(0)).drawMe(); ((Branch) branches.get(1)).drawMe(); } else{ color t_col=color((255/nLevels)*_level); loadPixels(); int pos; for(int y=0; y1 && y0 && xleftRect._h){ // cut width r1_w=int((leftRect._w/(count_1+count_2))*count_1); r2_w=leftRect._w-r1_w; r1_h=r2_h=leftRect._h; r1_x=leftRect._x; r2_x=leftRect._x+r1_w; r1_y=r2_y=leftRect._y; }else{ // cut height r1_h=int((leftRect._h/(count_1+count_2))*count_1); r2_h=leftRect._h-r1_h; r1_w=r2_w=leftRect._w; r1_y=leftRect._y; r2_y=leftRect._y+r1_h; r1_x=r2_x=leftRect._x; } TreeRect rect_1=new TreeRect(r1_x,r1_y,r1_w,r1_h); TreeRect rect_2=new TreeRect(r2_x,r2_y,r2_w,r2_h); myPixels=null; branches.addElement(new Branch(_x,_y,$c,pixels_1,rect_1,_level+1)); branches.addElement(new Branch($x,$y,$c,pixels_2,rect_2,_level+1)); blendedRects.addElement(rect_1); blendedRects.addElement(rect_2); } Branch getBranch(int $x, int $y){ Branch res=null; Branch t_res; if(branches.size()>0){ Branch child_1=(Branch) branches.get(0); Branch child_2=(Branch) branches.get(1); t_res=child_1.getBranch($x,$y); if(t_res!=null){ res=t_res; } else{ t_res=child_2.getBranch($x,$y); if(t_res!=null) res=t_res; } } else{ if(myPixels[w*$y+$x]==1) res=this; } return res; } Branch getRect(int $x, int $y){ Branch res=null; Branch t_res; if(branches.size()>0){ Branch child_1=(Branch) branches.get(0); Branch child_2=(Branch) branches.get(1); t_res=child_1.getRect($x,$y); if(t_res!=null){ res=t_res; } else{ t_res=child_2.getRect($x,$y); if(t_res!=null) res=t_res; } } else{ if($x>=leftRect._x && $x=leftRect._y && $y=leftRect._x && $x=leftRect._y && $y0){ ((Branch) branches.get(0)).highLightBranch($x,$y); ((Branch) branches.get(1)).highLightBranch($x,$y); } } } }