Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: DrewPee on September 17, 2008

Title: help with tinyptc . . .
Post by: DrewPee on September 17, 2008
Hello,
I need a little help please? Not sure if this has been covered before . . .

In tinyptc, how can you check if a pixel is a certain colour? is there a way to read each pixel on the screen and return as a value . . . ?

Regards and appreciation

Andy aka DrewPee
Title: Re: help with tinyptc . . .
Post by: hellfire on September 17, 2008
Have a look at the example files of TinyPTC Ext (http://dbfinteractive.com/forum/index.php?topic=1382.0).
There's a buffer (of 32bit integers) which stores the rgb-color (8bit per component) of each pixel:
Code: [Select]
dim shared buffer(640*480) as integer
If you want to display anything, you just have to write it into the buffer.
The whole buffer is then copied to the screen:
Code: [Select]
ptc_update @buffer(0)
So it's really simple to find out the color of a pixel at position x,y:
Code: [Select]
col= buffer(y*640+x)
red= (col shr 16) and 255
green= (col shr 8) and 255
blue= col and 255
(assuming your resolution is 640 * something)
Title: Re: help with tinyptc . . .
Post by: DrewPee on September 18, 2008
@Hellfire
Thanks! I knew it could be done - just couldn't figure out how!
Very much appreciated!

Andy
Title: Re: help with tinyptc . . .
Post by: DrewPee on September 18, 2008
Still having problems . . .

Sub DrawStars1
    for a=0 to ns-1
        testpixel=buffer(y(a)*640+x(a))
        red= (testpixel shr 16) and 255
        green= (testpixel shr 8) and 255
        blue= testpixel and 255
        total = red+green+blue
        'if total=white then dont print! any other colour print?
        if total>0 then pp(x(a),y(a),rgb(r,g,b))
        if total>0 then pp(x1(a),y1(a),rgb(r1,g1,b1))
        if total>0 then pp(x2(a),y2(a),rgb(r2,g2,b2))
        if total>0 then pp(x3(a),y3(a),rgb(r3,g3,b3))
    next a
End Sub

am i doing something really obviously wrong?

Andy
Title: Re: help with tinyptc . . .
Post by: hellfire on September 18, 2008
"white" means that every color-component is set to maximum (255), so "total" would be 255*3.
Of course you don't have to test every component separately:
Code: [Select]
if testpixel<>&hffffff
  pp(x(a),y(a),rgb(r,g,b))
Title: Re: help with tinyptc . . .
Post by: Clyde on September 18, 2008
Btw, if you use the [ code ] and [ / code ] tags, it'll do away with mr smiley.
Title: Re: help with tinyptc . . .
Post by: DrewPee on September 19, 2008
Hellfire,
Thanks for your help on this. It is now working! Cheers

Clyde,
Thanks to you too . . . i always forget about the [ code ] tags!!!