How to determine the color of a pixel?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
MagicBoy
Posts: 3
Joined: Wed Feb 06, 2019 12:35 am

How to determine the color of a pixel?

Post by MagicBoy » Tue May 14, 2019 9:07 pm

Hello, all!

I have taken up "book folding" which is the folding, measuring and cutting of the pages of a book to create a "relief" image in the pages when the book is set on it's end and opened to 90 degrees (if that made no sense whatsoever, search for "book folding" on Etsy for lots of examples).

Since I haven't found any good book-fold creation software on the Mac, I decided to write my own.

I wrote a stack that "reads" vertical slices of a black & white 1-bit graphic and lets me know the screen coordinates when the color changes (from white to black or from black to white).

Currently, I'm doing it by automating the mouse pointer to move down a single column of the graphic in teensy, weensy steps and logs the change into a field when the color change occurs. When it gets to the bottom of that column, it starts over again at the top in the next column and continues until it has covered the entire graphic (depending on the size of the graphic, this can take several hours to finish this process). It works fine but it's tediously slow.

What I would LOVE to do, to speed this up, is to have the "scanning" process happen WITHOUT having to move the mouse pointer. In other words, I'd like to quickly and easily know if the pixel at location x,y is "0,0,0" (black) or "255,255,255" (white).

Is there any way to do this without moving the mouse pointer to that location? I've scoured the LC user dictionary but this basic (to me) function seems to be missing.

Thanks for taking the time to read through this. Much appreciated.


Geoff

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6599
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How to determine the color of a pixel?

Post by FourthWorld » Tue May 14, 2019 9:22 pm

First, I didn't know what book folding was until your post - it's awesome! thanks.
https://www.etsy.com/market/book_folding

Changing the mouseLoc is pretty fast for one-offs, but if you need to check every pixel in an entire image I would imagine it's much faster to get the imageData and walk through it in a loop.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

MagicBoy
Posts: 3
Joined: Wed Feb 06, 2019 12:35 am

Re: How to determine the color of a pixel?

Post by MagicBoy » Tue May 14, 2019 10:21 pm

Wow, that was fast! Thanks, Richard!

I'll dig deeper into working with the imageData.


Geoff

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5957
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to determine the color of a pixel?

Post by dunbarx » Wed May 15, 2019 2:25 pm

Hi.

Did you do something like this:

Code: Select all

on mouseUp
   put the botRight of this cd into lastPixel
   
   repeat with x = 1 to item 1 of lastPixel
      repeat with y = 1 to item 2 of lastPixel
         set the screenMouseloc to x & "," & y
         put mouseColor() & return after colorData
      end repeat
   end repeat
end mouseUp
That would indeed take a while. Just like writing to a field, the fact that LC has to interact with the screen takes a whole lot of time.

I have always wanted to have a function "the pixelColor", that would not require the actual cursor to be placed somewhere, only to specify a loc. Maybe we can propose an enhancement request.

Craig Newman

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”