C++ to PB

Everything else that doesn't fall into one of the other PB categories.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

C++ to PB

Post by Fluid Byte »

I need help with translating the following lines to PB:

Code: Select all

if (tempr > 1) tempr--;
and

Code: Select all

if (tempb < 0) tempb++;
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
KarLKoX
Enthusiast
Enthusiast
Posts: 681
Joined: Mon Oct 06, 2003 7:13 pm
Location: France
Contact:

Post by KarLKoX »

Code: Select all

if tempr > 1 
  tempr - 1
endif

Code: Select all

if tempb < 0 
  tempb + 1
endif
"Qui baise trop bouffe un poil." P. Desproges

http://karlkox.blogspot.com/
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Merci! Image
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

And if you want it all in one line like the C++ version just use the : sign like this:

Code: Select all

If tempr > 1: tempr - 1: EndIf 
I like logic, hence I dislike humans but love computers.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

One more question. I need to know which lines belong to which IF/THEN block respectivley where it ends:

Code: Select all

if(l < 0.5) temp2 = l * (1 + s);      
else temp2 = (l + s) - (l * s);     
temp1 = 2 * l - temp2;    
tempr = h + 1.0 / 3.0;    
if(tempr > 1) tempr--;
tempg = h;     
tempb = h - 1.0 / 3.0;
if(tempb < 0) tempb++;
Is this correct?

Code: Select all

If L < 0.5
	temp2 = L * (1 + S)
Else
	temp2 = (L + S) - (L * S)
EndIf

temp1 = 2 * L - temp2
tempr = H + 1.0 / 3.0

If tempr > 1 : tempr -1 : EndIf

tempg = H
tempb = H - 1.0 / 3.0
	
If tempb < 0 : tempb + 1 : EndIf
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Is this correct?
I think so!
I like logic, hence I dislike humans but love computers.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Ok, thanks for verfying.

And if you want to recheck with the code's original context look here:

http://student.kuleuven.be/~m0216922/CG ... SL_to_RGB_
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Matt
Enthusiast
Enthusiast
Posts: 447
Joined: Sat May 21, 2005 1:08 am
Location: USA

Post by Matt »

Looks correct,

in C++

if (statement)
code;

is

if statement
code
endif

or

if statement : code : endif


and

if (statement) {
code;
code;
}

is

if statement
code
code
endif

In C++, when there are no braces, { }, like in the second example, the only code that is executed if the if statement is true is the code following the if statement, so in C++ these are different:

if (statement) {
execute;
execute;
}
and:
if (statement)
execute;
execute;

If the statement is false, in the first example, no 'execute' will execute. In the second if statement, if the condition is false, the second execute will still execute.
Post Reply