![]() Then it creates a new layer and identifies it as the script's drawable. The script also needs some other parameters that it can deduce from the GIMP interface: (define (script-fu-mandelbrot image palette-name threshold domain-width domain-height offset-x offset-y) The function requires a few parameters: an image to which it will add a layer with the fractal, the palette-name identifying the color palette to be used, the threshold value to stop the iteration, the domain-width and domain-height that identify the image boundaries, and the offset-x and offset-y to center the image to the desired feature. The best practice for writing a new function is to call it script-fu-something so that it can be identified in the Procedure Browser easily. The new function is called script-fu-mandelbrot. (+ (* ax by) (* ay bx))))) Draw the fractal I used Racket's documentation as inspiration for function names and roles: (define (make-rectangular x y) (cons x y)) Then I added the few functions needed for the script. I defined the complex numbers as pairs of real numbers. Since this image is all about complex numbers, I wrote a quick and dirty implementation of complex numbers in Script-Fu. I will go through the script to show you what it does. (real-y (- (* domain-height (/ y height)) offset-y)) (let* ((real-x (- (* domain-width (/ x width)) offset-x)) (if (or (= i num-colors) (> (magnitude z′) threshold)) (define bytes-per-pixel (car (gimp-drawable-bpp drawable))) (define new-layer (car (gimp-layer-new image (define height (car (gimp-image-height image))) ![]() (define width (car (gimp-image-width image))) (define colors (cadr (gimp-palette-get-colors palette-name))) (define num-colors (car (gimp-palette-get-info palette-name))) ![]() (define (script-fu-mandelbrot image palette-name threshold domain-width domain-height offset-x offset-y) Definition of the function creating the layer and drawing the fractal (make-rectangular (- (* ax bx) (* ay by)) (make-rectangular (+ (real-part a) (real-part b)) (define (make-rectangular x y) (cons x y)) Write a file called mandelbrot.scm with: Complex numbers implementation Mine is at $HOME/.config/GIMP/2.10/scripts. You can write your first script and save it to the Scripts folder found in the preferences window under Folders → Scripts. ↳ Returns a list containing 1, 2, 3, and 5 Write the script Functions and operators are applied to a list of operands by prefixing them: (function-name operand operand. Scheme is a Lisp-like language, so a major characteristic is that it uses a prefix notation and a lot of parentheses. Finally, the Help menu offers a Procedure Browser with very extensive documentation with all of Script-Fu's functions described in detail. I also wrote an article about batch processing images using Script-Fu. If you want to get more acquainted with Scheme, GIMP's documentation offers an in-depth tutorial. It is an implementation of the Scheme programming language. Script-Fu is the scripting language built into GIMP. In other words, the color scale shows how many steps are required for the succession to pass an upper-limit value. They represent how many iterations are required for the magnitude of the succession of numbers to pass a threshold value. In reality, the Mandelbrot set is the fancy-looking black blob in the pictures the nice-looking colors are outside the set. For the more math-savvy, the Mandelbrot set is defined as the set of complex numbers a for which the successionĭoes not diverge when starting from z₀ = 0. What is the Mandelbrot set?ĭo not panic! I will not go into too much detail here. In this tutorial, you will write a script that creates a layer in an image and draws a representation of the Mandelbrot set with a colored environment around it. Free online course: RHEL technical overview.
0 Comments
Leave a Reply. |