Re: Shaping an image to fit in a polygon

2021-10-18 Thread David Epstein via use-livecode
Jacqueline Gay’s suggestion is excellent, and by exactly aligning the rect of 
the polygon with the rect of the image being “trimmed”, I can avoid having the 
image centered or repeated.  See script below.  

I am still wondering what goes wrong with my alphaChannel approach to showing 
irregularly shaped images.  Is there some imprecision in the “within” function? 
 This would be important to know for other uses of it.

David Epstein

on imageToGrc gID
  # fills graphic id gID with image it is positioned on; works for polygon, 
oval, regular, or rectangle
  set the linesize of grc id gID to 0
  set the filled of grc id gID to false
  wait 1 ticks # seems needed so that linesize of 0 is respected
  hide grc id gID
  import snapshot from rectangle globalRect(the rect of control id gID)
  put the short id of image (the number of images) into imID
  set the rect of image id imID to the rect of grc id gID
  set the filled of grc id gID to true
  set the backgroundPattern of grc id gID to imID
  show grc id gID
  set the loc of grc id gID to the bottomRight of grc id gID ## to make it 
visible
  hide image id imID  ## note:  don’t delete, or polygon loses the image
  choose browse tool
end imageToGrc

function globalRect theRect
  return globalLoc(item 1 to 2 of theRect),globalLoc(item 3 to 4 of theRect)
end globalRect
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Shaping an image to fit in a polygon

2021-10-16 Thread J. Landman Gay via use-livecode

On 10/16/21 2:17 PM, David Epstein via use-livecode wrote:

I am trying to create an image that will appear to have the shape of some 
arbitrary polygon.  The idea is to set the image's alphaData so that pixels 
within the polygon are opaque, and those outside the polygon are transparent.  
The scripts below create a rectangular image of whatever is under the polygon's 
enclosing rectangle, and then adjust the alphaData of that new image.  But 
while the new image gets trimmed a bit, the result does not match the shape of 
the designated polygon.  Any thoughts?


If it's acceptable to make the polygon and the image the same size, you can just set the 
backgroundPattern of graphic to the ID of the image and it will appear the way you want. The 
down side is that the pattern is drawn from the top left of the graphic rather than centered 
within it, so that may be an issue.


--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Shaping an image to fit in a polygon

2021-10-16 Thread Richmond via use-livecode

Sorry, I am carrying this over to the Forums as I have a pictorial mind.

https://forums.livecode.com/viewtopic.php?f=7=36367

Richmond.

On 16.10.21 23:04, Richmond wrote:
Also, this presupposes that your 'arbitrary polygon' is exactly that, 
while LiveCode starts a 'polygon graphic' as
a line, and it is quite possible to end up with something that does 
NOT involve an enclosed territory.



On 16.10.21 23:00, Richmond wrote:
I'm a lazy slob, and because of that I would just do this sort of 
thing outwith LiveCode,

with, say, GIMP.

If you could explain your rationale behind trying to go "the long way 
round" in LiveCode

I might be both more sympathetic and more helpful.

Best, Richmond.

On 16.10.21 22:17, David Epstein via use-livecode wrote:
I am trying to create an image that will appear to have the shape of 
some arbitrary polygon.  The idea is to set the image's alphaData so 
that pixels within the polygon are opaque, and those outside the 
polygon are transparent.  The scripts below create a rectangular 
image of whatever is under the polygon's enclosing rectangle, and 
then adjust the alphaData of that new image.  But while the new 
image gets trimmed a bit, the result does not match the shape of the 
designated polygon. Any thoughts?


David Epstein

on action gID ## gID is the short id of the polygon
   import snapshot from rectangle globalRect(the rect of control id 
gID)

   put the short id of image (the number of images) into imID
   set the width of image id imID to the width of grc id gID
   set the height of image id imID to the height of grc id gID
   set the loc of image id imID to the loc of grc id gID
   set the polyCrop of image id imID to gID
end action

function globalRect theRect
   return globalLoc(item 1 to 2 of theRect),globalLoc(item 3 to 4 of 
theRect)

