Try to convert C# function to Pawn
#1

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;
    
hsb.Hue 60;
    
hsb.Saturation 255 100;
    
hsb.Brightness 255 100;
    
maxRGB b;
    if (
== 0) {
        
functionReturnValue.Red 0;
        
functionReturnValue.Green 0;
        
functionReturnValue.Blue 0;
    } else {
        
Delta maxRGB 255;
        if (
3) {
            
functionReturnValue.Blue Convert.ToByte(Round(maxRGB));
            if (
4) {
                
functionReturnValue.Green Convert.ToByte(Round(maxRGB Delta));
                
functionReturnValue.Red Convert.ToByte(Round((4) * Delta)) + functionReturnValue.Green;
            } else {
                
functionReturnValue.Red Convert.ToByte(Round(maxRGB Delta));
                
functionReturnValue.Green Convert.ToByte(functionReturnValue.Red Round((4) * Delta));
            }
        } else {
            if (
1) {
                
functionReturnValue.Green Convert.ToByte(Round(maxRGB));
                if (
2) {
                    
functionReturnValue.Red Convert.ToByte(Round(maxRGB Delta));
                    
functionReturnValue.Blue Convert.ToByte(Round((2) * Delta)) + functionReturnValue.Red;
                } else {
                    
functionReturnValue.Blue Convert.ToByte(Round(maxRGB Delta));
                    
functionReturnValue.Red Convert.ToByte(functionReturnValue.Blue Round((2) * Delta));
                }
            } else {
                if (
> -1) {
                    
functionReturnValue.Red Convert.ToByte(Round(maxRGB));
                    if (
0) {
                        
functionReturnValue.Blue Convert.ToByte(Round(maxRGB Delta));
                        
functionReturnValue.Green Convert.ToByte(Round(Delta)) + functionReturnValue.Blue;
                    } else {
                        
functionReturnValue.Green Convert.ToByte(Round(maxRGB Delta));
                        
functionReturnValue.Blue Convert.ToByte(functionReturnValue.Green Round(Delta));
                    }
                }
            }
        }
    }
    return 
functionReturnValue;

can we help me to convert this to pawn code
Reply
#2

Why would you want this in pawn?
What is the use for it?
Reply
#3

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 (
0+= 360;
    if (
>= 360-= 360;
    new 
Float:rFloat:gFloat:b;
    if (
sV <= 00,00;
    else if (
fS <= 0sVsVsV;
    else
    {
        new 
Float:hf 60.0;
        new 
floatround(hf);
        new 
Float:hf i;
        new 
Float:pv sV * (fS);
        new 
Float:qv sV * (fS f);
        new 
Float:tv sV * (fS * (f));
        switch (
i)
        {
            
// Red is the dominant color
            
case 0sV,tv,pv;
            
// Green is the dominant color
            
case 1qv,sV,pv;
            case 
2pv,sV,tv;
            
// Blue is the dominant color
            
case 3pv,qv,sV;
            case 
4tv,pv,sV;
            
// Red is the dominant color
            
case 5sV,pv,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 6sV,tv,pv;
            case -
1sV,pv,qv;
            
// The color is not defined, we should throw an error.
            
default:sV,sV,sV;
        }
    }
    new 
RGB;
    
RGBValue(floatround((255.0)));
    
RGBValue(floatround((255.0)));
    
RGBValue(floatround((255.0)));
    
printf("%d,%d,%d",R,G,B);
    return 
RGB(R,G,B,255);
}
stock RGBValue(i)
{
    if (
0) return 0;
    if (
255) return 255;
    return 
i;
}
stock RGBredgreenbluealpha )
{
    return (
red 16777216) + (green 65536) + (blue 256) + alpha;

But it always return 0,0,0
Reply
#4

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.HSV.V;
    
Hdash HSV.60.0;
    
Chroma * (1.0 Abs((Hdash 2.0) - 1.0));
    if(
Hdash 1.0)
    {
        
RGB.Chroma;
        
RGB.X;
    }
    else if(
Hdash 2.0)
    {
        
RGB.X;
        
RGB.Chroma;
    }
    else if(
Hdash 3.0)
    {
        
RGB.Chroma;
        
RGB.X;
    }
    else if(
Hdash 4.0)
    {
        
RGB.GX;
        
RGB.Chroma;
    }
    else if(
Hdash 5.0)
    {
        
RGB.X;
        
RGB.Chroma;
    }
    else if(
Hdash 6.0)
    {
        
RGB.Chroma;
        
RGB.X;
    }
    
Min HSV.Chroma;
    
RGB.+= Min;
    
RGB.+= Min;
    
RGB.+= Min;
    
RGB.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;
    
Chroma * (1.0 floatabs((mod(Hdash,2.0) - 1.0)));
    
    if(
Hdash 1.0)
    {
        
Chroma;
        
X;
    }
    else if(
Hdash 2.0)
    {
        
X;
        
Chroma;
    }
    else if(
Hdash 3.0)
    {
        
Chroma;
        
X;
    }
    else if(
Hdash 4.0)
    {
        
X;
        
Chroma;
    }
    else if(
Hdash 5.0)
    {
        
X;
        
Chroma;
    }
    else if(
Hdash 6.0)
    {
        
Chroma;
        
X;
    }
    
    
Min Chroma;
    
RGBValue(floatround(r+Min));
    
RGBValue(floatround(g+Min));
    
RGBValue(floatround(b+Min));
    
RGBValue(A);
    
printf("%d,%d,%d",R,G,B);
    return 
RGB(R,G,B,A);
}
stock Float:mod(Float:aFloat:b)
{
    while(
b)
        
-= b;
    return 
a;

This is another Algoritm but it's don't work too
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)