[go: up one dir, main page]

Menu

[3ece19]: / bin / forests.scm  Maximize  Restore  History

Download this file

134 lines (120 with data), 5.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
;;;
;;; Copyright (C) 2002-2022 The FreeCol Team
;;;
;;; This file is part of FreeCol.
;;;
;;; FreeCol is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; FreeCol is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with FreeCol. If not, see <http://www.gnu.org/licenses/>.
;;;
(define half-x 64)
(define half-y 32)
(define half-width 20)
(define half-height 10)
;;; Increment a binary number represented as a list of ones and zeros,
;;; starting with the least significant bit. Return #f if the number
;;; can not be incremented without adding another bit.
(define increment
(lambda (lst)
(let loop ((remaining lst)
(result '()))
(if (null? remaining)
#f
(if (= 0 (car remaining))
(append (reverse (cons 1 result))
(cdr remaining))
(loop (cdr remaining)
(cons 0 result)))))))
;;; Calculate the point on the line defined by the given point and
;;; slope, at x0.
(define calculate-point
(lambda (point slope x0)
(let* ((x (car point))
(y (cadr point))
(b (- y (* slope x))))
(list x0 (+ (* slope x0) b)))))
(define script-fu-cut-forests
(lambda (img drawable)
(let* ((height (car (gimp-image-height img)))
(offset (- height 64))
(north
(list half-x (+ offset (- half-y half-height))))
(east
(list (+ half-x half-width) (+ offset half-y)))
(south
(list half-x (+ offset half-y half-height)))
(west
(list (- half-x half-width) (+ offset half-y)))
(north-east
(list north (calculate-point north -0.5 128)
(calculate-point east -0.5 128)))
(south-east
(list east (calculate-point east 0.5 128)
(calculate-point south 0.5 128)))
(south-west
(list south (calculate-point south -0.5 0)
(calculate-point west -0.5 0)))
(north-west
(list west (calculate-point west 0.5 0)
(calculate-point north 0.5 0) north))
(rectangles
(list north-east south-east south-west north-west)))
(let loop ((count '(1 0 0 0)))
(if count
(let* ((image (car (gimp-image-duplicate img)))
(pic-layer (car (gimp-image-get-active-drawable image)))
(vec (car (gimp-vectors-new image "points"))))
(gimp-image-undo-disable image)
(gimp-image-undo-group-start image)
(gimp-selection-none image)
(gimp-image-add-vectors image vec -1)
(let branch-loop ((branches count)
(rectangles rectangles)
(result '()))
(if (null? branches)
(let ((points
(apply append (map (lambda (n) (append n n n)) result))))
(gimp-vectors-stroke-new-from-points
vec 0 (length points) (list->vector points) TRUE))
(let ((branch (car branches))
(rectangle (car rectangles)))
(branch-loop (cdr branches)
(cdr rectangles)
(append result
(if (= 1 branch)
rectangle
(list (car rectangle))))))))
(let* ((current-name (car (gimp-image-get-filename img)))
(name (substring current-name 0 (- (string-length current-name) 4))))
(gimp-vectors-to-selection
vec
CHANNEL-OP-ADD
TRUE FALSE 0 0)
(gimp-edit-clear pic-layer)
(file-png-save-defaults
1 image pic-layer
(string-append
name
(apply string-append (map number->string count))
".png") "")
(loop (increment count)))))))))
(script-fu-register "script-fu-cut-forests"
_"Cut forests"
_"Cut forests"
"Michael Vehrs <Michael.Burschik@gmx.de>"
"Michael Vehrs"
"2012-10-27"
"RGB GRAY"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0)
(script-fu-menu-register "script-fu-cut-forests"
"<Image>/Filters")