Hi Mario,
bjb007 is probably right in what he said regarding the math, but since I am not good at math myself I figured why not let revolution let it do another way
It is a little more involved than I thought but here it is, a solution for someone avoiding the math...
the recipe:
start out with a new stack all white and shiny
make a polygon graphic that you name "AreaOfInterest" in the inspector
make a field you name "f1" in the inspector
make a button the name is not important
set the script of the button to the following script:
---------------------
on mouseUp
if not (there is a graphic "AreaOfInterest") then
answer "couldnt find graphic to analyze"
exit mouseUp
end if
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 "AreaOfInterest" into tOldOpaque
put the backgroundcolor of graphic "AreaOfInterest" into tOldBackground
set the opaque of graphic "AreaOfInterest" to true
set the backgroundcolor of graphic "AreaOfInterest" to black
------
-- here you could move the graphic to a part of the card that is white
-- since if you have overlapping areas in the graphic then
-- this script will return incorrect results
------
-- turn the local coordinates of the graphic into global coordinates
-- since snapshot will not directly take a picture of the graphic
-- because snapshot ignores the opaque property of the graphic
-- and the imageData all black
put the rect of graphic "AreaOfInterest" into myRect
put item 1 to 2 of myRect into tTopLeft
put item 3 to 4 of myRect into tBottomRight
put globalloc(tTopLeft) into item 1 to 2 of myRect
put globalloc(tBottomRight) into item 3 to 4 of myRect
import snapshot from rect myRect -- ( the rect of graphic "AreaOfInterest" in global Coord)
set the name of last image to "ImageForArea"
set the loc of image "ImageForArea" to the loc of graphic "AreaOfInterest"
-- now calculate the area
put the width of image "imageForArea" into tWidth
put the height of image "imageForArea" into tHeight
put tWidth * tHeight into tSoManyPixels
-- now get the imageData -> Documentation
-- each pixel has four bytes
-- the first for the alpha channel which does not interest us
-- the second for red
-- the third for green
-- the fourth for blue
-- each byte has a value between 0 and 255
-- if you do a charToNum of the byte ->Documentation
-- if the color bytes are all 0 then the pixel is black, that is what we are looking for
-- since each pixel has four bytes the number of bytes is pixel times 4
put tSoManyPixels * 4 into tSoLong
put the imagedata of image "ImageForArea" into tImageData
put 0 into tB -- for the numtochar = 0
put 0 into tBlack -- counter for black pixels
put 0 into tOther -- counter for non-black pixels
repeat with i = 1 to tSoLong - 4 step 4
if the chartonum of char i +1 of tImageData is tb and \
the chartonum of char i +2 of tImageData is tb and \
the chartonum of char i + 3 of tImageData is tb then
-- only if all three bytes are 0 then the pixel is black
add 1 to tBlack
else
add 1 to tOther
end if
end repeat
-- get rid of the image that was analyzed
delete image "ImageForArea"
-- restore the graphic
set the opaque of graphic "AreaOfInterest" to tOldOpaque
set the backgroundcolor of graphic "AreaOfInterest" to tOldBackground
put the milliseconds - start into tTime
put "The image has " & tSoManyPixels & " pixels of which " & tBlack & " are black and " & tOther & " are not black" \
& return & "black and non-black pixels add up to " & tBlack + tOther & return \
& tTime & " milliseconds" into field "F1"
end mouseUp
---------------------
read the comments in the script
the basic idea is to make the polygon filled black then make a snapshot of the polygon and you get an image
the image is analyzed for black pixels
the number of black bixels is displayed in the field
so the number of black pixels is the area of the polygon in pixel
(maybe it is easier to learn the math???)
obviously you have to be careful to 'isolate' the polygon from adjacent objects, you could move it temporarily to a white spot on the card, or you could hide temporarily the adjacent objects.
hope this helps
Bernd