作成した画像(NSImage)に円を塗るAppleScriptです。
最近、6角形の図形ばかり塗りつぶしていましたが、「円に変えるとどうなんだろう?」と考えて、本ルーチンを試作してみました。
ためしに、6角形ではなく円で塗りつぶしてみたものの、そんなにイケていない感じがします。
AppleScript名:画像に円を塗る.scptd |
— – Created by: Takaaki Naganoya – Created on: 2020/02/11 — – Copyright © 2020 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use framework "AppKit" use scripting additions property aRadius : 40 set aFile to POSIX path of (choose file name) if aFile does not end with ".png" then set aFile to aFile & ".png" end if set aColor to current application’s NSColor’s redColor() set aImage to current application’s NSImage’s alloc()’s initWithSize:{300, 300} repeat with y from 0 to 300 by aRadius + 4 repeat with x from 0 to 300 by aRadius + 4 my drawCircleOnNSIMage(aImage, aRadius, x, y, aColor) end repeat end repeat set sRes to my saveNSImageAtPathAsPNG(aImage, aFile) # MARK: Call By Reference on drawCircleOnNSIMage(aImage, aRadius, aXpos, aYpos, aColor) set aBezier to generateCircle(aRadius, aXpos, aYpos) of me (aImage)’s lockFocus() aColor’s |set|() aBezier’s fill() –ぬりつぶし (aImage)’s unlockFocus() end drawCircleOnNSIMage # MARK: circleのBezier曲線を作成して返す on generateCircle(theRadius, x, y) set aRect to current application’s NSMakeRect(x, y, theRadius, theRadius) set aCirCle to current application’s NSBezierPath’s bezierPath() aCirCle’s appendBezierPathWithOvalInRect:aRect return aCirCle end generateCircle # NSImageを指定パスにPNG形式で保存 on saveNSImageAtPathAsPNG(anImage, outPath) set imageRep to anImage’s TIFFRepresentation() set aRawimg to current application’s NSBitmapImageRep’s imageRepWithData:imageRep set pathString to current application’s NSString’s stringWithString:outPath set newPath to pathString’s stringByExpandingTildeInPath() set myNewImageData to (aRawimg’s representationUsingType:(current application’s NSPNGFileType) |properties|:(missing value)) set aRes to (myNewImageData’s writeToFile:newPath atomically:true) as boolean return aRes –成功ならtrue、失敗ならfalseが返る end saveNSImageAtPathAsPNG |
More from my site
(Visited 70 times, 1 visits today)