summaryrefslogtreecommitdiff
path: root/alienator.scm
blob: f9d71d2d0d6f7104c2457c7894892f7869a79091 (plain)
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
; alienator.scm is a GIMP plugin that runs through a series of image files
; defined by a regex pattern, then filters those files through GIMP's alien map
; function values and writes them out to a specified directory. Once the
; conversion is finished, the plugin closes GIMP.
;
; Usage:
;
; 1.  Install to one of GIMP's plugin directories.
; 2.  Run from command line or GIMP's Scheme interpreter:
;
;   $ gimp -i -b='(alienator '/input/directory/*' '/output/directory')
;   ts> (alienator '/input/directory/*' '/output/directory')
;
; 3.  View the results and enjoy!
;
;   Copyright (c) Andrew Marchetta 2019
;
;   This program 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 3 of the License, or
;   (at your option) any later version.
;
;   This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
;

; define a function called alienator
(define (alienator glob_pattern out_directory)

    ; seed the PRNG because we get consistently boring results otherwise
    (srand (car (gettimeofday)))

    ; load in the list and start iterating over it
    (define filelist (cadr (file-glob glob_pattern 0)))
    (while (not (null? filelist))
        (define thisfile (car filelist))
        (define thisfile_basename (car (reverse (strbreakup thisfile "/"))))
        (define thisfile_imgid (car (gimp-file-load RUN-NONINTERACTIVE thisfile thisfile)))
        (define thisfile_drawable (car (gimp-image-get-active-drawable thisfile_imgid)))

        (print (cons (cons "Working on file " thisfile) " ..."))

        ; generate some random values for our parameters
        (define red_freq_floor 0.500)
        (define red_freq_ceil 1.500)
        (define red_angle_floor 25.000)
        (define red_angle_ceil 45.000)

        (define green_freq_floor 0.500)
        (define green_freq_ceil 1.500)
        (define green_angle_floor 25.000)
        (define green_angle_ceil 45.000)

        (define blue_freq_floor 0.500)
        (define blue_freq_ceil 1.500)
        (define blue_angle_floor 25.000)
        (define blue_angle_ceil 45.000)

        (define red_freq (+ (/ (random (+ (* (- red_freq_ceil red_freq_floor) 1000) 1)) 1000) red_freq_floor))
        (define green_freq (+ (/ (random (+ (* (- green_freq_ceil green_freq_floor) 1000) 1)) 1000) green_freq_floor))
        (define blue_freq (+ (/ (random (+ (* (- blue_freq_ceil blue_freq_floor) 1000) 1)) 1000) blue_freq_floor))

        (define red_angle (+ (/ (random (+ (* (- red_angle_ceil red_angle_floor) 10000) 1)) 10000) red_angle_floor))
        (define green_angle (+ (/ (random (+ (* (- green_angle_ceil green_angle_floor) 10000) 1)) 10000) green_angle_floor))
        (define blue_angle (+ (/ (random (+ (* (- blue_angle_ceil blue_angle_floor) 10000) 1)) 10000) blue_angle_floor))

        ; let's alienate our image
        (plug-in-alienmap2 RUN-NONINTERACTIVE thisfile_imgid thisfile_drawable red_freq red_angle green_freq green_angle blue_freq blue_angle 0 1 1 1)

        ; write out a new image
        (define thisfile_newout (string-append out_directory (string-append "/" thisfile_basename)))
        (print (string-append "Writing to file " thisfile_newout))
        (gimp-file-save RUN-NONINTERACTIVE thisfile_imgid thisfile_drawable thisfile_newout thisfile_newout)

        ; write a cute little log file
        (define logfile (open-output-file (string-append thisfile_newout "_alienated.log")))
        (print (cons "Alienated " (cons thisfile "!")) logfile)
        (write-char #\newline logfile)
        (print (cons "Red frequency: " red_freq) logfile)
        (write-char #\newline logfile)
        (print (cons "Green frequency: " green_freq) logfile)
        (write-char #\newline logfile)
        (print (cons "Blue frequency: " blue_freq) logfile)
        (write-char #\newline logfile)
        (print (cons "Red angle: " red_angle) logfile)
        (write-char #\newline logfile)
        (print (cons "Green angle: " green_angle) logfile)
        (write-char #\newline logfile)
        (print (cons "Blue angle: " blue_angle) logfile)
        (write-char #\newline logfile)
        (close-output-port logfile)

        ; winnow down our list because that's how scheme does loops
        (set! filelist (cdr filelist))

        ; close the while loop
        )

    ; close the program
    (gimp-quit 0)

; close the define
)