screenmouseloc not cutting it

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: FourthWorld, heatherlaine, Klaus, kevinmiller

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: screenmouseloc not cutting it

Post by bogs » Fri Oct 13, 2017 10:35 pm

Um. If I get what your trying to accomplish, this should work. For the moment, just make a simple stack like this
with some color filled rectangles and a field.
Image
I put this at the stack level, but depending on what your trying to accomplish you might want it elsewhere.
Image
Then just move your mouse around the things in the stack and watch the field, you should see the rgb values changing while you are within the program window.

You can click anywhere to have the mouse cursor move and tell you the color at the location it lands. Hope that helps.

Just noticed I am getting closer and closer to Klaus's code :lol:

BTW, I'd never recommend using mouseMove messages for anything much more complicated than this, probably.
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: screenmouseloc not cutting it

Post by FourthWorld » Fri Oct 13, 2017 10:42 pm

Klaus wrote:
Fri Oct 13, 2017 5:55 pm
FourthWorld wrote:
Fri Oct 13, 2017 5:48 pm
The toLocal and toGlobal functions translate points between coordinate systems.
@Richard
Maybe you have these functions in your own personal libraries, but these are no build-in LC functions! :D
You're right. I was pre-coffee and thinking in SuperTalk. In LiveCode the functions are named localLoc and globalLoc.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: screenmouseloc not cutting it

Post by Da_Elf » Fri Oct 13, 2017 11:39 pm

Thanks bogs. What i am trying to do is set an array of 8 coordinates and test the color at each coordinate to see if the color is white or not and set a true or false into my list at those coordinates. Its my way of testing a walkable area in an A* Pathfinder script. This is the 1st part in the piece of a larger puzzle

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: screenmouseloc not cutting it

Post by Da_Elf » Fri Oct 13, 2017 11:43 pm

Fourthworld im just spitballing here but i guess i would say

Code: Select all

set the screenmouseloc to globalloc(250,250)
as an example

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: screenmouseloc not cutting it

Post by bogs » Sat Oct 14, 2017 9:24 am

Well, as you just described it, to me it looks like the code your trying for is right there.

Your array is going to have the x,y set, and those points are going to be within the rect of your program. A simple repeat loop should tell you what the colors of each point are, I'd probably use something like

Code: Select all

// psuedo code
on [message]
   repeat with x = 1 to the number of points of myArray
      if the foregroundColor of x = "255,255,255" then set xValue to true
   end repeat 
end [message]
I used 'foregroundColor' because earlier you were asking about mouseColor, but really there are a LOT of other color arrangements you could test for.

If your game is using mouse clicks, it would be even easier, something like

Code: Select all

if the mouseColor = "white" then put "true" into xValue
Alternately, I could just be missing something blatantly obvious from your side not coming across in the description to me.

Took a look at your code (finally had some time, but am just waking up really). Curious about this part -

Code: Select all

function walkarea mPosition
   set the screenmouseloc to Calculatescreenpos(mPosition)
   if the mousecolor <> 255,255,255 then
      put "P" into walkable
   else
      put "B" into walkable
   end if
   return walkable
end walkarea
I probably don't have my mind right, but why not something like

Code: Select all

function walkarea mPosition
   set the screenmouseloc to Calculatescreenpos(mPosition)
   if the mousecolor = "255,255,255" then put "P" into walkable
   return walkable
end walkarea
Again, I don't know how much this game is using the mouse, but if your returning sLoc from calculating the screen pos, why not just get the color of sLoc?

Code: Select all

function walkarea mPosition
   if the foregroundColor of sLoc = "255,255,255" then put "P" into walkable
// anything else isn't "P" and can be rejected as not walkable...
   return walkable
end walkarea
I won't go into using globals and like that.
Image

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: screenmouseloc not cutting it

Post by Da_Elf » Sat Oct 14, 2017 3:05 pm

the game does use mouse clicks. The character is at the start position x,y and the click is the end position x,y but what i need to test for is a path from start to finish making its way around obstacles. This is why i need to check different spots along the way

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: screenmouseloc not cutting it

Post by jacque » Sat Oct 14, 2017 5:48 pm

if the foregroundColor of sLoc = "255,255,255" then
Did you try this? The engine won't know that sLoc numbers indicate a pixel on screen. Right now the only way to test for a color without parsing the binary content of an image is to use mousecolor.

Well, there's one other way actually. I have a little trick stored in my saved snippets somewhere, if I can find it I'll post it later. But I think using mousecolor is probably easiest.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: screenmouseloc not cutting it

Post by Da_Elf » Sat Oct 14, 2017 6:19 pm

so this will allow me to check the color at any pixel on the screen? i was trying to find something like that and a lot of posts i found kept mentioning mousecolor

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: screenmouseloc not cutting it

Post by bogs » Sat Oct 14, 2017 6:33 pm

Ah, I get it now,
Da_Elf wrote:
Sat Oct 14, 2017 3:05 pm
the game does use mouse clicks. The character is at the start position x,y and the click is the end position x,y but what i need to test for is a path from start to finish making its way around obstacles. This is why i need to check different spots along the way
my bad. If your using points on a path, though, you could just move along a path without checking anything. For instance, I was screwing around with a splash for a demo, and was moving bubbles along a path (several actually) that I created with a free hand tool.

