Sideway
output.to from Sideway
Draft for Information Only

Content

Value Tracker
 Class ValueTracker(Mobject)
  Example
   Code
   Output
 Class ExponentialValueTracker(ValueTracker)
  Example
   Code
   Output
 Class ComplexValueTracker(ValueTracker)
  Example
   Code
   Output

Value Tracker

The defined value tracker VMobject in value_tracker.py
  • Class ValueTracker(Mobject)
  • Class ExponentialValueTracker(ValueTracker)
  • Class ComplexValueTracker(ValueTracker)

Class ValueTracker(Mobject)

ValueTracker is used to generate a value tracker Mobject for given parameters.

Example

Code

# folder/file: tut/manim_mobject_valuetracker_001a.py

import numpy as np
from manimlib.scene.scene import Scene
from manimlib.mobject.value_tracker import ValueTracker
from manimlib.mobject.geometry import Dot, Line
from manimlib.mobject.number_line import NumberLine
from manimlib.mobject.svg.tex_mobject import TexMobject
from manimlib.mobject.numbers import DecimalNumber, Integer

class manim_mobject_valuetracker_001a(Scene):
    def construct(self):
        def linear(t): return t
        def v_tracker(obj):
            obj.set_value(v.get_value())
            obj.set_x(v.get_value()-7)
        v=ValueTracker(1)
        self.add(NumberLine(x_min=-6,x_max=6).move_to([0,-1.5,0]))
        dotv = Dot().add_updater(lambda i: i.set_x(v.get_value()-7))
        self.add(dotv.move_to([-4,-1.5,0]))
        textv = DecimalNumber(v.get_value()).add_updater(v_tracker)
        self.add(textv.move_to([-4,-2.5,0]))
        self.play(v.set_value,13,rate_func=linear,run_time=2)
        self.wait()
        value1=ValueTracker(0.0000001)
        text1 = DecimalNumber(value1.get_value(),num_decimal_places=5).add_updater(lambda x: x.set_value(value1.get_value())).move_to([-3,3,0])
        self.add(text1)
        self.play(value1.set_value,1,run_time=2)
        self.wait()
        text2 = DecimalNumber(value1.get_value(),num_decimal_places=5)
        self.add(text2.move_to([3,3,0]))
        def update_text(obj):
            obj.set_value(np.cos(value1.get_value()))
        text2.add_updater(update_text)
        self.play(value1.set_value,0.0000001,run_time=2)
        self.wait()
        def update_tracker(obj,obj1):
            dx=x.get_value()-update_tracker.x
            obj.increment_value(-dx),
            if (x.get_value()**2+y.get_value()**2+z.get_value()**2) > 1 :
                obj.increment_value(dx)             
            update_tracker.x=x.get_value()
            z.set_value((1-x.get_value()**2-y.get_value()**2)**0.5)
            return obj.get_value()
        x=ValueTracker(1)
        update_tracker.x=x.get_value()
        y=ValueTracker(0)
        z=ValueTracker(0)
        self.add(Line((0,0,0)).move_to([-3.5,1.5,0]))
        dot1 = Dot().add_updater(lambda i: i.set_x(x.get_value()-4))
        self.add(dot1.move_to([-4,1.5,0]))
        self.add(Line((0,0,0)).move_to([-3.5,1,0]))
        dot2 = Dot().add_updater(lambda i: i.set_x(y.get_value()-4))
        self.add(dot2.move_to([-4-1,1,0]))
        self.add(Line((0,0,0)).move_to([-3.5,0.5,0]))
        dot3 = Dot().add_updater(lambda i: i.set_x(z.get_value()-4))
        self.add(dot3.move_to([-4-1,0.5,0]))
        def update_texty(obj):
            obj.set_value(update_tracker(y,x))
        textx = DecimalNumber(x.get_value(),num_decimal_places=5).add_updater(lambda i: i.set_value(x.get_value()))
        self.add(textx.move_to([-4+2,1.5,0]))
        texty = DecimalNumber(y.get_value(),num_decimal_places=5).add_updater(update_texty)
        self.add(texty.move_to([-4+2,1,0]))
        textz = DecimalNumber(z.get_value(),num_decimal_places=5).add_updater(lambda i: i.set_value(z.get_value()))
        self.add(textz.move_to([-4+2,0.5,0]))
        total = DecimalNumber(1,num_decimal_places=22).add_updater(lambda i: i.set_value((x.get_value()**2+y.get_value()**2+z.get_value()**2)))
        self.add(total.next_to(texty,buff=0.7))
        self.play(x.set_value,0.0000001,run_time=2)
        self.wait()

