Am 08.05.2006 um 19:58 schrieb [EMAIL PROTECTED]:


Hi,

As mentioned on Direct-L, you can create a Math object from a JS script, (not using flash asset??).

with math=getMath()

and a JS script:
function getMath()
{
return Math;
}


It takes about 1780 ms for the script to run, against 2580 for Valentin's original script.

Alex, your method is still faster with 1240 ms.

out of interest, did you test on mac or PC ?


Now my question is: Where does the Math() object come from in the JS version?

As far as I understand, it is a complete ECMA framework called SpiderMonkey Engine.
So the Math object is certainly a class of this framework.

what is in the math object from flash or spider monkey, what you can't do in lingo ? I have a bunch of parent scripts written in lingo which may be pretty similar, but are in most cases significantly faster. so why are people so thrilled about using the flash or the ECMA math object rather than a lingo math object ?

as for performance, there is another little optimization, which can be done for Valentins handler: replace the power() function, as for an unknown reason the power() function is known to be somewhat slow.


here's what gave me the best results:


-- Parentscript "spherizeFilter"
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on new me
  return me
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-- optional parameters tPercent, tCenter, tRadius
-- defaults: tPercent=100%, tCenter=center of image
on spherize me, tImage, tPercent, tCenter, tRadius

  ms = the milliseconds
  w = tImage.width
  h = tImage.height

  if voidP(tPercent) then tPercent=100.0
  if voidP(tCenter) then tCenter = point(w/2, h/2)
  if voidP(tRadius) then tRadius = min(w/2, h/2)

  newImage = tImage.duplicate()
  centerX = tCenter[1]
  centerY = tCenter[2]
  rr = tRadius / sqrt(1- power(1-tPercent/100.0, 2) )

  f = asin(me, tRadius/rr) -- 100%: pi/2

  repeat with y = 0 to h-1
    repeat with x = 0 to w-1
      deltaX = x - centerX
      deltaY = y - centerY
      d0 = sqrt((deltaX*deltaX) + (deltaY*deltaY))
      if d0<tRadius then
        if d0>0 then
          d1 = tRadius * asin(me, d0/rr)
          k = d1/d0/f
          xNew = centerX + (deltaX * k)
          yNew = centerY + (deltaY * k)
newImage.setPixel(x, y, tImage.getPixel(xNew, yNew, #integer))
        end if
      end if
    end repeat
  end repeat

  tImage.copyPixels(newImage, newImage.rect, newImage.rect)
  put the milliseconds - ms
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on asin me, ratio
  if ratio < 1 and ratio > -1 then
    RETURN atan(ratio/sqrt(1.0 - (ratio * ratio)))
  else if ratio = 1 then
    RETURN pi()/2
  else if ratio = -1 then
    RETURN -pi()/2
  end if
end



---------------------------

  |||
a¿ex



[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[email protected]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to