These lines are from 2 different handlers, but I don't think it would be hard to modify it to what your talking about.

Code: Select all

// set the starting point of your move
 set the location of graphic "bubOne" to 113,395 // beginning of one path
 // move along that path
 move graphic "bubOne" to the points of graphic "mainPathOne"
jacque wrote:
Sat Oct 14, 2017 5:48 pm
Did you try this? The engine won't know that sLoc numbers indicate a pixel on screen. Right now the only way to test for a color without parsing the binary content of an image is to use mousecolor.
Actually, I didn't, which is also my bad. I just assumed you could grab the foreground color of a specific pixel by location. You would think I'd know better by now :oops:

On the other side of that, I ALWAYS look forward to you opening your bag of tricks Jacque :mrgreen:
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: screenmouseloc not cutting it

Post by jacque » Sat Oct 14, 2017 8:36 pm

I've been collecting handlers and tricks for years, here is what I have for retrieving the color of a designated pixel. My own contribution is what we've already discussed, followed by two other methods. The second one is ingenius and is what I was thinking of, I wish I'd saved the name of the author.

Code: Select all

Jacque's version:

function getPixelColor pPt -- pass local stack-based pt
  put the screenmouseloc into tOldLoc
  put (item 1 of pPt) + (the left of this stack) into tloc
  put (item 2 of pPt) + (the top of this stack) into item 2 of tloc
  set the screenmouseloc to tloc
  put the mousecolor into tColor
  set the screenmouseloc to tOldLoc
  return tColor
end getPixelColor


------

Unknown author:

function readPixelColor pVal
   put globalLoc(pVal) into pVal
   put item 1 of pVal + 1 into item 3 of pVal
   put item 2 of pVal + 1 into item 4 of pVal
   export snapshot from rect pVal to templateImage
   get the imageData of templateImage
   reset templateImage
   return byteToNum(char 2 of it) & "," & byteToNum(char 3 of it) & "," & byteToNum(char 4 of it)
end readPixelColor

-------
Scott Rossi:

local theImageData

function getPixelColor pImage,pX,pY
   if theImageData is empty then put the imageData of pImage into
theImageData
   put width of pImage into W
   put ((pY-1)*W)*4+pX*4 into lastChar
   put charToNum(char lastChar of theImageData) into B
   put charToNum(char lastChar-1 of theImageData) into G
   put charToNum(char lastChar-2 of theImageData) into R
   return R,G,B
end getPixelColor


This should retrieve the color of a pixel in a target image based on the X,Y
offset of the touch from the topLeft.  The idea is to store the imageData of
the target image in theImageData variable so the function doesn't have to
retrieve it repeatedly.

I've been wanting mouseColor on iOS myself and while not true mouseColor,
this comes close.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: screenmouseloc not cutting it

Post by bogs » Sat Oct 14, 2017 10:18 pm

I guess I shouldn't be surprised to see Scott's name in that mix 8) Pretty slick stuff, but I am still surprised that with all the pixel related things built in, there isn't a one line method to get the color of one like how the mouseColor works.

What I had thought there would be (before you pointed out there wasn't) would be something like

Code: Select all

get the foregroundColor of (pixel(x,y)) // or any of the other 'color types
Still, yours looks the easiest to mold to this problem, after all, he is almost to that point now. Tough call, slick, slicker, slickest :P

*Edit -
I did just try this, and it worked so fast that without locking the screen, I couldn't see the mouse move, so not sure why you would see the jitter you were talking about earlier Da_Elf ? There is simply 3 points, in this case I'm only using one for the x,y point, but I did click as far from the blue one as I could, and thats the rgb you see in the 2nd field.
Image

*Edit 2 -
I should add that I still think you'd be better off using move along path setup than this method, but least you got choices :shock:
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: screenmouseloc not cutting it

Post by jacque » Sat Oct 14, 2017 11:00 pm

Right, the change in the mouse position is too fast to see. I think in this case locking the screen might actually slow it down.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: screenmouseloc not cutting it

Post by bogs » Sat Oct 14, 2017 11:40 pm

That makes sense. I wonder if you did a lot of those, if that would make it more visible. Tomorrow I'll random a bit and find out :D
Image

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: screenmouseloc not cutting it

Post by Da_Elf » Sun Oct 15, 2017 1:05 am

My reason for wanting to spot check a color by position goes way beyond a path bogs. so far there has been loads of help here so far.

This video is the best way to explain it.
the 1st video gives a concept that anyone can understand.
the 2nd coded it for unity in c# which i tried to break down and change to livecode which i got done and it worked
the 3rd video i got lost
after that... well screw it.

Ive been trying to optimize it myself in livecode.

this is the video

https://www.youtube.com/watch?v=-L-WgKMFuhE

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: screenmouseloc not cutting it

Post by bogs » Sun Oct 15, 2017 10:54 am

Ahhhh, I get it. Well, I see why your looking for colors, I probably shouldn't say I get the rest of it :P
Image

Post Reply