Last active
August 9, 2024 11:06
-
-
Save uwezi/694ceda948428225b483d1ec5dbed748 to your computer and use it in GitHub Desktop.
[Displaying dynamic coordinates] Displaying x,y coordinates from value trackers. #manim #decimalnumber #coordinates #animation #valuetracker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://discord.com/channels/581738731934056449/1271400215525724162/1271400215525724162 | |
| from manim import * | |
| class coordNumber(Scene): | |
| def construct(self): | |
| ax = NumberPlane().add_coordinates() | |
| self.add(ax) | |
| x = ValueTracker(1) | |
| y = ValueTracker(1) | |
| cdisp = always_redraw(lambda: | |
| VGroup( | |
| Text("("), | |
| DecimalNumber(number=x.get_value(),), | |
| VGroup( | |
| Text(",)")[0], | |
| Rectangle(width=0.2,height=0.5).set_opacity(0), | |
| ), | |
| DecimalNumber(number=y.get_value()), | |
| Text(")"), | |
| ).arrange(RIGHT,buff=0.1).to_corner(UR).add_background_rectangle() | |
| ) | |
| dot = always_redraw(lambda: | |
| Dot(point=ax.c2p(x.get_value(),y.get_value()), color=YELLOW) | |
| ) | |
| self.add(cdisp,dot) | |
| self.wait() | |
| for _ in range(5): | |
| self.play( | |
| x.animate.set_value(np.random.uniform(-6,6)), | |
| y.animate.set_value(np.random.uniform(-3,3)) | |
| ) | |
| self.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
