So, I've been trying to make a Dragon Curve with Python, Pygame, and what I've done is have a main file for running it and have a curve.py
file where I put the Curve
class. The Curve
class is pretty simple (and incomplete) at the moment, but here's how it works:
there's a positions
value which should hold the line's positions (I'm basically first drawing a line, then duplicating it, and rotate it 90 degrees, then instead of a line, this time I'm drawing the object I've drawn (2 lines with a 90 degrees angle between them) with a 90 degrees difference in angle to the previous one), then I have a current_shape
list which holds the start and end points of the current shape lines, then there is next_shape
which is for the duplicate object (which then rotates 90 degrees and then merges with the initial object). So this is my Curve
class right now:
class Curve:
def __init__(self, shape_start, multiplier, counter): # counter is for making only a number of curves
self.multiplier = multiplier
self.positions = [shape_start]
self.current_shape = [[shape_start, [self.positions[0][0] + self.multiplier, self.positions[0][1]]]]
self.counter = counter
self.next_shape = [[shape_start, [self.positions[0][0] + self.multiplier, self.positions[0][1] + self.multiplier]]]
def copy_object(self):
self.next_shape = self.current_shape.copy()
def rotate_next(self, degrees):
for id, line in enumerate(self.next_shape):
line[1][0] = self.positions[id][0] + int(cos(degrees/180*pi)*self.multiplier)
line[1][1] = self.positions[id][1] + int(sin(degrees/180*pi)*self.multiplier)
def merge(self):
self.current_shape = self.current_shape.copy() + self.next_shape.copy()
def draw(self, display):
for line in self.current_shape:
pygame.draw.line(display, (100, 100, 255), (line[0][0], line[0][1]), (line[1][0], line[1][1]), 2)
self.counter -= 1
(note: counter
is for the iteration of the curve, I can't let it make curves forever you know!)
my problem right now is that when I rotate_next(90)
, it rotates both of them.
here's a part of main.py
which holds the order of the functions:
dragoncurve.copy_object()
dragoncurve.rotate_next(90)
dragoncurve.merge()
dragoncurve.draw(screen)
so yea, first I copy current_shape
to next_shape
, then I rotate next_shape
90 degrees, then I merge the 2 lists, then I draw current_shape
.
What is wrong with this?