メキシカンハットの描画AppleScriptの、edama2さんバージョンです。
AppleScript名:メキシカンハット v3.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 idBezierPath to current application’s NSBezierPath’s bezierPath() –https://x.com/Stosstruppe/status/1279774386396880897 set dT to {} set dB to {} repeat 256 times set dT’s end to 192 end repeat repeat 256 times set dB’s end to -1 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 cX to floor (128 + x / 2 – y / 4) set cY to floor (128 – y / 4 – z / 2) if not (cX < 0 or 256 ≤ cX) then set pSet to false if ((dT’s item (cX + 1)) > cY) then set (dT’s item (cX + 1)) to cY set pSet to true end if if ((dB’s item (cX + 1)) < cY) then set dB’s item (cX + 1) to cY set pSet to true end if if pSet then set idRect to current application’s NSMakeRect(cX * aScale, cY * aScale, aScale, aScale) (idBezierPath’s appendBezierPathWithRect:idRect) end if end if end repeat end repeat log idBezierPath’s |bounds|() set srcWidth to current application’s NSMaxX(idBezierPath’s |bounds|()) set srcHeight to current application’s NSMaxY(idBezierPath’s |bounds|()) set srcSize to current application’s NSMakeSize(srcWidth, srcHeight) log result –set idColor to current application’s NSColor’s blueColor() –set idColor to current application’s NSColor’s redColor() set idColor to current application’s NSColor’s greenColor() tell current application’s NSImage’s alloc() tell initWithSize_(srcSize) lockFocus() idColor’s setFill() idBezierPath’s fill() unlockFocus() set srcImage to it end tell end tell # 反転して合成 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 1 times, 1 visits today)