lunedì 10 novembre 2014

Intersezione di due grafici o immagini

Il seguente codice permette di visualizzare solo la parte in comune di due grafici o due immagini.
Ad esempio nell'immagine successiva abbiamo un quadrato e un cerchio e visualizziamo solo la parte sovrapposta dei due.
example
Il codice crea un gruppo con le due immagini, ne fa vedere solo una alla volta e ne crea le relative immagini (temp1 e temp2), successivamente analizza le parti non trasparenti in comune e le applica a una delle due immagine.

on graphIntersection graph1, graph2
   group graphic graph1 and graphic graph2
   set the name of the last group to "tempg"
   set the showborder of group "tempg" to false
   set the lockloc of group "tempg" to true
   set the visible of graphic graph2to false
   import snapshot from group "tempg"
   set the name of the last image to "temp1"
   set the visible of graphic graph2to true
   set the visible of graphic graph1to false
   import snapshot from group "tempg"
   set the name of the last image to "temp2"
   set the visible of graphic graph1to true
   put the alphadata of image "temp1" into aImage1
   put the alphadata of image "temp2" into aImage2
   put the length of aImage1 into numpix
   repeat with i=1 to numpix
      if (charTonum(char i of aImage1) is not 0) and (chartoNum(char i of aImage2) is not 0) then
         put numtoChar(255) after tResult
      else
         put numtoChar(0) after tResult
      end if
   end repeat
   set the alphadata of image "temp1" to tResult
   delete image "temp2"
   ungroup group "tempg"
end graphIntersection

Se volete applicarlo alle immagini, basta cambiare le parole graphic con image nella prima riga.

Nessun commento:

Posta un commento