| René Nyffenegger's collection of things on the web | |
|
René Nyffenegger on Oracle - Most wanted - Feedback
|
Script-fu example 06: Creating a function to draw lines, using it to draw stars | ||
|
Creates a 250x250 picture and draws a star into it.
Since I am going to draw several lines here, I create a function that takes care of drawing a line.
draw_line.scm
(define (draw-line layer x-from y-from x-to y-to)
(let* (
(points (cons-array 4 'double))
)
(aset points 0 x-from)
(aset points 1 y-from)
(aset points 2 x-to )
(aset points 3 y-to )
(gimp-pencil layer 4 points)
)
)
The function is then called in the following script.
ex_06.scm
(define (ex_06 nof-points jump-points)
(
(let* (
(my-image (car (gimp-image-new 250 250 RGB)))
(my-layer (car (gimp-layer-new my-image 250 250 RGB-IMAGE "my layer" 0 NORMAL)))
(i nof-points)
)
(gimp-image-add-layer my-image my-layer 0)
(gimp-context-set-background '(255 255 255))
(gimp-context-set-foreground '(000 000 000))
(gimp-drawable-fill my-layer BACKGROUND-FILL)
(gimp-brushes-set-brush "Circle (01)" )
(gimp-brush-set-spacing "Circle (01)" 100)
(while (> i 0)
(draw-line
my-layer
(+ 125 (* 100 (sin (* 2 *pi* jump-points i (/ 1 nof-points)))))
(+ 125 (* 100 (cos (* 2 *pi* jump-points i (/ 1 nof-points)))))
(+ 125 (* 100 (sin (* 2 *pi* jump-points (+ i 1) (/ 1 nof-points)))))
(+ 125 (* 100 (cos (* 2 *pi* jump-points (+ i 1) (/ 1 nof-points)))))
)
(set! i (- i 1))
)
(gimp-file-save RUN-NONINTERACTIVE my-image my-layer "c:\\temp\\ex_06.jpg" "")
)
)
)
c:\> start gimp-2.2.exe -d -i -b "(ex_06 10 3)" "(gimp-quit 0)"
See also other examples
|