end globalRect

setProp polyCrop polyID
   -- crop target image's alphadata to show only points within grc 
id polyID

   put the filled of grc id polyID into fillState
   set the filled of grc id polyID to true
   put the rect of the target into r
   put numToChar(255) into P ## opaque
   put numToChar(0) into T ## transparent
   repeat with y = 1+item 2 of r to item 4 of r ## SEE NOTE*
 repeat with x = 1+item 1 of r to item 3 of r
   put x,y into myPoint
   if within(grc id polyID,myPoint) then put P after hold else 
put T after hold

 end repeat
   end repeat
   set the filled of grc id polyID to fillState
   set the alphaData of the target to hold
end polyCrop

* NOTE:  the "1+" is these statements is my effort to step through 
the exact number of pixels in the width and height of the image.  
The number of values in the series (item 1 of the rect of the image) 
to (item 3 of the rect of the image), inclusive, is 1+ the width of 
the image.  (But I am not really sure whether to add 1 to the first 
value or subtract 1 from the last value).

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your 
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-livecode







___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Shaping an image to fit in a polygon

2021-10-16 Thread Richmond via use-livecode
Also, this presupposes that your 'arbitrary polygon' is exactly that, 
while LiveCode starts a 'polygon graphic' as
a line, and it is quite possible to end up with something that does NOT 
involve an enclosed territory.



On 16.10.21 23:00, Richmond wrote:
I'm a lazy slob, and because of that I would just do this sort of 
thing outwith LiveCode,

with, say, GIMP.

If you could explain your rationale behind trying to go "the long way 
round" in LiveCode

I might be both more sympathetic and more helpful.

Best, Richmond.

On 16.10.21 22:17, David Epstein via use-livecode wrote:
I am trying to create an image that will appear to have the shape of 
some arbitrary polygon.  The idea is to set the image's alphaData so 
that pixels within the polygon are opaque, and those outside the 
polygon are transparent.  The scripts below create a rectangular 
image of whatever is under the polygon's enclosing rectangle, and 
then adjust the alphaData of that new image.  But while the new image 
gets trimmed a bit, the result does not match the shape of the 
designated polygon. Any thoughts?


David Epstein

on action gID ## gID is the short id of the polygon
   import snapshot from rectangle globalRect(the rect of control id gID)
   put the short id of image (the number of images) into imID
   set the width of image id imID to the width of grc id gID
   set the height of image id imID to the height of grc id gID
   set the loc of image id imID to the loc of grc id gID
   set the polyCrop of image id imID to gID
end action

function globalRect theRect
   return globalLoc(item 1 to 2 of theRect),globalLoc(item 3 to 4 of 
theRect)

end globalRect

setProp polyCrop polyID
   -- crop target image's alphadata to show only points within grc id 
polyID

   put the filled of grc id polyID into fillState
   set the filled of grc id polyID to true
   put the rect of the target into r
   put numToChar(255) into P ## opaque
   put numToChar(0) into T ## transparent
   repeat with y = 1+item 2 of r to item 4 of r ## SEE NOTE*
 repeat with x = 1+item 1 of r to item 3 of r
   put x,y into myPoint
   if within(grc id polyID,myPoint) then put P after hold else 
put T after hold

 end repeat
   end repeat
   set the filled of grc id polyID to fillState
   set the alphaData of the target to hold
end polyCrop

* NOTE:  the "1+" is these statements is my effort to step through 
the exact number of pixels in the width and height of the image.  The 
number of values in the series (item 1 of the rect of the image) to 
(item 3 of the rect of the image), inclusive, is 1+ the width of the 
image.  (But I am not really sure whether to add 1 to the first value 
or subtract 1 from the last value).

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your 
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-livecode





___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Shaping an image to fit in a polygon

2021-10-16 Thread Richmond via use-livecode
I'm a lazy slob, and because of that I would just do this sort of thing 
outwith LiveCode,

with, say, GIMP.

If you could explain your rationale behind trying to go "the long way 
round" in LiveCode

I might be both more sympathetic and more helpful.

