How Do I Create Multiple Shapes Relative To Each Other In Kivy?
I want to be able to create multiple shapes on my canvas and have them evenly spaced out from each other. I would also like to have the shapes start a new line once they reach the
Solution 1:
pos[0]
, pos[1]
, size[0]
, size[1]
what does the 0 and 1 in rect.size and new_pos do?
Kivy Widget » pos
pos
Position of the widget.
pos is a ReferenceListProperty of (x, y) properties.
The pos
contains the x and y coordinates of a widget's position. pos[0]
refers to the x coordinate, and pos[1]
refers to the y coordinate.
Kivy Widget » size
size
Size of the widget.
size is a ReferenceListProperty of (width, height) properties.
The size
contains the width and height of a widget. size[0]
refers to the width and size[1]
refers to the height.
Create multiple shapes
To prevent the rectangles from overlapping, save the starting position and increment it after drawing each rectangle.
Snippets
The following snippets add rectangles diagonally.
new_pos = can.pos
for x inrange(get_score):
with can.ids.my_box.canvas:
Color(0, 1, 0, .75, mode='rgba')
rect = Rectangle(pos=new_pos, size=(30, 30))
new_pos[0] += rect.size[0]
new_pos[1] += rect.size[1]
Post a Comment for "How Do I Create Multiple Shapes Relative To Each Other In Kivy?"