Quote: "It would be neat if there was an OOP based language designed specifically to be learned; that could be a great stepping stone for those intending to learn OOP."
Well technically that would be Java, seeing as its entirely OOP!
The code I wrote above is Java, minus a few things.
Java code for a Color class I just made (I was bored):
public class Color
{
private float[] color_components;
public Color( float red, float green, float blue )
{
this.color_components = new float[]{ red, green, blue };
}
public Color( int red, int green, int blue )
{
this(red/255f, green/255f, blue/255f);
}
public int[] toIntegerArray()
{
return new int[] {
(int) (this.color_components[0]*255),
(int) (this.color_components[1]*255),
(int) (this.color_components[2]*255)
};
}
public float[] toFloatArray()
{
return this.color_components;
}
public void setColorComponents( float red, float green, float blue )
{
this.color_components[0] = red;
this.color_components[1] = green;
this.color_components[2] = blue;
}
public void setColorComponents( int red, int green, int blue )
{
this.setColorComponents( red/255f, green/255f, blue/255f );
}
public void multiply( Color color )
{
float[] colors = color.toFloatArray();
for( int i = 0, ii = this.color_components.length; i < ii; i++ )
{
this.color_components[ i ] *= colors[ i ];
}
}
public void screen( Color color )
{
float[] colors = color.toFloatArray();
for( int i = 0, ii = this.color_components.length; i < ii; i++ )
{
this.color_components[ i ] = 1 - (1 - this.color_components[ i ]) * (1 - colors[ i ]);
}
}
public void overlay( Color color )
{
float[] colors = color.toFloatArray();
for( int i = 0, ii = this.color_components.length; i < ii; i++ )
{
float base = this.color_components[ i ];
if( base < 0.5 )
{
this.color_components[ i ] = 2 * base * colors[ i ];
}else
{
this.color_components[ i ] = 1 - 2 * (1 - base) * (1 - colors[ i ]);
}
}
}
public void hardLight( Color color )
{
float[] colors = color.toFloatArray();
for( int i = 0, ii = this.color_components.length; i < ii; i++ )
{
float base = colors[ i ];
if( base < 0.5 )
{
this.color_components[ i ] = 2 * base * this.color_components[ i ];
}else
{
this.color_components[ i ] = 1 - 2 * (1 -base) * (1-this.color_components[ i ]);
}
}
}
public void softLight( Color color )
{
float[] colors = color.toFloatArray();
for( int i = 0, ii = this.color_components.length; i < ii; i++ )
{
float source = colors[ i ];
float base = this.color_components[ i ];
if( source < 0.5 )
{
this.color_components[ i ] = (2 * base * source) + (float)(Math.pow( base, 2 ) * (1 - 2*source));
}else
{
this.color_components[ i ] = (2 * base * (1 - source)) + (float)(Math.sqrt(base)*(2*source - 1));
}
}
}
public void invert()
{
for( int i = 0, ii = this.color_components.length; i < ii; i++ )
{
this.color_components[ i ] = 1 - this.color_components[ i ];
}
}
public String toHex()
{
int[] col_components = this.toIntegerArray();
return Integer.toHexString( 0x100 | col_components[0] ).substring(1) +
Integer.toHexString( 0x100 | col_components[1] ).substring(1) +
Integer.toHexString( 0x100 | col_components[2] ).substring(1);
}
public String toString()
{
return String.format("rgb(%.2f, %.2f, %.2f)", this.color_components[0],
this.color_components[1],
this.color_components[2]
);
}
}
