MCPcopy Create free account
hub / github.com/acm-clan/algorithm-stone / construct

Method construct

animations/measure_scene.py:4–47  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2
3class MeasureScene(AlgoScene):
4 def construct(self):
5 shape = self.camera.frame.get_shape()
6
7 font_size = 30
8
9 t = Text("1 width %.2f height %.2f delta 0.00"%(shape[0], shape[1]), color=GREEN, font_size=font_size).shift(LEFT*3)
10 self.add(t)
11
12 hw = shape[0]/2
13 hh = shape[1]/2
14
15 left = Line(start=LEFT*hw+UP*hh, end=LEFT*hw+DOWN*hh, color=BLUE)
16 right = Line(start=RIGHT*hw+UP*hh, end=RIGHT*hw+DOWN*hh, color=BLUE_A)
17 top = Line(start=LEFT*hw+UP*hh, end=RIGHT*hw+UP*hh, color=BLUE_B)
18 bottom = Line(start=LEFT*hw+DOWN*hh, end=RIGHT*hw+DOWN*hh, color=BLUE_C)
19
20 horizon = Line(start=LEFT*shape[0]/2, end=RIGHT*shape[0]/2, color=RED)
21 verticle = Line(start=UP*shape[1]/2, end=DOWN*shape[1]/2, color=YELLOW)
22 self.play(ShowCreation(horizon), ShowCreation(verticle), ShowCreation(left),
23 ShowCreation(right), ShowCreation(top), ShowCreation(bottom))
24
25 t.next_to(horizon, direction=UP, buff=0)
26
27 count = 2
28 delta = 0.0
29 lastcentery = t.get_center()[1]
30 print("center:", t.get_center())
31 while True:
32 nt = Text("%d width %.2f height %.2f delta %.2f"%(count, shape[0], shape[1], delta),
33 color=GREEN, font_size=font_size).shift(LEFT*3)
34 nt.next_to(t, direction=UP, buff=0)
35 p = nt.get_center()
36 print("center:", p)
37 delta = p[1] - lastcentery
38 t = nt
39 lastcentery = p[1]
40 if p[1] > shape[1]/2:
41 break
42 count += 1
43 self.play(ShowCreation(nt))
44
45 self.camera.frame.shift(OUT*10)
46 self.snapshot()
47 self.wait()
48
49
50class MeasureScene2(AlgoScene):

Callers

nothing calls this directly

Calls 3

printFunction · 0.85
snapshotMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected