Area of Irregular Polygon

BNig bernd.niggemann at uni-wh.de
Wed Nov 11 20:01:46 EST 2015


for those on the list like me who can only iteratively add 1 to a variable
and that have 10 seconds to spare to get at the area of a polygon:
here is what the screen thinks it is:

-----------------------------------------------
on mouseUp
   put "poly" into pName
   
   if not (there is a graphic pName) then
      answer "couldnt find graphic to analyze"
      exit mouseUp
   end if
   
   lock screen
   if there is a image "ImageForArea" then delete image "ImageForArea"
   put the milliseconds into start
   
   -- set up the graphic for black
   put the opaque of graphic pName into tOldOpaque
   put the editMode of graphic pName into tOldEdit
   put the backgroundcolor of graphic pName into tOldBackground
   put the lineSize of graphic pName into tOldLinesize
   put the antialiased of graphic pName into tOldAntiAliased
   
   set the opaque of graphic pName to true -- this forces "closure" of
polygon
   set the backgroundcolor of graphic pName to black
   set the lineSize of graphic pName to 0
   set the editMode of graphic pName to "none"
   set the antialiased of grc pName to false
   
   reset the templateGroup
   set the margins of the templateGroup to 0
   
   select graphic pName
   group
   export snapShot from the last group to tImg as png
   ungroup
   
   create image "ImageForArea"
   set the text of image "ImageForArea" to tImg
   
   put the AlphaData of image "ImageForArea" into tAlphaData
   
   put numToByte(255) into tTransparent -- 0 = transparent
   
   put 127 into tCutOff
   
   put 0 into tBlack
   
   repeat for each byte aByte in tAlphaData
      if byteToNum(aByte) > tCutOff then add 1 to tBlack
   end repeat
   
   -- get rid of the image that was analyzed
   delete image "ImageForArea"
   
   -- restore the graphic
   set the opaque of graphic pName to tOldOpaque
   set the backgroundcolor of graphic pName to tOldBackground
   set the lineSize of graphic pName to tOldLinesize
   set the editMode of graphic pName to tOldEdit
   set the antialiased of graphic pName to tOldAntiAliased
   
   put the milliseconds - start into tTime
   put "Area is " & tBlack & return \
         &  tTime & " milliseconds"  into field "F1" 
   reset the templateGroup
   select empty
end mouseUp
-------------------------------------
here we count the pixel of the alphaData of a snapshot from the graphic that
have a value > 127, i.e. are more than half transparent.

10 seconds is for Hermann's graphic created with testPoints. It is pretty
close to the calculated values.

:)))

Kind regards
Bernd




--
View this message in context: http://runtime-revolution.278305.n4.nabble.com/How-to-interface-with-third-party-API-using-URLs-tp4698551p4698719.html
Sent from the Revolution - User mailing list archive at Nabble.com.




More information about the use-livecode mailing list