Try to convert C# function to Pawn - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Try to convert C# function to Pawn (
/showthread.php?tid=360584)
HSB color to RBG -
xX_Simon_Xx - 18.07.2012
PHP код:
public RGBColor HSBToRGB(HSBColor hsb)
{
RGBColor functionReturnValue = default(RGBColor);
double maxRGB = 0;
double Delta = 0;
double h = 0;
double s = 0;
double b = 0;
h = hsb.Hue / 60;
s = hsb.Saturation * 255 / 100;
b = hsb.Brightness * 255 / 100;
maxRGB = b;
if (s == 0) {
functionReturnValue.Red = 0;
functionReturnValue.Green = 0;
functionReturnValue.Blue = 0;
} else {
Delta = s * maxRGB / 255;
if (h > 3) {
functionReturnValue.Blue = Convert.ToByte(Round(maxRGB));
if (h > 4) {
functionReturnValue.Green = Convert.ToByte(Round(maxRGB - Delta));
functionReturnValue.Red = Convert.ToByte(Round((h - 4) * Delta)) + functionReturnValue.Green;
} else {
functionReturnValue.Red = Convert.ToByte(Round(maxRGB - Delta));
functionReturnValue.Green = Convert.ToByte(functionReturnValue.Red - Round((h - 4) * Delta));
}
} else {
if (h > 1) {
functionReturnValue.Green = Convert.ToByte(Round(maxRGB));
if (h > 2) {
functionReturnValue.Red = Convert.ToByte(Round(maxRGB - Delta));
functionReturnValue.Blue = Convert.ToByte(Round((h - 2) * Delta)) + functionReturnValue.Red;
} else {
functionReturnValue.Blue = Convert.ToByte(Round(maxRGB - Delta));
functionReturnValue.Red = Convert.ToByte(functionReturnValue.Blue - Round((h - 2) * Delta));
}
} else {
if (h > -1) {
functionReturnValue.Red = Convert.ToByte(Round(maxRGB));
if (h > 0) {
functionReturnValue.Blue = Convert.ToByte(Round(maxRGB - Delta));
functionReturnValue.Green = Convert.ToByte(Round(h * Delta)) + functionReturnValue.Blue;
} else {
functionReturnValue.Green = Convert.ToByte(Round(maxRGB - Delta));
functionReturnValue.Blue = Convert.ToByte(functionReturnValue.Green - Round(h * Delta));
}
}
}
}
}
return functionReturnValue;
}
can we help me to convert this to pawn code
Re: Try to convert C# function to Pawn -
milanosie - 18.07.2012
Why would you want this in pawn?
What is the use for it?
Re: Try to convert C# function to Pawn -
xX_Simon_Xx - 18.07.2012
I try to do and i made this
PHP код:
stock HSVtoRBG(H,S,V) //H = 0 to 360 - S = 0 to 100 - V = 0 to 100
{
new Float:fS,Float:sV;
fS = S/100;
sV = V/100;
if (H < 0) H += 360;
if (H >= 360) H -= 360;
new Float:r, Float:g, Float:b;
if (sV <= 0) r = 0,g = 0, b = 0;
else if (fS <= 0) r = sV, g = sV, b = sV;
else
{
new Float:hf = H / 60.0;
new i = floatround(hf);
new Float:f = hf - i;
new Float:pv = sV * (1 - fS);
new Float:qv = sV * (1 - fS * f);
new Float:tv = sV * (1 - fS * (1 - f));
switch (i)
{
// Red is the dominant color
case 0: r = sV,g = tv,b = pv;
// Green is the dominant color
case 1: r = qv,g = sV,b = pv;
case 2: r = pv,g = sV,b = tv;
// Blue is the dominant color
case 3: r = pv,g = qv,b = sV;
case 4: r = tv,g = pv,b = sV;
// Red is the dominant color
case 5: r = sV,g = pv,b = qv;
// Just in case we overshoot on our math by a little, we put these here. Since its a switch it won't slow us down at all to put these here.
case 6: r = sV,g = tv,b = pv;
case -1: r = sV,g = pv,b = qv;
// The color is not defined, we should throw an error.
default:r = sV,g = sV,b = sV;
}
}
new R, G, B;
R = RGBValue(floatround((r * 255.0)));
G = RGBValue(floatround((g * 255.0)));
B = RGBValue(floatround((b * 255.0)));
printf("%d,%d,%d",R,G,B);
return RGB(R,G,B,255);
}
stock RGBValue(i)
{
if (i < 0) return 0;
if (i > 255) return 255;
return i;
}
stock RGB( red, green, blue, alpha )
{
return (red * 16777216) + (green * 65536) + (blue * 256) + alpha;
}
But it always return 0,0,0
Re: Try to convert C# function to Pawn -
xX_Simon_Xx - 18.07.2012
C#
PHP код:
static final function LinearColor HSVToRGB(const out HSVColour HSV)
{
local float Min;
local float Chroma;
local float Hdash;
local float X;
local LinearColor RGB;
Chroma = HSV.S * HSV.V;
Hdash = HSV.H / 60.0;
X = Chroma * (1.0 - Abs((Hdash % 2.0) - 1.0));
if(Hdash < 1.0)
{
RGB.R = Chroma;
RGB.G = X;
}
else if(Hdash < 2.0)
{
RGB.R = X;
RGB.G = Chroma;
}
else if(Hdash < 3.0)
{
RGB.G = Chroma;
RGB.B = X;
}
else if(Hdash < 4.0)
{
RGB.G= X;
RGB.B = Chroma;
}
else if(Hdash < 5.0)
{
RGB.R = X;
RGB.B = Chroma;
}
else if(Hdash < 6.0)
{
RGB.R = Chroma;
RGB.B = X;
}
Min = HSV.V - Chroma;
RGB.R += Min;
RGB.G += Min;
RGB.B += Min;
RGB.A = HSV.A;
return RGB;
}
Pawn:
PHP код:
stock HSVtoRBG(H,Float:S,Float:V,A)
{
new Float:Min;
new Float:Chroma;
new Float:Hdash;
new Float:X;
new Float:r,Float:b,Float:g;
new R,G,B;
Chroma = S*V;
Hdash = H/60.0;
X = Chroma * (1.0 - floatabs((mod(Hdash,2.0) - 1.0)));
if(Hdash < 1.0)
{
r = Chroma;
g = X;
}
else if(Hdash < 2.0)
{
r = X;
g = Chroma;
}
else if(Hdash < 3.0)
{
g = Chroma;
b = X;
}
else if(Hdash < 4.0)
{
g = X;
b = Chroma;
}
else if(Hdash < 5.0)
{
r = X;
b = Chroma;
}
else if(Hdash < 6.0)
{
r = Chroma;
b = X;
}
Min = V - Chroma;
R = RGBValue(floatround(r+Min));
G = RGBValue(floatround(g+Min));
B = RGBValue(floatround(b+Min));
A = RGBValue(A);
printf("%d,%d,%d",R,G,B);
return RGB(R,G,B,A);
}
stock Float:mod(Float:a, Float:b)
{
while(a > b)
a -= b;
return a;
}
This is another Algoritm but it's don't work too