Project 01
Caroline Li

My project takes the idea of vector-to-raster drawing and combines it with a cool color-mapping technique to create an interactive image. I got the idea from the provided code, "PIcewise_Linear_Curves." I set up the start point and the end point of the color ramp, and the mouse controls the middle point. By dragging the mouse left and right, I can instantly change how the input distance maps to the final Hue of the image.

        
            vec3 RGBtoHSV(vec3 rgb)
{
    vec3 hsv;
    float cmax = max(rgb.r, max(rgb.g, rgb.b));
    float cmin = min(rgb.r, min(rgb.g, rgb.b));
    
    hsv.z = cmax; 

    float chroma = cmax - cmin;
    
    if (cmax == 0.0) {
        hsv.y = 0.0;
        hsv.x = 0.0;
        return hsv;
    }

    hsv.y = chroma / cmax;

    if(rgb.r == cmax)
    {
        hsv.x = (0.0 + (rgb.g - rgb.b) / chroma) / 6.0;
    }
    else if(rgb.g == cmax)
    {
        hsv.x = (2.0 + (rgb.b - rgb.r) / chroma) / 6.0;
    }
    else
    {
        hsv.x = (4.0 + (rgb.r - rgb.g) / chroma) / 6.0;
    }

    hsv.x = fract(hsv.x);
    
    return hsv;
}

vec3 HSVtoRGB(in vec3 c)
{
    vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),6.0)-3.0)-1.0, 0.0, 1.0);
    return c.z * mix(vec3(1.0), rgb, c.y);
}


void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv_centered = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;

    vec3 col = vec3(0.0,0.0,0.0);
    
    float x[3] = float[3](0.0,0.5,1.0); 
    float y[3] = float[3](0.01,0.5,0.99); 
    int N=3;
    
    x[1]=iMouse.x/iResolution.x;
    
    
    float input_distance = length(uv_centered);
    
    float grays = clamp(input_distance * 2.0, 0.0, 1.0);
    
    float MappedValue, t;
   
    for(int i=0; i= x[i] && grays <= x[i+1])  {
            t = (grays-x[i])/(x[i+1]-x[i]);
            MappedValue = y[i]*(1.0-t) + y[i+1]*t;
            break; 
        }
    } 
    
    
    vec3 hsv = vec3(
        MappedValue, 
        0.8,         
        1.0          
    );
    
    
    hsv.x = fract(hsv.x + iTime * 0.02);
    
    col = HSVtoRGB(hsv);
    
    fragColor = vec4(col, 1.0);
}