Output

image

Class ExponentialValueTracker(ValueTracker)

ExponentialValueTracker is used to generate a exponential value tracker Mobject for given parameters.

Example

Code

# folder/file: tut/manim_mobject_ExponentialValueTracker_001a.py

import numpy as np
from manimlib.scene.scene import Scene
from manimlib.mobject.value_tracker import ExponentialValueTracker
from manimlib.mobject.geometry import Dot, Line
from manimlib.mobject.number_line import NumberLine
from manimlib.mobject.svg.tex_mobject import TexMobject
from manimlib.mobject.numbers import DecimalNumber, Integer

class manim_mobject_ExponentialValueTracker_001a(Scene):
    def construct(self):
        def linear(t): return t
        def e_tracker(obj):
            obj.set_value(e.get_value())
            obj.set_x(e.get_value()-7)
            textv.set_x(np.log(e.get_value())*12/np.log(13)-6)
        e=ExponentialValueTracker(1)
        self.add(NumberLine(x_min=-6,x_max=6).move_to([0,-1.5,0]))
        dotv = Dot(radius=0.15,color="#FF3300").add_updater(lambda i: i.set_x(np.log(e.get_value())*12/np.log(13)-6))
        self.add(dotv.move_to([-4,-1.5,0]))
        textv = DecimalNumber(e.get_value()).add_updater(lambda i: i.set_value(np.log(e.get_value())*12/np.log(13)+1))
        self.add(textv.move_to([-4,-0.5,0]))
        dote = Dot().add_updater(lambda i: i.set_x(e.get_value()-7))
        self.add(dote.move_to([-4,-1.5,0]))
        texte = DecimalNumber(e.get_value()).add_updater(e_tracker)
        self.add(texte.move_to([-4,-2.5,0]))
        self.play(e.set_value,13,rate_func=linear,run_time=2)
        self.wait()
        value1=ExponentialValueTracker(0.0000001)
        text1 = DecimalNumber(value1.get_value(),num_decimal_places=5).add_updater(lambda x: x.set_value(value1.get_value())).move_to([-3,3,0])
        self.add(text1)
        self.play(value1.set_value,1,run_time=2)
        self.wait()
        text2 = DecimalNumber(value1.get_value(),num_decimal_places=5)
        self.add(text2.move_to([3,3,0]))
        def update_text(obj):
            obj.set_value(np.cos(value1.get_value()))
        text2.add_updater(update_text)
        self.play(value1.set_value,0.0000001,run_time=2)
        self.wait()
        def update_tracker(obj,obj1):
            dx=x.get_value()-update_tracker.x
            obj.increment_value(-dx),
            if (x.get_value()**2+y.get_value()**2+z.get_value()**2) > 1 :
                obj.increment_value(dx)             
            update_tracker.x=x.get_value()
            z.set_value((1-x.get_value()**2-y.get_value()**2)**0.5)
            return obj.get_value()
        x=ExponentialValueTracker(1)
        update_tracker.x=x.get_value()
        y=ExponentialValueTracker(0)
        z=ExponentialValueTracker(0)
        self.add(Line((0,0,0)).move_to([-3.5,1.5,0]))
        dot1 = Dot().add_updater(lambda i: i.set_x(x.get_value()-4))
        self.add(dot1.move_to([-4,1.5,0]))
        self.add(Line((0,0,0)).move_to([-3.5,1,0]))
        dot2 = Dot().add_updater(lambda i: i.set_x(y.get_value()-4))
        self.add(dot2.move_to([-4-1,1,0]))
        self.add(Line((0,0,0)).move_to([-3.5,0.5,0]))
        dot3 = Dot().add_updater(lambda i: i.set_x(z.get_value()-4))
        self.add(dot3.move_to([-4-1,0.5,0]))
        def update_texty(obj):
            obj.set_value(update_tracker(y,x))
        textx = DecimalNumber(x.get_value(),num_decimal_places=5).add_updater(lambda i: i.set_value(x.get_value()))
        self.add(textx.move_to([-4+2,1.5,0]))
        texty = DecimalNumber(y.get_value(),num_decimal_places=5).add_updater(update_texty)
        self.add(texty.move_to([-4+2,1,0]))
        textz = DecimalNumber(z.get_value(),num_decimal_places=5).add_updater(lambda i: i.set_value(z.get_value()))
        self.add(textz.move_to([-4+2,0.5,0]))
        total = DecimalNumber(1,num_decimal_places=22).add_updater(lambda i: i.set_value((x.get_value()**2+y.get_value()**2+z.get_value()**2)))
        self.add(total.next_to(texty,buff=0.7))
        self.play(x.set_value,0.0000001,run_time=2)
        self.wait()