Best, Richmond.

On 16.10.21 22:17, David Epstein via use-livecode wrote:

I am trying to create an image that will appear to have the shape of some 
arbitrary polygon.  The idea is to set the image's alphaData so that pixels 
within the polygon are opaque, and those outside the polygon are transparent.  
The scripts below create a rectangular image of whatever is under the polygon's 
enclosing rectangle, and then adjust the alphaData of that new image.  But 
while the new image gets trimmed a bit, the result does not match the shape of 
the designated polygon.  Any thoughts?

David Epstein

on action gID ## gID is the short id of the polygon
   import snapshot from rectangle globalRect(the rect of control id gID)
   put the short id of image (the number of images) into imID
   set the width of image id imID to the width of grc id gID
   set the height of image id imID to the height of grc id gID
   set the loc of image id imID to the loc of grc id gID
   set the polyCrop of image id imID to gID
end action

function globalRect theRect
   return globalLoc(item 1 to 2 of theRect),globalLoc(item 3 to 4 of theRect)
end globalRect

setProp polyCrop polyID
   -- crop target image's alphadata to show only points within grc id polyID
   put the filled of grc id polyID into fillState
   set the filled of grc id polyID to true
   put the rect of the target into r
   put numToChar(255) into P ## opaque
   put numToChar(0) into T ## transparent
   repeat with y = 1+item 2 of r to item 4 of r ## SEE NOTE*
 repeat with x = 1+item 1 of r to item 3 of r
   put x,y into myPoint
   if within(grc id polyID,myPoint) then put P after hold else put T after 
hold
 end repeat
   end repeat
   set the filled of grc id polyID to fillState
   set the alphaData of the target to hold
end polyCrop

* NOTE:  the "1+" is these statements is my effort to step through the exact 
number of pixels in the width and height of the image.  The number of values in the 
series (item 1 of the rect of the image) to (item 3 of the rect of the image), inclusive, 
is 1+ the width of the image.  (But I am not really sure whether to add 1 to the first 
value or subtract 1 from the last value).
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Shaping an image to fit in a polygon

2021-10-16 Thread David Epstein via use-livecode
I am trying to create an image that will appear to have the shape of some 
arbitrary polygon.  The idea is to set the image's alphaData so that pixels 
within the polygon are opaque, and those outside the polygon are transparent.  
The scripts below create a rectangular image of whatever is under the polygon's 
enclosing rectangle, and then adjust the alphaData of that new image.  But 
while the new image gets trimmed a bit, the result does not match the shape of 
the designated polygon.  Any thoughts?

David Epstein

on action gID ## gID is the short id of the polygon
  import snapshot from rectangle globalRect(the rect of control id gID) 
  put the short id of image (the number of images) into imID
  set the width of image id imID to the width of grc id gID
  set the height of image id imID to the height of grc id gID
  set the loc of image id imID to the loc of grc id gID
  set the polyCrop of image id imID to gID
end action

function globalRect theRect
  return globalLoc(item 1 to 2 of theRect),globalLoc(item 3 to 4 of theRect)
end globalRect

setProp polyCrop polyID
  -- crop target image's alphadata to show only points within grc id polyID
  put the filled of grc id polyID into fillState
  set the filled of grc id polyID to true
  put the rect of the target into r
  put numToChar(255) into P ## opaque
  put numToChar(0) into T ## transparent
  repeat with y = 1+item 2 of r to item 4 of r ## SEE NOTE*
repeat with x = 1+item 1 of r to item 3 of r
  put x,y into myPoint
  if within(grc id polyID,myPoint) then put P after hold else put T after 
hold
end repeat
  end repeat
  set the filled of grc id polyID to fillState
  set the alphaData of the target to hold
end polyCrop

* NOTE:  the "1+" is these statements is my effort to step through the exact 
number of pixels in the width and height of the image.  The number of values in 
the series (item 1 of the rect of the image) to (item 3 of the rect of the 
image), inclusive, is 1+ the width of the image.  (But I am not really sure 
whether to add 1 to the first value or subtract 1 from the last value).
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode