Page 1 of 3 123>
Topic Options
#106488 - 2003-11-03 02:27 PM Mini-putt for a slow day on korg ...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Here's a little mini-putt challenge for a slow (here rainy) day ... kind of an extention of the PxMagic tourney kinda ...

Object:

Given a hexidecimal number representing an RGB color, with a format like this:

&BBGGRR

where

BB = the blue color component
GG = the green color component
RR = the red color component

create a little algorithm that strips-out the three color components into seperate $vars (for example $blue, $green, $red) as a number from 0 to 255 ...

For example, I give you the color YELLOW specified in BGR like this:

&00FFFF

and you give me:

$blue = 00
$green = FF (255)
$red = FF (255)

Don't want it as a UDF, just want some statements of code ... like to see who can get it down to the fewest statements, $vars should be dimmed though.

-Shawn

Top
#106489 - 2003-11-03 02:28 PM Re: Mini-putt for a slow day on korg ...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
dad, can I use baseconverter() ?
_________________________
!

download KiXnet

Top
#106490 - 2003-11-03 02:38 PM Re: Mini-putt for a slow day on korg ...
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
code:
Break ON
Dim $, $c, $x
$= "&00FFFF"
for $x=2 to 6 step 2
$rc = execute("$$c = &"+ substr($,$x,2))
? $c
next


exit 0

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#106491 - 2003-11-03 02:52 PM Re: Mini-putt for a slow day on korg ...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
ok, ok - you made it look too easy - let me give you entire spec ...

This is going to be used in a FadeToBlack() UDF ... FadeToBlack() takes a number (a hex number) in the BBGGRR format above, and a second parameter called "level" that is a number from 0 to 255 (0 to FF) ... you call it like this:

$color = FadeToBlack($color, 200)

Here's what FadeToBlack should do. Compare each color component (0-FF) with "level" ... if the color component is less than level, leave it alone. If the color component is equal to or greater than level - set the color component to equal level. Then "reassemble" the color components back into a BBGGRR color, for example:

$color = &00DDFF
$color = FadeToBlack($color, &EE)

color should now be: &00DDEE. Then when you call it again, using the new value of color and a new value for level,

$color = &00DDEE
$color = FadeToBlack($color, &DD)

color should now be &00DDDD

and again:

$color = &00DDDD
$color = FadeToBlack($color, &CC)

color will be &00CCCC and so on and so on. The level parm will always be a value from 0 to FF (255) ... under no circumstances should a negative BBGGRR color be returned ...

Top
#106492 - 2003-11-03 02:56 PM Re: Mini-putt for a slow day on korg ...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
code:
$in= "&00FFFF"
Dim $, $c
for $=1 to 3
$c = execute("? &"+substr($in,$*2,2))
next

should do and be less than hoby's [Wink]

[ 03. November 2003, 14:59: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#106493 - 2003-11-03 02:56 PM Re: Mini-putt for a slow day on korg ...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
More details and the prototype:

Function FadeToBlack($color, $level)

$FadeToBalck = <number>

EndFunction

FadeToBlack HAS to return a number. THe big thing is the following: it HAS to be FAST, FAST, FAST ... even more important then size, speed is the watch word here ... but ideally, this routine should be small and FASSSSTTTT !

-Shawn

Top
#106494 - 2003-11-03 03:36 PM Re: Mini-putt for a slow day on korg ...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
eh?
you want us to return number even though you feed some basta-hex?
_________________________
!

download KiXnet

Top
#106495 - 2003-11-03 03:41 PM Re: Mini-putt for a slow day on korg ...
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
code:
function FadeToBlack($color, $level)

Dim $B, $G, $R
$B=$color/65536
$G=($color mod 65536)/256
$R=$color-($B*65536)-($G*256)

$B = IIF($B<$level), $B, $B-17)
$G = IIF($G<$level), $G, $G-17)
$R = IIF($R<$level), $R, $R-17)

$B = IIF($B<0), 0, $B)
$G = IIF($G<0), 0, $G)
$R = IIF($R<0), 0, $R)

return ($B*65536)+($G*256)+$R

endfunction

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#106496 - 2003-11-03 03:46 PM Re: Mini-putt for a slow day on korg ...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
noo!
here:
code:
;$i = color
;$l = level
function fadetoblack($i,$l)
Dim $, $c, $x
$l=right($l,2)
for $x=1 to 3
$c=substr($i,$x*2,2)
$=$+iif($l>$c,$c,$l)
next
$fadetoblack=val("&"+$)
endfunction



