forked from jtauber/pyifs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regenerate.py
64 lines (56 loc) · 2.29 KB
/
regenerate.py
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
import argparse
from ifsfiles import get_ifs_files
from generate import run_jobs
import pyifs
from palette import Palette
import colorsys
def adjust_saturation(g, saturation):
for (p,t) in g.ifs.transforms:
r,g,b = t.get_colour()
h,s,v = colorsys.rgb_to_hsv(r,g,b)
s = s + saturation if s + saturation < 1.0 else 1.0
r,g,b = colorsys.hsv_to_rgb(h,s,v)
t.set_colour(r,g,b)
def dump_it(g):
for w,t in g.ifs.transforms:
print repr(t)
print t.initial_params
def update_files(ifs_files, args):
palette = None
if args.palette:
palette = Palette.from_open_file(args.palette)
for ifs_file in ifs_files:
g = pyifs.Generator.from_file(ifs_file)
if args.iterations:
g.iterations = args.iterations
if args.points:
g.num_points = args.points
if args.scale:
g.scale = args.scale
if args.gamma:
g.gamma = args.gamma
if args.zoom:
g.ifs.d = args.zoom
if args.colour or palette:
g.ifs.transforms = [(p, t.get_mutated_colour(palette=palette) ) for (p,t) in g.ifs.transforms]
if args.saturation:
adjust_saturation(g, args.saturation)
f = open(ifs_file, 'w')
f.write(repr(g))
f.truncate()
f.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("gen", help="Directory or file to regenerate.")
parser.add_argument("--iterations", help="Number of iterations.", type=int)
parser.add_argument("--points", help="Number of points.", type=int)
parser.add_argument("--scale", help="Lighting scale adjustment.", type=float)
parser.add_argument("--gamma", help="Gamma adjustment.", type = float)
parser.add_argument("--zoom", help="Camera zoom - bigger numbers zoom out, default is 0.5.", type=float)
parser.add_argument("--colour", help="Mutate colours.", action="store_true")
parser.add_argument("--palette", help="Palette file.", type=file)
parser.add_argument("--saturation", help="Saturation adjustment.", type=float)
args = parser.parse_args()
ifs_files = get_ifs_files(args.gen)
update_files( ifs_files, args)
run_jobs(('pypy pyifs.py --gen %s --desc %s' % (f, f) for f in ifs_files))