The Flying Meat Wiki : AcornReflectPlugin

HomePage :: Categories :: PageIndex :: RecentChanges :: Login/Register
This is an example, which will take the current layer, make a new image to draw into (adding reflections and such), and then make a new document out of it.

Here's what it looks like (the original is on the left):

Reflection


MakeNewImageWithReflection.py
import objc, os, math
from Foundation import *
from AppKit import *

ACScriptSuperMenuTitle = None
ACScriptMenuTitle = "New image with reflection"

def main(image):
    doc          = NSDocumentController.sharedDocumentController().currentDocument()
    data         = doc.dataRepresentationOfType_('public.tiff')
    nsimg        = image.NSImage()
    extent       = image.extent()
    originalSize = extent[1]
    half         = math.floor(originalSize[1] / 2)
    newSize      = (originalSize[0], originalSize[1] + half)
    newImage     = NSImage.alloc().initWithSize_(newSize)
   
    newImage.setFlipped_(True)
    newImage.lockFocus()
   
    NSColor.blueColor().set()
   
    NSBezierPath.bezierPathWithRect_(((0,0), newSize)).fill()
   
    nsimg.drawAtPoint_fromRect_operation_fraction_((0, originalSize[1]), NSZeroRect, NSCompositeCopy, 1.0);
   
    newImage.unlockFocus()
   
    newImage.setFlipped_(False)
   
    newImage.lockFocus()
   
    # trust me, TSGradient is there (it's pretty much CTGradient)
    fade = objc.lookUpClass("TSGradient").gradientWithBeginningColor_endingColor_(NSColor.clearColor(), NSColor.blackColor())
   
    fade.fillRect_angle_(((0, half), (originalSize[0], -half)), 90.0)
   
    nsimg.drawAtPoint_fromRect_operation_fraction_((0, half), NSZeroRect, NSCompositeCopy, 1.0);
   
    newImage.unlockFocus()
   
    # Yes, I know this isn't documented.  I'll have to do that.
    NSDocumentController.sharedDocumentController().newDocumentWithImageData_(newImage.TIFFRepresentation())
   
    # we're not changing the image, so we'll return nothing to put on
    return None




Back to AcornPlugins
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.3
Page was generated in 0.0694 seconds