ScreenGrid object has no attribute 'rows' #1575
Answered
by
TonyCrane
Peter-Fayez95
asked this question in
Q&A
-
When trying the example written by Theorem of Beethoven (related to grids and point positions), it gives the following error message: AttributeError: ScreenGrid object has no attribute 'rows' from manim import *
class Grid(VGroup):
CONFIG = {
"height": 6.0,
"width": 6.0,
}
def __init__(self, rows, columns, **kwargs):
digest_config(self, kwargs, locals())
super().__init__(**kwargs)
x_step = self.width / self.columns
y_step = self.height / self.rows
for x in np.arange(0, self.width + x_step, x_step):
self.add(Line(
[x - self.width / 2., -self.height / 2., 0],
[x - self.width / 2., self.height / 2., 0],
))
for y in np.arange(0, self.height + y_step, y_step):
self.add(Line(
[-self.width / 2., y - self.height / 2., 0],
[self.width / 2., y - self.height / 2., 0]
))
class ScreenGrid(VGroup):
CONFIG = {
"rows": 8,
"columns": 14,
"height": config.frame_height,
"width": 14,
"grid_stroke": 0.5,
"grid_color": WHITE,
"axis_color": RED,
"axis_stroke": 2,
"labels_scale": 0.25,
"labels_buff": 0,
"number_decimals": 2
}
def __init__(self, **kwargs):
super().__init__(**kwargs)
rows = self.rows
columns = self.columns
grid = Grid(width=self.width, height=self.height, rows=rows, columns=columns)
grid.set_stroke(self.grid_color, self.grid_stroke)
vector_ii = ORIGIN + np.array((- self.width / 2, - self.height / 2, 0))
vector_si = ORIGIN + np.array((- self.width / 2, self.height / 2, 0))
vector_sd = ORIGIN + np.array((self.width / 2, self.height / 2, 0))
axes_x = Line(LEFT * self.width / 2, RIGHT * self.width / 2)
axes_y = Line(DOWN * self.height / 2, UP * self.height / 2)
axes = VGroup(axes_x, axes_y).set_stroke(self.axis_color, self.axis_stroke)
divisions_x = self.width / columns
divisions_y = self.height / rows
directions_buff_x = [UP, DOWN]
directions_buff_y = [RIGHT, LEFT]
dd_buff = [directions_buff_x, directions_buff_y]
vectors_init_x = [vector_ii, vector_si]
vectors_init_y = [vector_si, vector_sd]
vectors_init = [vectors_init_x, vectors_init_y]
divisions = [divisions_x, divisions_y]
orientations = [RIGHT, DOWN]
labels = VGroup()
set_changes = zip([columns, rows], divisions, orientations, [0, 1], vectors_init, dd_buff)
for c_and_r, division, orientation, coord, vi_c, d_buff in set_changes:
for i in range(1, c_and_r):
for v_i, directions_buff in zip(vi_c, d_buff):
ubication = v_i + orientation * division * i
coord_point = round(ubication[coord], self.number_decimals)
label = Text(f"{coord_point}",font="Arial",stroke_width=0).scale(self.labels_scale)
label.next_to(ubication, directions_buff, buff=self.labels_buff)
labels.add(label)
self.add(grid, axes, labels)
class positions(Scene):
def construct(self):
grid= ScreenGrid()
object = Dot()
object.to_corner(UR)
self.add(grid,object)
self.wait(3) ` |
Beta Was this translation helpful? Give feedback.
Answered by
TonyCrane
Jul 11, 2021
Replies: 1 comment
-
Seems that you are using the community version of manim. So you'd better ask the question in the discord channel or open an issue in ManimCommunity/manim instead of here. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
TonyCrane
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems that you are using the community version of manim. So you'd better ask the question in the discord channel or open an issue in ManimCommunity/manim instead of here.