int i=0;
for (int y=1;y<=height;y++) {
for (int x=1;x<=width;x++) {
color c=img.pixels[int(y-1)*width+int(x-1)];
if (red(c)<230) {
// if ((x % 4)==1) {
if (random(1)<0.07) {
dot[i]=new Dot(x,y,c);
i++;
}
}
}
nrOfDots=i-1;
}}
class Dot {
float x,y,sx,sy;
float d,dm=20000.0;
float xmov=0,ymov=0;
float movability;
int nrOfNeighbours;
color col=color(255,255,255);
Dot(int x, int y, color c) {
col=c;
sx=x;sy=y;
this.x=x; this.y=y;
xmov=random(-3,3);
ymov=random(-3,3);
movability=1-dist(x,y,width/2.0,height/2.0)/sqrt(pow(width/2.0,2)+pow(height/2.0,2)); // 0..
}
class blendmodes{
int[] theList=new int[6];
color theColor;
blendmodes(){
}
void makeList(color cl1, color cl2){
theList[0]=int(red(cl1));
theList[1]=int(green(cl1));
theList[2]=int(blue(cl1));
theList[3]=int(red(cl2));
theList[4]=int(green(cl2));
theList[5]=int(blue(cl2));
}
void makeColor(){
theColor=color(theList[0],theList[1],theList[2]);
}
color average(color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
theList[i]=(theList[i]+theList[i+3])>>1;
}
makeColor();
return(theColor);
}
color multiply(color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
theList[i]=(theList[i]*theList[i+3])>>8;
}
makeColor();
return(theColor);
}
color screen(color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
theList[i]=255 - ((255-theList[i]) * (255-theList[i+3]) >>8);
}
makeColor();
return(theColor);
}
color darken(color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
if(theList[i]<theList[i+3]){
theList[i]=theList[i];
}else{
theList[i]=theList[i+3];
}
}
makeColor();
return(theColor);
}
color lighten(color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
if(theList[i]>theList[i+3]){
theList[i]=theList[i];
}else{
theList[i]=theList[i+3];
}
}
makeColor();
return(theColor);
}
color difference (color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
theList[i]=abs(theList[i]-theList[i+3]);
}
makeColor();
return(theColor);
}
color negation (color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
theList[i]=255-abs(255-theList[i]-theList[i+3]);
}
makeColor();
return(theColor);
}
color exclusion (color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
theList[i]=theList[i]+theList[i+3]-(theList[i]*theList[i+3]>>7);
}
makeColor();
return(theColor);
}
color overlay (color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
if (theList[i] < 128){
theList[i]=(theList[i]*theList[i+3])>>7;
}else{
theList[i]= 255 -((255-theList[i])*(255-theList[i+3])>>7);
}
}
makeColor();
return(theColor);
}
color hardLight (color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
if (theList[i+3] < 128){
theList[i]=(theList[i]*theList[i+3])>>7;
}else{
theList[i]= 255 -((255-theList[i])*(255-theList[i+3])>>7);
}
}
makeColor();
return(theColor);
}
color dodge (color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
if(theList[i+3]==255){
theList[i]= 255;
}else{
int res = (theList[i] << 8) / (255-theList[i+3]);
if (res>255) {
theList[i]= 255;
} else{
theList[i]=res;
}
}
}
makeColor();
return(theColor);
}
color burn (color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
if(theList[i+3]==0){
theList[i]= 0;
}else{
int res = 255 - (((255-theList[i]) << 8) / theList[i+3]);
if (res<0) {
theList[i]= 0;
} else{
theList[i]=res;
}
}
}
makeColor();
return(theColor);
}
color reflect (color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
if (theList[i+3]== 255){
theList[i]= 255;
}else{
int res = theList[i]*theList[i] / (255-theList[i+3]);
if (res > 255){
theList[i]= 255;
}else{
theList[i]=res;
}
}
}
makeColor();
return(theColor);
}
color glow (color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
if (theList[i]== 255){
theList[i]= 255;
}else{
int res = theList[i+3]*theList[i+3] / (255-theList[i]);
if (res > 255){
theList[i]= 255;
}else{
theList[i]=res;
}
}
}
makeColor();
return(theColor);
}
color freeze (color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
if (theList[i+3]==0){
theList[i+3]= 0;
}else{
int res =int(255-sq(255-theList[i])/theList[i+3]);
if (res < 0){
theList[i]= 0;
}else{
theList[i]=res;
}
}
}
makeColor();
return(theColor);
}
color heat (color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
if (theList[i]==0){
theList[i]= 0;
}else{
int res =int(255-sq(255-theList[i+3])/(theList[i]));
if (res < 0){
theList[i]= 0;
}else{
theList[i]=res;
}
}
}
makeColor();
return(theColor);
}
color stamp (color cl1, color cl2 ){
makeList(cl1,cl2);
for (int i=0;i<3;i++){
int res = theList[i] + 2*theList[i+3] - 256;
if (res < 0){
theList[i]= 0;
}else if (res > 255){
theList[i]= 255;
}else{
theList[i]= res;
}
}
makeColor();
return(theColor);
}
}