Failing to WritePixelFast to CanvasBuffer

BlitzPlus Forums/BlitzPlus Programming/Failing to WritePixelFast to CanvasBuffer

Pineapple(Posted 2008) [#1]
I have now found the problem, but I need to find out how to fix it.


How do you take a string of text that represents a hexadecimal color code ( $FD4A67 ) and convert it into a format readable by WritePixelFast?


Timjo(Posted 2008) [#2]
Here's how I would do it. It's a fairly clumsy way. I'm sure there is someone out there who could provide a slicker solution.

It's basically just stripping out each 'Letter' from the string you provided, finding it's decimal value using it's ascii value, and multiplying up according to it's positon in the string.

ie: right to left dec * 2^0 ..... dec *2^4 .... dec *2^8 etc..
The last operation puts it in the correct format.
The final value 'colour_val' should be useable with writepixelfast.


CODE:

------------
colour_hex$="$FD4A67" ; your text string

multiply=1

colour_val=0

For string_pos=7 To 2 Step-1

asc_val=Asc(Mid$(colour_hex$,string_pos,1))

If asc_val>=65 And asc_val<=70
colour_val=colour_val+( (asc_val-64+9) * multiply) ; A to F
Else
colour_val=colour_val+( (asc_val-48) * multiply) ; 0 to 9
EndIf

multiply=multiply Shl 4

Next

colour_val=$ff000000+colour_val
----------



There is also a post in these forums about converting colour values which might be of use..Here's the link:

http://www.blitzbasic.com/Community/posts.php?topic=25938#269844

Hope this helps. Tim.


Pineapple(Posted 2008) [#3]
Thank you very much for your help. Now once I polish this thing up it'll probably end up in the showcase!

Would like a mention someplace?


Timjo(Posted 2008) [#4]
You're welcome B+man, glad it was useful. Let me know when you finish the project. The demos looked really clever.

(Yes, I am part of the 8%..but it was so long ago I can't even remember being a teenager - guess that's why I'm in that 8% ).


Pineapple(Posted 2008) [#5]
Well, I don't feel that it's yet ready for the showcase, but here's the latest version.

You can follow QuickSand's progress here.

Download QuickSand v1.1 Alpha 2.5