Output

image

Class ComplexValueTracker(ValueTracker)

ComplexValueTracker is used to generate a complex value tracker Mobject for given parameters.

Example

Code

# folder/file: tut/manim_mobject_ComplexValueTracker_001a.py

import numpy as np
from manimlib.scene.scene import Scene
from manimlib.mobject.value_tracker import ComplexValueTracker, ValueTracker
from manimlib.mobject.geometry import Dot, Line, Circle
from manimlib.mobject.number_line import NumberLine
from manimlib.mobject.svg.tex_mobject import TexMobject
from manimlib.mobject.numbers import DecimalNumber, Integer

class manim_mobject_ComplexValueTracker_001a(Scene):
    def construct(self):
        def linear(t): return t
        def v_tracker(obj):
            obj.set_value(v.get_value())
            p_tracker(obj)
        def p_tracker(obj):
            obj.set_x(v.get_value().real)
            obj.set_y(v.get_value().imag)
        v=ComplexValueTracker(complex(5.5,3.5))
        self.add(NumberLine(x_min=-6,x_max=6))
        self.add(NumberLine(x_min=-4,x_max=4).rotate(1.5708))
        dotv = Dot(color="#FF3300").add_updater(p_tracker)
        self.add(dotv.move_to([5.5,3.5,0]))
        textv = DecimalNumber(v.get_value()).add_updater(v_tracker)
        self.add(textv.move_to([5.5,3.5,0]))
        self.play(v.set_value,complex(-5.5,-3.5),rate_func=linear,run_time=2)
        self.wait()
        def s_tracker(obj):
            obj.set_value(np.abs(s.get_value())**0.5)
            obj.set_y(np.abs(s.get_value())**0.5)
        s=ComplexValueTracker(complex(5.5,3.5))
        dots = Dot(color="#FF3300").add_updater(lambda x: x.set_y(np.abs(s.get_value())**0.5))
        self.add(dots.move_to([0,0,0]))
        texts = DecimalNumber(s.get_value()).add_updater(s_tracker)
        self.add(texts.next_to(dots,buff=1))
        self.play(s.set_value,complex(-3.5,-3.5),rate_func=linear,run_time=2)
        self.wait()
        s.set_value(complex(5.5,3.5))
        circle1=Circle()
        self.add(circle1)        
        circle1.i=circle1.copy()
        def a_tracker(obj):
            obj.become(Circle())
            obj.scale(np.abs(s.get_value())**0.5)
        circle1.add_updater(a_tracker)
        self.add(circle1)
        self.play(s.set_value,complex(-3.5,-3.5),rate_func=linear,run_time=2)
        self.wait()
        i=ComplexValueTracker(complex(5.5,3.5))
        circle1=Circle()
        self.add(circle1)        
        circle1.i=circle1.copy()
        def i_tracker(obj):
            obj.become(Circle())
            obj.scale(i.get_value().real)
        circle1.add_updater(i_tracker)
        self.add(circle1)
        self.play(i.set_value,complex(-3.5,-3.5),rate_func=linear,run_time=2)
        self.wait()

Output

image

©sideway

ID: 200600602 Last Updated: 6/6/2020 Revision: 0


Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339new

Travel 7new

Reference 79

Computer

Hardware 251

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 431

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Set 1

Logic 1

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019