1977 Kawasaki KZ400 D4
Tuesday — July 29th, 2008

1977 Kawasaki KZ400 D4

My motorcycle in all its glory. Unfortunetly mine isn’t so shiny and perfect like this one, maybe some day…. I just need it to work. Currently I am watching the Kill Switch part, on ebay, but I am unsure if the 1976 kill switch will fit my bike. I can either take the $40 chance, or I can bypass the kill switch to see if that is really the problem. Either way I am going to need a new kill switch, so I’m thinking that I will need to buy it anyway…

What should I do about the Kill Switch?

  • Bypass it, and wait until I find the part for the same year? (67%, 2 Votes)
  • Buy the part, and take the chance that it is the wrong part? (33%, 1 Votes)

Total Voters: 3

Loading ... Loading ...
blog...

Convert Color Spaces (HSL->RGB)

Math

{h}\in[0,360) 

{s}\in[0,1] 

{l}\in[0,1] 

 {q}= \begin{cases}     {{l}\times({1}+{s})}, & if\quad{l}<\frac{1}{2} \\     {{l}+{s}-({l}\times{s})}, & if\quad{l}\ge\frac{1}{2} \end{cases} 

{2}\times{l}-{q} 

h_k=\frac{h}{360} 

t_R=(h_k+\frac{1}{3})\mod{1} 

t_G=(h_k)\mod{1} 

t_B=(h_k-\frac{1}{3})\mod{1} 

