04-14-2023, 04:00 AM
(04-14-2023, 03:04 AM)mnrvovrfc Wrote:(04-13-2023, 11:48 AM)dbox Wrote:Code: (Select All)Dim colors() As _Unsigned Long
colors("brick red") = &HFFC62D42
colors("electric lime") = &HFFCCFF00
colors("metalic sunburst") = &HFF9C7C38
Cls , 15
Line (10, 10)-(100, 100), colors("electric lime"), BF
Line (200, 200)-(300, 300), colors("brick red"), BF
Circle (200, 100), 50, colors("metalic sunburst")
This could be faked as function, and on 64-bit it's faster than any "dictionary" implementation:
Code: (Select All)FUNCTION colors~& (mycolor$)
DIM iret AS _UNSIGNED LONG
IF mycolor$ = "brick red" THEN
iret = &HFFC62D42
ELSEIF mycolor$ = "electric lime" THEN
iret = &HFFCCFF00
ELSEIF mycolor$ = "metallic sunburst" THEN
iret = &HFF9C7C38
ELSE
iret = 0
END IF
colors~& = iret
END FUNCTION
Sure, but the "dictionary" code is way easier to read, and much better for filling the dictionary with values coming from DATA statements or from files. The data source, as-is, works as documentation.
If speed is critical, then pick the speedy one. If flexibility and readability are critical, then go for the dictionary.