-
Notifications
You must be signed in to change notification settings - Fork 1
/
scene8_anim.py
executable file
·98 lines (78 loc) · 2.84 KB
/
scene8_anim.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
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
#!/usr/bin/env python3
# vim: set fileencoding=utf-8
#
# (C) Copyright 2018, 2021 Pavel Tisnovsky
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Pavel Tisnovsky
#
"""Blobs/metaballs, vytvoření animované sekvence snímků."""
from vapory import *
from math import *
class Blob(POVRayElement):
"""Blob()"""
# často používané vektory
x = (1, 0, 0)
y = (0, 1, 0)
z = (0, 0, 1)
# vytvoření kamery ve scéně
camera = Camera('orthographic',
'location', (0, 0, -1),
'right', '5*4/3*x',
'up', 'y*5',
'look_at', (0, 0, 0))
# dva světelné zdroje
light1 = LightSource((2, 10, -10),
'color', (0.7, 0.7, 0.7))
light2 = LightSource((0, 0, -10000),
'color', (0.7, 0.7, 0.7),
'shadowless')
# objekt - nekonečná rovina
plane = Plane(z,
2,
'hollow', 'on',
Texture(
Pigment('agate',
'agate_turb', 0.9),
Finish('ambient', 0.1,
'diffuse', 0.4)))
def new_blob(threshold, dx, dy, t):
"""Vytvoření nového objektu ve scéně."""
delta = 0.3 * sin(2*pi*t)
return Blob('threshold', threshold,
'component', 1.0, 1.0, (0, -0.5 - delta, 0),
'component', 1.0, 1.0, (0, 0.5 + delta, 0),
Texture(
Pigment('color', (0.6, 0.8, 1.0)),
Finish('ambient', 0.2,
'diffuse', 0.4,
'phong', 0.5,
'phong_size', 5)),
'translate', (dx, dy, 0))
def construct_scene(t):
"""Funkce volaná pro vytvoření každého snímku v animaci."""
objects = [light1, light2, plane]
objects.append(new_blob(0.40, -2.00, -1.2, t))
objects.append(new_blob(0.50, -0.65, -1.2, t))
objects.append(new_blob(0.60, 0.65, -1.2, t))
objects.append(new_blob(0.70, 2.00, -1.2, t))
objects.append(new_blob(0.75, -2.00, 1.2, t))
objects.append(new_blob(0.80, -0.65, 1.2, t))
objects.append(new_blob(0.82, 0.65, 1.2, t))
objects.append(new_blob(0.90, 2.00, 1.2, t))
# složení scény z jednotlivých objektů
return Scene(camera, objects=objects,
included=('colors.inc',),
global_settings=('assumed_gamma 2.2',))
# parametry pro animaci
FRAMES = 200
for frame in range(0, FRAMES):
t = frame / float(FRAMES)
scene = construct_scene(t)
filename = "frame_{:03d}.png".format(frame)
scene.render(filename, width=400, height=300, auto_camera_angle=False)