Skip to content

Commit 9938bf5

Browse files
RobinPHMrDiver
andauthored
Added grid_lines attribute to Rectangle to add individual styling to the grid lines (#3428)
* Added 'grid_line_stroke_width' parameter in Rectangle * Added 'grid_lines' (VGroup) attribute to 'Rectangle' class --------- Co-authored-by: Tristan Schulz <[email protected]>
1 parent 0a24cad commit 9938bf5

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

manim/mobject/geometry/polygram.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,10 @@ class RectangleExample(Scene):
598598
def construct(self):
599599
rect1 = Rectangle(width=4.0, height=2.0, grid_xstep=1.0, grid_ystep=0.5)
600600
rect2 = Rectangle(width=1.0, height=4.0)
601+
rect3 = Rectangle(width=2.0, height=2.0, grid_xstep=1.0, grid_ystep=1.0)
602+
rect3.grid_lines.set_stroke(width=1)
601603
602-
rects = Group(rect1,rect2).arrange(buff=1)
604+
rects = Group(rect1, rect2, rect3).arrange(buff=1)
603605
self.add(rects)
604606
"""
605607

@@ -618,6 +620,8 @@ def __init__(
618620
self.stretch_to_fit_width(width)
619621
self.stretch_to_fit_height(height)
620622
v = self.get_vertices()
623+
self.grid_lines = VGroup()
624+
621625
if grid_xstep is not None:
622626
from manim.mobject.geometry.line import Line
623627

@@ -633,7 +637,7 @@ def __init__(
633637
for i in range(1, count)
634638
)
635639
)
636-
self.add(grid)
640+
self.grid_lines.add(grid)
637641
if grid_ystep is not None:
638642
grid_ystep = abs(grid_ystep)
639643
count = int(height / grid_ystep)
@@ -647,7 +651,10 @@ def __init__(
647651
for i in range(1, count)
648652
)
649653
)
650-
self.add(grid)
654+
self.grid_lines.add(grid)
655+
656+
if self.grid_lines:
657+
self.add(self.grid_lines)
651658

652659

653660
class Square(Rectangle):

0 commit comments

Comments
 (0)