|
| 1 | +from compas.geometry import Box |
| 2 | +from compas_viewer import Viewer |
| 3 | +from compas.colors import Color |
| 4 | + |
| 5 | +viewer = Viewer() |
| 6 | + |
| 7 | +boxes = [ |
| 8 | + Box.from_width_height_depth(1, 1, 1), |
| 9 | + Box.from_width_height_depth(2, 2, 0.5), |
| 10 | + Box.from_width_height_depth(3, 3, 0.2), |
| 11 | +] |
| 12 | + |
| 13 | +obj1 = viewer.scene.add(boxes[0], facecolor=Color.blue()) |
| 14 | + |
| 15 | +objects_to_remove = [obj1] |
| 16 | + |
| 17 | + |
| 18 | +@viewer.on(interval=1000) |
| 19 | +def dynamic_update(frame): |
| 20 | + """ |
| 21 | + This function is called every 1000ms for 6 frames. |
| 22 | + """ |
| 23 | + print(f"Frame {frame}") |
| 24 | + |
| 25 | + if frame == 1: |
| 26 | + print("Adding second box...") |
| 27 | + added_object = viewer.scene.add(boxes[1], facecolor=Color.red()) |
| 28 | + objects_to_remove.append(added_object) |
| 29 | + |
| 30 | + if frame == 2: |
| 31 | + print("Adding third box...") |
| 32 | + added_object = viewer.scene.add(boxes[2], facecolor=Color.green()) |
| 33 | + objects_to_remove.append(added_object) |
| 34 | + |
| 35 | + if frame == 4: |
| 36 | + print("Removing first box...") |
| 37 | + viewer.scene.remove(objects_to_remove.pop(-1)) |
| 38 | + |
| 39 | + if frame == 5: |
| 40 | + print("Removing second box...") |
| 41 | + viewer.scene.remove(objects_to_remove.pop(-1)) |
| 42 | + |
| 43 | + if frame == 6: |
| 44 | + print("Removing third box...") |
| 45 | + viewer.scene.remove(objects_to_remove.pop(-1)) |
| 46 | + |
| 47 | +viewer.show() |
0 commit comments