メキシカンハットの描画AppleScriptのedama2さんバージョンで、さらに多色対応したものです。
AppleScript名:メキシカンハット v3a.scptd |
— Created 2024-06-28 by Takaaki Naganoya — Modified 2024-07-09 by Edama2 use AppleScript version "2.5" use scripting additions use framework "Foundation" use framework "AppKit" use mLib : script "calcLibAS" use imgDispLib : script "imageDisplayLib" on run my main() end run on main() (* set userReply to display dialog "拡大率を入力してください(1-8)" default answer "3" set aScale to userReply’s text returned as number if aScale < 1 or 8 < aScale then return beep *) set aScale to 3 –描画 set listBezierPaths to {} repeat 3 times set listBezierPaths’s end to current application’s NSBezierPath’s bezierPath() end repeat –https://x.com/yone/status/1805552100400939161 set D to {} set dR to pi / 180 repeat 255 times set end of D to 192 end repeat repeat with y from -120 to 120 by 4 if y < 0 then set rY to -60 else set rY to 60 end if repeat with x from -180 to 180 by 4 if (x < -60) then set rX to -120 else if (x < 60) then set rX to 0 else set rX to 120 end if set rR to (x – rX) ^ 2 + (y – rY) ^ 2 set z to 180 * (exp (rR / -800)) set sX to floor (128 + x / 2 – y / 4) set sY to floor (128 – y / 4 – z / 2) if not (sX < 0 or 256 ≤ sX) then if not ((D’s item (sX + 1)) ≤ sY) then set zz to (floor (z * 0.0389)) + 1 log result set idRect to current application’s NSMakeRect(sX * aScale, sY * aScale, aScale, aScale) if ((zz = 1) or (zz = 3) or (zz = 5) or (zz = 7)) then (listBezierPaths’s item 1’s appendBezierPathWithRect:idRect) end if if ((zz = 2) or (zz = 3) or (zz ≥ 6)) then (listBezierPaths’s item 2’s appendBezierPathWithRect:idRect) end if if (zz ≥ 4) then (listBezierPaths’s item 3’s appendBezierPathWithRect:idRect) end if set (D’s item (sX + 1)) to sY end if end if end repeat end repeat # set srcWidth to 0 set srcHeight to 0 repeat with idBezierPath in listBezierPaths set tmpWidth to current application’s NSMaxX(idBezierPath’s |bounds|()) set tmpHeight to current application’s NSMaxY(idBezierPath’s |bounds|()) if srcWidth < tmpWidth then set srcWidth to tmpWidth if srcHeight < tmpHeight then set srcHeight to tmpHeight end repeat # set srcSize to current application’s NSMakeSize(srcWidth, srcHeight) log result set srcImage to current application’s NSImage’s alloc()’s initWithSize:srcSize set operation to current application’s NSCompositingOperationScreen –>set operation to current application’s NSCompositingOperationSourceOver repeat with num from 1 to count listBezierPaths if num is 1 then set idColor to current application’s NSColor’s blueColor() else if num is 2 then set idColor to current application’s NSColor’s redColor() else if num is 3 then set idColor to current application’s NSColor’s greenColor() end if tell srcImage lockFocus() tell current application’s NSImage’s alloc() tell initWithSize_(srcSize) lockFocus() idColor’s setFill() listBezierPaths’s item num’s fill() unlockFocus() (its drawAtPoint:(current application’s NSZeroPoint) fromRect:(current application’s NSZeroRect) operation:operation fraction:1.0) end tell end tell unlockFocus() end tell end repeat # 反転して合成 set dstImage to current application’s NSImage’s alloc()’s initWithSize:srcSize tell dstImage lockFocus() current application’s NSColor’s blackColor()’s setFill() current application’s NSRectFill(current application’s NSMakeRect(0, 0, its |size|()’s width, its |size|()’s height)) set xform to current application’s NSAffineTransform’s transform() xform’s translateXBy:0.0 yBy:(its |size|()’s height) xform’s scaleXBy:1.0 yBy:-1.0 xform’s concat() srcImage’s drawInRect:(current application’s NSMakeRect(0, 0, its |size|()’s width, its |size|()’s height)) unlockFocus() end tell –結果表示 dispImage(dstImage, "Mexican Hat") of imgDispLib end main |
More from my site
(Visited 12 times, 1 visits today)