//Jeremy English 18-May-2007 <jhe@jeremyenglish.org>
//Make a given image look like George Seurat painted it.

abstract class tempColor{
    color c;
    public abstract color randHue(float saturation, float brightness);
}

class WarmColor extends tempColor{
    color randHue(float saturation, float brightness){
        float hue = random(270,450) % 360;
        this.c = color(hue, saturation, brightness);
        return c;
    }
}

class CoolColor extends tempColor{
    color randHue(float saturation, float brightness){
        float hue = random(90,270);
        this.c = color(hue, saturation, brightness);
        return c;
    }
}

color pickColor(color source,WarmColor warmColor, CoolColor coolColor){
    float hue = hue(source);
    if (90 <= hue && hue <= 270) //Cool part of the color wheel
        return coolColor.randHue(saturation(source),brightness(source));
    else
        return warmColor.randHue(saturation(source),brightness(source));
}


class Point{
    int min;
    int max;
    Point(int min, int max){
        this.min = min;
        this.max = max;
    }
    void draw(float x, float y, color c){
        float radius = random(min,max);
        fill(c);
        stroke(c);
        ellipse(x,y,radius,radius);
    }

}


class Seurat{
    WarmColor wc;
    CoolColor cc;
    Point p;
    PImage image;
    Seurat(String filename,int pointMin,int pointMax){
        colorMode(HSB,360,100,100);
        wc = new WarmColor();
        cc = new CoolColor();
        p = new Point(pointMin,pointMax);
        image = loadImage(filename);
    }
    int width(){
        return image.width;
    }
    int height(){
        return image.height;
    }
    void paint(){
        int x = floor(random(image.width));
        int y = floor(random(image.height));
        color source = image.pixels[floor(y * image.width + x)];
        p.draw(x,y,pickColor(source,wc,cc));
    }
}

Seurat seurat;

void setup(){
    seurat = new Seurat("van_gogh.png",1,4);
    size(seurat.width(), seurat.height());
}

void draw(){
    for (int i = 0; i < 1000; i++){
        seurat.paint();
    }
}