foreach\quad{t_C}\in\{{t_R}, {t_G}, {t_B}\} 
 {t_C}= \begin{cases}     {{p}+(({q}-{p})\times{6}\times{t_C}}, & if\quad{t_C <\frac{1}{6}} \\     {q}, & if\quad{\frac{1}{6}\le{t_C}<\frac{1}{2}} \\     {{p}+(({q}-{p})\times{6}\times{\frac{2}{3}-t_C}}, & if\quad{\frac{1}{2}\le{t_C}<\frac{2}{3}} \\     {p}, & otherwise \end{cases} 

{{t_R}\equiv{r}}\in[0,1] 

{{t_G}\equiv{g}}\in[0,1] 

{{t_B}\equiv{b}}\in[0,1] 

C/C++

pixeltype HSLtoRGB(pixeltype palette_color){
	//0.0f <= h <  360.0f
	//0.0f <= s <= 1.0f
	//0.0f <= l <= 1.0f
	double h = (double)(HUE_OF(palette_color));
    double s = (double)(SATURATION_OF(palette_color));
    double l = (double)(LIGHTNESS_OF(palette_color));
	double q, p, h_k;
	double rgb[3];

	if(l < 0.5f){
		q = l * (1 + s);
	}else{
		q = l + s - (l * s);
	}
	p = 2 * l - q;
	h_k = h / 360.0f;
	rgb[0] = h_k + (1 / 3);
	rgb[1] = h_k;
	rgb[2] = h_k - (1 / 3);
	for(size_t i = 0; i < 3; i++){
		if(rgb[i] < (1 / 6)){
			rgb[i] = p + ((q - p) * 6.0f * rgb[i]);
		}else if(rgb[i] >= (1 / 6) && rgb[i] < (1 / 2)){
			rgb[i] = q;
		}else if(rgb[i] >= (1 / 2) && rgb[i] < (2 / 3)){
			rgb[i] = p + ((q - p) * 6.0f * ((2 / 3) - rgb[i]));
		}else{
			rgb[i] = p;
		}
	}
	//0.0f <= rgb[0] <= 1.0f
	//0.0f <= rgb[1] <= 1.0f
	//0.0f <= rgb[2] <= 1.0f
	return RGB_OF(rgb[0], rgb[1], rgb[2]);
}

Convert Color Spaces (RGB->HSL)

Math

{r}\in[0,1] 
{g}\in[0,1] 
{b}\in[0,1] 
max=\max(r,g,b) 
min=\min(r,g,b) 

 h = \begin{cases}     {0}, & if {max}={min} \\     ({60}\times\frac{{g}-{b}}{{max}-{min}}+{360})\mod{360}, & if {max}={r} \\     ({60}\times\frac{{b}-{r}}{{max}-{min}}+{120}), & if {max}={g} \\     ({60}\times\frac{{r}-{g}}{{max}-{min}}+{240}), & if {max}-{b} \end{cases} 

\frac{1}{2}({{max}+{min}}) 

 s = \begin{cases}     0, & if {max}={min} \\     \frac{{max}-{min}}{2l}, & if l\le{\frac{1}{2}} \\     \frac{{max}-{min}}{{2}-2l}, & if l>{\frac{1}{2}} \end{cases} 

C/C++

pixeltype RGBtoHSV(pixeltype palette_color){
	//0.0f <= r <= 1.0f
	//0.0f <= g <= 1.0f
	//0.0f <= b <= 1.0f
    double r = (double)(RED_OF(palette_color));
    double g = (double)(GREEN_OF(palette_color));
    double b = (double)(BLUE_OF(palette_color));
    double max, min, h, s, l;

	if(r > g){
		max = r;
	}else{
		max = g;
	}
	if(b > max){
		max = b;
	}

	if(r < g){
		min = r;
	}else{
		min = g;
	}
	if(b < min){
		min = b;
	}

    if(max == min){
        h = 0.0f;
    }else if(max == r){
        h = ((60.0f * ((g - b) / (max - min)) + 360) % 360.0f);
    }else if(max == g){
        h = ((60.0f * ((b - r) / (max - min)) + 120));
    }else if(max == b){
        h = ((60.0f * ((r - g) / (max - min)) + 240));
    }

	l = (max + min) / 2.0f;

	if(max == min){
		s = 0;
	}else if(l <= 0.5f){
		s = ((max - min) / (2 * l));
	}else if(l > 0.5f){
		s = ((max - min) / (2 - (2 * l)));
	}

	//0.0f <= h <= 360.0f
	//0.0f <= s <= 1.0f
	//0.0f <= l <= 1.0f
    return HSL_OF(h, s, l);
}
}

Convert Color Spaces (RGB->HSV)

Math

{r}\in[0,1] 
{g}\in[0,1] 
{b}\in[0,1] 
max=\max(r,g,b) 
min=\min(r,g,b) 

 h = \begin{cases}     {0}, & if {max}={min} \\     ({60}\times\frac{{g}-{b}}{{max}-{min}}+{360})\mod{360}, & if {max}={r} \\     ({60}\times\frac{{b}-{r}}{{max}-{min}}+{120}), & if {max}={g} \\     ({60}\times\frac{{r}-{g}}{{max}-{min}}+{240}), & if {max}-{b} \end{cases} 

 s = \begin{cases}     0, & if {max}={0} \\     {1}-\frac{min}{max}, & otherwise \end{cases} 

v=max 

C/C++


pixeltype RGBtoHSV(pixeltype palette_color){
	//0.0f <= r <= 1.0f
	//0.0f <= g <= 1.0f
	//0.0f <= b <= 1.0f
    double r = (double)(RED_OF(palette_color));
    double g = (double)(GREEN_OF(palette_color));
    double b = (double)(BLUE_OF(palette_color));
    double max, min, h, s, v;

	if(r > g){
		max = r;
	}else{
		max = g;
	}
	if(b > max){
		max = b;
	}

	if(r < g){
		min = r;
	}else{
		min = g;
	}
	if(b < min){
		min = b;
	}

    if(max == min){
        h = 0.0f;
    }else if(max == r){
        h = ((60.0f * ((g - b) / (max - min)) + 360) % 360.0f);
    }else if(max == g){
        h = ((60.0f * ((b - r) / (max - min)) + 120));
    }else if(max == b){
        h = ((60.0f * ((r - g) / (max - min)) + 240));
    }

    if(max == 0){
        s = 0.0f;
    }else{
        s = 1.0f - (min / max);
    }
    v = max;

	//0.0f <= h <= 360.0f
	//0.0f <= s <= 1.0f
	//0.0f <= v <= 1.0f
    return HSV_OF(h, s, v);
}

Convert Color Spaces (HSV->RGB)

Math

{h}\in[0,360] 
{s}\in[0,1] 
{v}\in[0,1] 

h_i = \lfloor\frac{h}{60}\rfloor\mod{6} 

f = \frac{h}{60}-\lfloor\frac{h}{60}\rfloor 

p=v\times(1-s) 

q=v\times(1-f\times{s}) 

t=v\times(1-(1-f)\times{s}) 

 (r, g, b) = \begin{cases}     (v, t, p), & if h_i = 0 \\     (q, v, p), & if h_i = 1 \\     (p, v, t), & if h_i = 2 \\     (p, q, v), & if h_i = 3 \\     (t, p, v), & if h_i = 4 \\     (v, p, q), & if h_i = 5 \end{cases} 

C/C++

pixeltype HSVtoRGB(pixeltype palette_color){
    //0.0f <= h <= 360.0f
    //0.0f <= s <= 1.0f
    //0.0f <= v <= 1.0f
    double h = (double)(HUE_OF(palette_color));
    double s = (double)(SATURATION_OF(palette_color));
    double v = (double)(VALUE_OF(palette_color));
    double hi, f, p, q, t, temp;
    pixeltype rgb;

	temp = (h / 60.0f);
	hi = floor(temp) % 6.0f;
	f = temp - floor(temp);
	p = v * (1.0f - s);
	q = v * (1.0f - f * s);
	t = v * (1.0f - (1.0f - f) * s);
	switch((int)floor(hi)){
		case 0:rgb = RGB_OF(v, t, p);break;
		case 1:rgb = RGB_OF(q, v, p);break;
		case 2:rgb = RGB_OF(p, v, t);break;
		case 3:rgb = RGB_OF(p, q, v);break;
		case 4:rgb = RGB_OF(t, p, v);break;
		case 5:rgb = RGB_OF(v, p, q);break;
	}
	return rgb;

        //0.0f <= r <= 1.0f
	//0.0f <= g <= 1.0f
	//0.0f <= b <= 1.0f
}

Fixed Point

Fixed point is used to represent a floating point number.
It could be used to speed up the multiplication and division operations on systems without a floating point processor.

Floating point is represented by scaling an integer.
In C/C++ one would shift the number by a scale…

const int SHIFT_AMT = 16;
const int INTEGER_MASK = 0xFF;
const int DECIMAL_MASK = 0xFF;

It is easiest for me to think of fixed point as a number multiplied by a scale.
I find it easier because it makes thinking about operations on the fixed point easier.

MATH

fixedpoint = (number * scale)

C/C++

typedef signed int fixedpoint;
int i = 10;
fixedpoint fp = i << SHIFT_AMT;

Addition and Subtraction are trivial with fixed point, Multiplication and Division are not...
Well... they are just not as trivial, there is one more step involved, scaling the result.

For Multiplication, you need to divide by the scale.
For Division, you need to multiply by the scale.

Multiplication
MATH

fixedpoint * fixedpoint =

(number1 * scale) * (number2 * scale) =

((number1 * number2) * scale^2) =

(((number1 * number2) * scale^2) / scale) =

((number1 * number2) * scale)

C/C++

fixedpoint number1 = 10 << SHIFT_AMT;
fixedpoint number2 = 10 << SHIFT_AMT;
fixedpoint result = (number1 * number2) >> SHIFT_AMT;

Division
MATH

fixedpoint * fixedpoint =

(number1 * scale) / (number2 * scale) =

(number1 / number2) =

(((number1 / number2)) * scale)

C/C++

fixedpoint number1 = 10 << SHIFT_AMT;
fixedpoint number2 = 10 << SHIFT_AMT;
fixedpoint result = (number1 / number2) << SHIFT_AMT;

Other useful operations on fixed point could be:
Modulus.
Square-root.
Sine.
Cosine.

Calculate Black and White value for pixel.

Pseudo-algorithm:

We are finding the average value for the three color components…

1. Extract the Red, Green and Blue of a color.
2. Add the three values together, divide them by three.
3. Put the Red, Green and Blue values together to form the gray value.

int pixel_value = RGB(13, 152, 186);
//get the red value of the pixel
int red = RED_OF(pixel_value) ;
//get the green value of the pixel
int green = GREEN_OF(pixel_value) ;
//get the blue value of the pixel
int blue BLUE_OF(pixel_value) ;
//average each color together to get the gray value
int gray = (red + green + blue)/3;
//bitwise 'or' them to make the complete RGB
int gray_pixel_value = RGB_OF(gray, gray, gray);

sidenote:
Love these colors from Crayola, they bring back so many memories!

Calculate Alpha blend

Pseudo-algorithm:

Extract the RGB color values of the initial and to be drawn pixels colors.
Add each of the extract RGB values together and multiply by 0.5 (basically find the average of the two colors.

//The initial pixel color.
int color_initial = PIXELCOLOR;
//The pixel color to draw.
int color_draw = DRAWCOLOR;
//Extract each of the R, G, and B for each color of the initial pixel color.
int red_initial = RED_OF(color_initial);
int green_initial = GREEN_OF(color_initial);
int blue_initial = BLUE_OF(color_initial);
int red_draw = RED_OF(color_draw);
int green_draw = GREEN_OF(color_draw);
int blue_draw = BLUE_OF(color_draw);
//Find the average of the initial and new pixel colors.
int new_red = (red_initial + red_draw) * 0.5f;
int new_green = (green_initial + green_draw) * 0.5f;
int new_blue  = (blue_initial + blue_draw) * 0.5f;
int new_color = RGB_OF(new_red, new_green, new_blue);

Next up… gray values…

New Comment Engine!

Intense Debate is now installed as the comment solution to this site. The intention here is to decrease cpu and bandwidth usage on the server that gpa uses, while also possibly getting other people aware of this site who are already on Intense Debate.

(2009-07-06)

  • @TLConTLC is it that offensive? When I was little my dad would call me that, in a loving way. #

Powered by Twitter Tools.

(2009-07-06)

  • @TLConTLC is it that offensive? When I was little my dad would call me that, in a loving way. #

Powered by Twitter Tools.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes

GameProgrammerArt is Digg proof thanks to caching by WP Super Cache