diff --git a/scanline/billboards_of_ny.py b/scanline/billboards_of_ny.py new file mode 100644 index 0000000..6a49d58 --- /dev/null +++ b/scanline/billboards_of_ny.py @@ -0,0 +1,51 @@ +from manim import * + +field = Rectangle(width=10.0, height=5.0) + +class Billboard(Rectangle): + + def __init__(self, x, y, w, h): + Rectangle.__init__(self, width=w, height=h) + self.x = x + self.y = y + self.w = w + self.h = h + self.align_to(field, UL) + self.shift(x*RIGHT + y*DOWN) + +class Scanline(VGroup): + + def __init__(self): + self.line = Line(field.get_top(), field.get_bottom(), color=RED).align_to(field, LEFT) + self.tops = dict() + VGroup.__init__(self) + self.add(self.line) + + def insert(self, y): + self.tops[y] = Dot().move_to(self.line.get_top()).shift(y*DOWN) + self.add(self.tops[y]) + + def delete(self, y): + self.remove(self.tops[y]) + del self.tops[y] + + +class Main(Scene): + def construct(self): + + boards = [Billboard(x, y, w, h) for x, y, w, h in [(1, 0, 3, 3), (2, 2, 5, 2)]] + self.add(*boards) + + poi = sorted([(b.x, 1, i) for i, b in enumerate(boards)] + [(b.x + b.w, -1, i) for i, b in enumerate(boards)]) + + scan = Scanline() + + for x, left, i in poi: + self.play(scan.animate.move_to(field.get_left() + x*RIGHT)) + if left == 1: + scan.insert(boards[i].y) + else: + scan.delete(boards[i].y) + + + self.wait(2)