| 282 | |
| 283 | === Animation of Color and Opacity |
| 284 | As seen above, the color and opacity maps are stored in Python as lists. |
| 285 | Given a start and a end color/opacity list, it is very easy to implement a small python funtion to calculate a linear interpolation. In the following example, images for interpolated opacity values are rendered. |
| 286 | {{{ |
| 287 | #!python |
| 288 | # t: timestep, in range [0.0, 1.0] |
| 289 | def interpolate(t, list1, list2): |
| 290 | if len(list1) != len(list2): |
| 291 | return [] |
| 292 | result = [] |
| 293 | for i in range(len(list1)): |
| 294 | diff = list2[i]-list1[i] |
| 295 | result.append(list1[i] + diff*t) |
| 296 | return result |
| 297 | |
| 298 | |
| 299 | # start opacity list, t=0.0 |
| 300 | pLIPWF1 = [0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 254.0, 1.0, 0.5, 0.0] |
| 301 | #end opacity list, t=1.0 |
| 302 | pLIPWF2 = [0.0, 0.0, 0.5, 0.0, 25.0, 0.0, 0.5, 0.0, 254.0, 1.0, 0.5, 0.0] |
| 303 | |
| 304 | camera.SetPosition(0.0, 0.0, 1.488) |
| 305 | camera.SetFocalPoint(0.0, 0.0, 0.0) |
| 306 | camera.SetViewUp(-1.0, 0.0, 0.0) |
| 307 | imageNum = 0 |
| 308 | |
| 309 | for i in range(30): |
| 310 | pLIPWF.Points = interpolate (i/29.0, pLIPWF1, pLIPWF2) |
| 311 | print ("opacity interpolation: rendering image %04d" % (imageNum)) |
| 312 | Render() |
| 313 | WriteImage("opacity_image_%04d.png" % (imageNum)) |
| 314 | imageNum = imageNum + 1 |
| 315 | |
| 316 | }}} |
| 317 | Resulting movie snippet: |
| 318 | [raw-attachment:opacity.wmv Animation of opacity] |
| 319 | |