From 5e11f004a4602e8513ffd4bd4cb3201b55007db7 Mon Sep 17 00:00:00 2001 From: Licini Date: Thu, 25 Aug 2022 19:37:53 +0200 Subject: [PATCH 1/2] solar example --- scripts/v120_solar.py | 67 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 scripts/v120_solar.py diff --git a/scripts/v120_solar.py b/scripts/v120_solar.py new file mode 100644 index 000000000..2c2d100a5 --- /dev/null +++ b/scripts/v120_solar.py @@ -0,0 +1,67 @@ +from math import radians +from unicodedata import name +from compas_view2.app import App +from compas.geometry import Sphere, Circle, Plane, Point +from compas.colors import Color + +Sun = Sphere([0, 0, 0], radius=1) +EarthOrbit = Circle(Plane([0, 0, 0], [0, 0, 1]), radius=10) +EarthLocator = Point(0, 0, 0) + +EarthContainer = Point(0, 0, 0) +Earth = Sphere([0, 0, 0], radius=0.5) +MoonOrbitContainer = Point(0, 0, 0) +MoonOrbit = Circle(Plane([0, 0, 0], [0, 0, 1]), radius=4) +MoonLocator = Point(0, 0, 0) +MoonContainer = Point(0, 0, 0) +Moon = Sphere([0, 0, 0], radius=0.25) + + +viewer = App(show_grid=False, enable_sceneform=True) + +SunObj = viewer.add(Sun, facecolor=Color.red(), name="Sun") +EarthOrbitObj = viewer.add(EarthOrbit, u=100, name="EarthOrbit") +EarthLocatorObj = EarthOrbitObj.add(EarthLocator, name="EarthLocator") +EarthLocatorObj.translation = [10, 0, 0] + +EarthContainerObj = viewer.add(EarthContainer, name="EarthContainer") +EarthContainerObj.rotation = [0, -radians(15), 0] +EarthObj = EarthContainerObj.add(Earth, facecolor=Color.blue(), name="Earth") + +MoonOrbitContainerObj = viewer.add(MoonOrbitContainer, name="MoonOrbitContainer") +MoonOrbitContainerObj.rotation = [0, radians(15), 0] + +MoonOrbitObj = MoonOrbitContainerObj.add(MoonOrbit, u=100, name="MoonOrbit") +MoonLocatorObj = MoonOrbitObj.add(MoonLocator, name="MoonLocator") +MoonLocatorObj.translation = [4, 0, 0] +MoonContainerObj = viewer.add(MoonContainer, name="MoonContainer") +MoonContainerObj.rotation = [0, -radians(15), 0] +MoonObj = MoonContainerObj.add(Moon, facecolor=Color.white(), name="Moon") + + +@viewer.on(interval=0.05) +def orbit(frame): + + SunObj.rotation = [0, 0, -radians(frame)/5] + SunObj._update_matrix() + + EarthOrbitObj.rotation = [0, 0, radians(frame)/5] + EarthOrbitObj._update_matrix() + + EarthContainerObj.translation = EarthLocatorObj.transformation_world.translation_vector + EarthContainerObj._update_matrix() + EarthObj.rotation = [0, 0, -radians(frame)/2] + EarthObj._update_matrix() + + MoonOrbitContainerObj.translation = EarthLocatorObj.transformation_world.translation_vector + MoonOrbitContainerObj._update_matrix() + MoonOrbitObj.rotation = [0, 0, radians(frame)/2] + MoonOrbitObj._update_matrix() + + MoonContainerObj.translation = MoonLocatorObj.transformation_world.translation_vector + MoonContainerObj._update_matrix() + MoonObj.rotation = [0, 0, -radians(frame)/2] + MoonObj._update_matrix() + + +viewer.show() From 1f9ac52ef0411ee30a27158010214a979375cc9c Mon Sep 17 00:00:00 2001 From: Licini Date: Thu, 25 Aug 2022 19:38:45 +0200 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51cfd1380..1a6ab3502 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased ### Added + * Added `RobotObject`. +* Added `v120_solar.py` example script. ### Changed