[ 03. November 2003, 16:07: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#106497 - 2003-11-03 03:55 PM Re: Mini-putt for a slow day on korg ...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
hehee, just got back from coffee and two submissions already ... let me plug both these into my game and see which one works best ...

[ 03. November 2003, 15:55: Message edited by: Shawn ]

Top
#106498 - 2003-11-03 03:59 PM Re: Mini-putt for a slow day on korg ...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
ok, jooel's submission gets the following:

ERROR : undefined variable [$b]!
Script: C:\kixpad\ship.KIX
Line : 1045

Top
#106499 - 2003-11-03 04:08 PM Re: Mini-putt for a slow day on korg ...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
forgot one letter!
try again with the above.
_________________________
!

download KiXnet

Top
#106500 - 2003-11-03 04:08 PM Re: Mini-putt for a slow day on korg ...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Howards submission has some mis-matched parens and doesn't return the number, but when patched, returns the wrong number - but close:

code:
function FadeToBlack($color, $level)

Dim $B, $G, $R

$B=$color/65536
$G=($color mod 65536)/256
$R=$color-($B*65536)-($G*256)

$B = IIF($B<$level, $B, $B-17)
$G = IIF($G<$level, $G, $G-17)
$R = IIF($R<$level, $R, $R-17)

$B = IIF($B<0, 0, $B)
$G = IIF($G<0, 0, $G)
$R = IIF($R<0, 0, $R)

$fadeToBlack = ($B*65536)+($G*256)+$R

endfunction

$c = fadeToBlack(&00DDFF,&DD)

?"value=" DecToHex($c)

returned value is CCEE, should be &00DDDD

-Shawn

Top
#106501 - 2003-11-03 04:09 PM Re: Mini-putt for a slow day on korg ...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
in english:
$=$+iif($b>$c,$c,$l)

should be:
$=$+iif($l>$c,$c,$l)
_________________________
!

download KiXnet

Top
#106502 - 2003-11-03 04:14 PM Re: Mini-putt for a slow day on korg ...
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
quote:
let me plug both these into my game and see which one works best ...
Cool ! A new game. Can't wait to see that one [Smile]
_________________________



Top
#106503 - 2003-11-03 04:15 PM Re: Mini-putt for a slow day on korg ...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Still wrong number buddy - one point of clarification ... the numbers passed may be specifed in HEX ie,

$color = FadeToBlack(&00DDEE, &DD)

but they are decimal inside the UDF ... so wouldn't make any assumptions about that. Just that they are easier to pass and visualize using hex. With Jooels ...

$c = fadeToBlack(&00DDFF,&DD)

?"value=" DecToHex($c)

value is: 8441 (dec) 2121 (hex) - should be 56797 (dec) or DDDD (hex)

Top
#106504 - 2003-11-03 04:21 PM Re: Mini-putt for a slow day on korg ...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
shawn, you changed the rules.
first you gave input of string and now you give hex.
try to make up your mind!

doing simple test run:

code:
$in= "&00FFFF"
val($in) ?
$level
function fadetoblack($i,$l)
Dim $, $c, $x
$l=right($l,2)
for $x=1 to 3
$c=substr($i,$x*2,2)
$=$+iif($l>$c,$c,$l)
next
$fadetoblack=val("&"+$)
endfunction
fadetoblack( "&00FFFF","&DD")

get $

gives correct results.
_________________________
!

download KiXnet

Top
#106505 - 2003-11-03 04:23 PM Re: Mini-putt for a slow day on korg ...
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Slow on the draw there Lonkero. Saw that immediately thus my approach. [Wink]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#106506 - 2003-11-03 04:25 PM Re: Mini-putt for a slow day on korg ...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
where did I say that FadeToBlack took a string ? said it took a number in the BBGGRR format. Check-out the examples in the long-winded specification.

jochen - in a way, you have already seen this game - about 3 years ago in the BGI days [Wink]

[ 03. November 2003, 16:27: Message edited by: Shawn ]

Top
#106507 - 2003-11-03 04:29 PM Re: Mini-putt for a slow day on korg ...
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
The one with the Ship ?
Uh Baby !!
_________________________



Top
Page 1 of 3 123>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 837 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.16 seconds in which 0.112 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org