Applescript to create Mandlebrot set

Discuss and share Pixelmator Pro resources such as templates, mockups, and tutorials.
User avatar

2023-09-13 19:01:01

Someone will get a kick out of this script to fill your image with the Mandlebrot set. It runs very slow, but the result is fun to see it actually works.
set MAX_ITER to 20
set RGB to 257

tell application "Pixelmator Pro"
	activate
	
	tell the front document
		set maxPixX to width
		set maxPixY to height
		repeat with ypixel from 1 to maxPixY
			repeat with xpixel from 1 to maxPixX
				set x0 to -2.0 + (xpixel * (2.47 / maxPixX))
				set y0 to -1.12 + (ypixel * (2.24 / maxPixY))
				set x to 0.0
				set y to 0.0
				set iteration to 0
				repeat while (x * x + y * y ≤ 2 * 2 and iteration < MAX_ITER)
					set xtemp to x * x - y * y + x0
					set y to 2 * x * y + y0
					set x to xtemp
					set iteration to iteration + 1
				end repeat
				
				set colorThres to 13
				set colorThres2 to 17
				
				if (iteration > colorThres and iteration < colorThres2) then
					draw selection bounds {xpixel, ypixel, 1, 1}
					convert selection into shape
					
					set colorSize to iteration - colorThres
					set colorPick to 255 - (colorSize * (255 / (MAX_ITER - colorThres)))
					tell the styles of layer 1
						set its fill color to {colorPick * RGB, colorPick * RGB, colorPick * RGB}
					end tell
				end if
			end repeat # Each Row merge to prevent too many layers!!!!
			merge visible
		end repeat # Merge it all when done!
		merge visible
	end tell
end tell

User avatar

2023-09-18 14:57:02

@ShaTi; that is a marvelous thing to behold. I made the mistake of making the initial blank image too large; it was very slow. Gave up on that and reduced to small 150x150 ran very quickly but pixel density was lacking. Settled on 3x3 inches with 600 ppi for the following image that took about 22 minutes with fewer gaps. Interesting stuff; I was confused to end with only a single layer till I saw all the merges.

Image
User avatar

2023-09-19 20:46:36

Glad you enjoyed it :)

Just need a way to quickly set a pixel color to make this very fast:
Pixelmator team can you add something like:
set pixel color {xpixel, ypixel, colorPick * RGB, colorPick * RGB, colorPick * RGB}

Then the merges could be removed and the runtime for this would be very fast.