Пример #1
0
 def Make_Graph_Property(self):
     disposable_list = []
     list_x, list_of_list_x = [], []
     list_y, list_of_list_y = [], []
     maximum_size = len(self.x[-1])
     for item in self.x:
         while len(item) < maximum_size:
             for subitem in item:
                 disposable_list.extend((subitem, subitem))
             item = disposable_list
             disposable_list = []
         list_of_list_x.append(item)
     for item in self.y:
         while len(item) < maximum_size:
             for subitem in item:
                 disposable_list.extend((subitem, subitem))
             item = disposable_list
             disposable_list = []
         list_of_list_y.append(item)
     for item in range(maximum_size - 1):
         for subitem in range(len(self.x) - 1):
             list_x.append(list_of_list_x[subitem][item])
             list_y.append(list_of_list_y[subitem][item])
         self.property_perimeter = PropertyPerimeter(list_x, list_y)
         new_x, new_y = self.property_perimeter.Perimeter(self.passing)
         if self.noshow:
             pass
         else:
             plt.plot(list_x, list_y, color = self.variables["color"])
         self.new_xx.extend(new_x)
         self.new_yy.extend(new_y)
         list_x, list_y = [], [] ## Jamais comente essa linha POR FAVOR!!!!!
Пример #2
0
 def Do_Perimeter(self, paint_squares=False):
     passing = self.variables["size"] / self.variables["value"]
     self.property_perimeter = PropertyPerimeter(self.x, self.y)
     self.x, self.y = self.property_perimeter.Perimeter(passing)
     self.property_square = PropertyPerSquare(self.x, self.y,
                                              self.variables["value"],
                                              paint_squares)
Пример #3
0
 def Do_Perimeter(self, paint_squares=False):
     self.passing = (max(self.x) - min(self.x)) / self.variables["value"]
     self.property_perimeter = PropertyPerimeter(self.x, self.y)
     self.x, self.y = self.property_perimeter.Perimeter(self.passing)
     self.property_square = PropertyPerSquare(self.x, self.y,
                                              self.variables["value"],
                                              paint_squares)
Пример #4
0
 def First_Property(self, paint_squares=True):
     self.Create_Fractal()
     passing = (max(self.x) - min(self.x)) / self.variables["value"]
     self.property_perimeter = PropertyPerimeter(self.x, self.y)
     self.x, self.y = self.property_perimeter.Perimeter(passing)
     self.property_square = PropertyPerSquare(self.x, self.y,
                                              self.variables["value"],
                                              paint_squares)
Пример #5
0
 def Do_Area(self):
     self.passing = (max(self.x) - min(self.x)) / self.variables["value"]
     self.property_perimeter = PropertyPerimeter(self.x, self.y)
     self.x, self.y = self.property_perimeter.Perimeter(self.passing)
     self.property_area = PropertyArea(self.x,
                                       self.y,
                                       self.variables["value"],
                                       passing=self.passing)
Пример #6
0
 def Do_Perimeter(self, paint_squares=False):
     limit = len(self.x)
     new_x, new_y = [], []
     for item in range(limit):
         self.property_perimeter = PropertyPerimeter(
             self.x[item], self.y[item])
         new_x_perimeter, new_y_perimeter = self.property_perimeter.Perimeter(
             self.passing)
         new_x.extend(new_x_perimeter)
         new_y.extend(new_y_perimeter)
     self.property_square = PropertyPerSquare(new_x, new_y,
                                              self.variables["value"],
                                              paint_squares)
Пример #7
0
 def Progression_Property(self, first_property=False, make_graph=True):
     for iteration_number in range(1, self.variables["times"] + 1):
         self.Make_Triangle()
         new_x, new_y = [], []
         index = 0
         limit = len(self.x)
         while index < limit:
             new_x.extend(self.x[index])
             new_y.extend(self.y[index])
             index += 1
         passing = (max(new_x) - min(new_y)) / self.variables["value"]
         self.property_perimeter = PropertyPerimeter(new_x, new_y)
         new_x, new_y = self.property_perimeter.Perimeter(passing)
         self.property_square = PropertyPerSquare(new_x, new_y,
                                                  self.variables["value"])
         # print("%d of %d" % (iteration_number, self.variables["times"]))
         self.property_x.append(iteration_number)
         if first_property:
             self.property_y.append(
                 self.property_square.amount_of_marcked_squares)
         else:
             self.dimension_obj = Dimension(
                 self.property_square.amount_of_marcked_squares,
                 self.property_square.passing)
             self.property_y.append(self.dimension_obj.dimension)
     if first_property:
         description = {
             "title":
             "Progression of property perimeter\nArrowhead Fractal",
             "label_x": "Iteration",
             "label_y": "Marcked Squares",
             "label_plot": "Arrowhead"
         }
     else:
         description = {
             "title":
             "Progression of property dimension\nArrowhead Fractal",
             "label_x": "Iteration",
             "label_y": "Dimension Fractal",
             "label_plot": "Arrowhead"
         }
     self.Assemble_Graph(self.property_x, self.property_y,
                         description["title"], description["label_x"],
                         description["label_y"], description["label_plot"],
                         make_graph)
Пример #8
0
 def Do_Area(self):
     self.new_x, self.new_y = [], []
     self.limit = len(self.x)
     for item in range(self.limit):
         self.property_perimeter = PropertyPerimeter(
             self.x[item] + [self.x[item][0]],
             self.y[item] + [self.y[item][0]])
         self.perimeter_x, self.perimeter_y = self.property_perimeter.Perimeter(
             self.passing)
         self.new_x.append(self.perimeter_x)
         self.new_y.append(self.perimeter_y)
     self.area_x, self.area_y = [], []
     for item in range(self.limit):
         self.area_x.extend(self.new_x[item])
         self.area_y.extend(self.new_y[item])
     self.property_area = PropertyArea(self.area_x,
                                       self.area_y,
                                       self.variables["value"],
                                       passing=self.passing)
Пример #9
0
class CantorSet(Fractal):
    def __init__(self, args={}):
        default_vars = {
            "times": 10,
            "scale": 1,
            "color": "#000000",
            "value": 10
        }
        self.variables = self.Define_Vars(args, default_vars)
        Fractal.__init__(self, [[0, self.variables["scale"]]], [[0, 0]])
        self.iteration_number = 0
        self.property_x, self.property_y = [], []
        self.passing = self.variables["scale"] / self.variables["value"]

    def Make_Graph(self):
        limit = len(self.x)
        for item in range(limit):
            plt.plot(self.x[item],
                     self.y[item],
                     color=self.variables["color"],
                     linewidth=1)

    def Organizing_Function(self, value_of_y):
        new_x, new_y = [], []
        limit = len(self.x)
        for item in range(limit):
            x_list, y_list = self.Each_Row_Cantor_Set(self.x[item], value_of_y)
            new_x.extend(x_list)
            new_y.extend(y_list)
        return new_x, new_y

    def Each_Row_Cantor_Set(self, x_position, value_of_y):
        x_1 = x_position[0]
        x_2 = x_1 + ((x_position[1] - x_position[0]) / 3)
        x_3 = x_position[1]
        x_4 = x_3 - ((x_position[1] - x_position[0]) / 3)
        return ([x_1, x_2], [x_3,
                             x_4]), ([value_of_y,
                                      value_of_y], [value_of_y, value_of_y])

    def Create_Fractal(self):
        while self.iteration_number < self.variables["times"]:
            self.iteration_number += 1
            self.Make_Graph()
            self.x, self.y = self.Organizing_Function(self.iteration_number)
            # print("%d of %d" % (self.iteration_number, self.variables["times"]))
        self.Make_Graph()

    def Do_Perimeter(self, paint_squares=False):
        limit = len(self.x)
        new_x, new_y = [], []
        for item in range(limit):
            self.property_perimeter = PropertyPerimeter(
                self.x[item], self.y[item])
            new_x_perimeter, new_y_perimeter = self.property_perimeter.Perimeter(
                self.passing)
            new_x.extend(new_x_perimeter)
            new_y.extend(new_y_perimeter)
        self.property_square = PropertyPerSquare(new_x, new_y,
                                                 self.variables["value"],
                                                 paint_squares)

    def First_Property(self, paint_squares=True):
        self.Create_Fractal()
        self.Do_Perimeter(paint_squares)

    def Property_Dimension(self):
        self.First_Property(paint_squares=False)
        dimension_obj = Dimension(
            self.property_square.amount_of_marcked_squares,
            self.property_square.passing)
        self.dimension = dimension_obj.dimension

    def Progression_Property(self, first_property=False, make_graph=True):
        while self.iteration_number < self.variables["times"]:
            self.iteration_number += 1
            self.x, self.y = self.Organizing_Function(self.iteration_number)
            print("%d of %d" %
                  (self.iteration_number, self.variables["times"]))
            self.Do_Perimeter()
            self.property_x.append(self.iteration_number)
            if first_property:
                self.property_y.append(
                    self.property_square.amount_of_marcked_squares)
            else:
                self.dimension_obj = Dimension(
                    self.property_square.amount_of_marcked_squares,
                    self.property_square.passing)
                self.property_y.append(self.dimension_obj.dimension)
        if first_property:
            description = {
                "title":
                "Progression of property per square\nCantor Set Fractal",
                "label_x": "Row",
                "label_y": "Marcked Squares",
                "label_plot": "Cantor Set"
            }
        else:
            description = {
                "title":
                "Progression of property dimension\nCantor Set Fractal",
                "label_x": "Row",
                "label_y": "Dimension Fractal",
                "label_plot": "Cantor Set"
            }
        self.Assemble_Graph(self.property_x, self.property_y,
                            description["title"], description["label_x"],
                            description["label_y"], description["label_plot"],
                            make_graph)
Пример #10
0
class Sierpinski(Fractal):
    def __init__(self, x=[], y=[], args={}):
        Fractal.__init__(self, x, y)
        self.Create_Vars(args)

    def Create_Vars(self, args={}):
        default_vars = {"times": 8, "size": 1, "color": "#000000", "value": 10}
        self.variables = self.Define_Vars(args, default_vars)
        self.iteration_number = 0
        self.x = [[-self.variables["size"] / 2, 0, self.variables["size"] / 2]]
        self.y = [[
            -self.variables["size"] * 3**0.5 / 6,
            self.variables["size"] * 3**0.5 / 3,
            -self.variables["size"] * 3**0.5 / 6
        ]]
        self.property_x, self.property_y = [], []
        self.passing = self.variables["size"] / self.variables["value"]

    def Create_Fractal(self, property_area=False):
        while self.iteration_number < self.variables["times"]:
            self.iteration_number += 1
            self.Setting_Function()
            # print("%d of %d" % (self.iteration_number, self.variables["times"]))
        if not property_area:
            self.Triangle_Picker()
        self.Make_Graph()

    def Do_Area(self):
        self.new_x, self.new_y = [], []
        self.limit = len(self.x)
        for item in range(self.limit):
            self.property_perimeter = PropertyPerimeter(
                self.x[item] + [self.x[item][0]],
                self.y[item] + [self.y[item][0]])
            self.perimeter_x, self.perimeter_y = self.property_perimeter.Perimeter(
                self.passing)
            self.new_x.append(self.perimeter_x)
            self.new_y.append(self.perimeter_y)
        self.area_x, self.area_y = [], []
        for item in range(self.limit):
            self.area_x.extend(self.new_x[item])
            self.area_y.extend(self.new_y[item])
        self.property_area = PropertyArea(self.area_x,
                                          self.area_y,
                                          self.variables["value"],
                                          passing=self.passing)

    def First_Property(self):
        self.Create_Fractal(property_area=True)
        self.Do_Area()

    def Property_Dimension(self):
        self.First_Property()
        dimension_obj = Dimension(self.property_area.amount_of_marcked_squares,
                                  self.property_area.passing)
        self.dimension = dimension_obj.dimension

    def Progression_Property(self, first_property=False, make_graph=True):
        self.Create_Vars()
        while self.iteration_number < self.variables["times"]:
            self.iteration_number += 1
            self.Setting_Function()
            # print("%d of %d" % (self.iteration_number, self.variables["times"]))
            self.Do_Area()
            self.property_x.append(self.iteration_number)
            if first_property:
                self.property_y.append(
                    self.property_area.amount_of_marcked_squares)
            else:
                self.dimension_obj = Dimension(
                    self.property_area.amount_of_marcked_squares,
                    self.property_area.passing)
                self.property_y.append(self.dimension_obj.dimension)
        if first_property:
            description = {
                "title":
                "Progression of property area\nSierpinski Triangle Fractal",
                "label_x": "Iteration Number",
                "label_y": "Marcked Squares",
                "label_plot": "Sierpinski Triangle"
            }
        else:
            description = {
                "title":
                "Progression of property dimension\nSierpinski Triangle Fractal",
                "label_x": "Iteration Number",
                "label_y": "Dimension Fractal",
                "label_plot": "Sierpinski Triangle"
            }
        self.Assemble_Graph(self.property_x, self.property_y,
                            description["title"], description["label_x"],
                            description["label_y"], description["label_plot"],
                            make_graph)

    def Setting_Function(self):
        new_x, new_y = [], []
        siz = len(self.x)
        for item in range(siz):
            x, y = self.Sierpinski_Triangle(self.x[item], self.y[item])
            new_x.extend(x)
            new_y.extend(y)
        self.x, self.y = new_x, new_y

    def Sierpinski_Triangle(self, x, y):
        x_1 = x[0]
        x_2 = (x[0] + x[1]) / 2
        x_3 = x[1]
        x_4 = (x[1] + x[2]) / 2
        x_5 = x[2]
        x_6 = (x[2] + x[0]) / 2
        y_1 = y[0]
        y_2 = (y[0] + y[1]) / 2
        y_3 = y[1]
        y_4 = (y[1] + y[2]) / 2
        y_5 = y[2]
        y_6 = (y[2] + y[0]) / 2
        triangle_1_x = [x_1, x_6, x_2]
        triangle_1_y = [y_1, y_6, y_2]
        triangle_2_x = [x_2, x_3, x_4]
        triangle_2_y = [y_2, y_3, y_4]
        triangle_3_x = [x_6, x_4, x_5]
        triangle_3_y = [y_6, y_4, y_5]
        return (triangle_1_x, triangle_2_x,
                triangle_3_x), (triangle_1_y, triangle_2_y, triangle_3_y)

    def Triangle_Picker(self):
        new_x, new_y = [], []
        indication = 0
        limit = len(self.x)
        while indication < limit:
            new_x.append([
                self.x[indication][0], self.x[indication][1],
                self.x[indication][2]
            ])
            new_y.append([
                self.y[indication][0], self.y[indication][1],
                self.y[indication][2]
            ])
            indication += 1
        self.x, self.y = new_x, new_y

    def Make_Graph(self):
        limit = len(self.x)
        for item in range(limit):
            plt.fill(self.x[item], self.y[item], color=self.variables["color"])
Пример #11
0
class Arrowhead(Fractal):
    def __init__(self, x=[[0, 1]], y=[[0, 0]], args={}):
        Fractal.__init__(self, x, y)
        default_vars = {"times": 8, "color": "#000000", "value": 10}
        self.variables = self.Define_Vars(args, default_vars)
        self.property_x, self.property_y = [], []

    def Create_Fractal(self):
        for iteration_number in range(1, self.variables["times"] + 1):
            self.Make_Triangle()
            # print("%d of %d" % (iteration_number, self.variables["times"]))
        new_x, new_y = [], []
        index = 0
        limit = len(self.x)
        while index < limit:
            new_x.extend(self.x[index])
            new_y.extend(self.y[index])
            index += 1
        self.x, self.y = new_x, new_y
        self.Make_Graph()

    def First_Property(self, paint_squares=True):
        self.Create_Fractal()
        passing = (max(self.x) - min(self.x)) / self.variables["value"]
        self.property_perimeter = PropertyPerimeter(self.x, self.y)
        self.x, self.y = self.property_perimeter.Perimeter(passing)
        self.property_square = PropertyPerSquare(self.x, self.y,
                                                 self.variables["value"],
                                                 paint_squares)

    def Property_Dimension(self):
        self.First_Property()
        dimension_obj = Dimension(
            self.property_square.amount_of_marcked_squares,
            self.property_square.passing)
        self.dimension = dimension_obj.dimension

    def Progression_Property(self, first_property=False, make_graph=True):
        for iteration_number in range(1, self.variables["times"] + 1):
            self.Make_Triangle()
            new_x, new_y = [], []
            index = 0
            limit = len(self.x)
            while index < limit:
                new_x.extend(self.x[index])
                new_y.extend(self.y[index])
                index += 1
            passing = (max(new_x) - min(new_y)) / self.variables["value"]
            self.property_perimeter = PropertyPerimeter(new_x, new_y)
            new_x, new_y = self.property_perimeter.Perimeter(passing)
            self.property_square = PropertyPerSquare(new_x, new_y,
                                                     self.variables["value"])
            # print("%d of %d" % (iteration_number, self.variables["times"]))
            self.property_x.append(iteration_number)
            if first_property:
                self.property_y.append(
                    self.property_square.amount_of_marcked_squares)
            else:
                self.dimension_obj = Dimension(
                    self.property_square.amount_of_marcked_squares,
                    self.property_square.passing)
                self.property_y.append(self.dimension_obj.dimension)
        if first_property:
            description = {
                "title":
                "Progression of property perimeter\nArrowhead Fractal",
                "label_x": "Iteration",
                "label_y": "Marcked Squares",
                "label_plot": "Arrowhead"
            }
        else:
            description = {
                "title":
                "Progression of property dimension\nArrowhead Fractal",
                "label_x": "Iteration",
                "label_y": "Dimension Fractal",
                "label_plot": "Arrowhead"
            }
        self.Assemble_Graph(self.property_x, self.property_y,
                            description["title"], description["label_x"],
                            description["label_y"], description["label_plot"],
                            make_graph)

    def Make_Triangle(self):
        new_x, new_y = [], []
        limit = len(self.x)
        for item in range(limit):
            x_list = self.x[item]
            y_list = self.y[item]
            if y_list[1] - y_list[0] == 0:
                x_1 = x_list[0]
                x_2 = x_list[0] + (x_list[1] - x_list[0]) / 4
                x_3 = x_list[0] + (x_list[1] - x_list[0]) * 3 / 4
                x_4 = x_list[1]
                y_1 = y_list[0]
                y_2 = y_list[0] + abs(x_list[1] - x_list[0]) / 4
                y_3 = y_2
                y_4 = y_list[1]
            elif x_list[1] - x_list[0] == 0:
                x_1 = x_list[0]
                x_2 = x_list[0] + abs(y_list[1] - y_list[0]) / 4
                x_3 = x_2
                x_4 = x_list[1]
                y_1 = y_list[0]
                y_2 = y_list[0] + (y_list[1] - y_list[0]) / 4
                y_3 = y_list[0] + (y_list[1] - y_list[0]) * 2 / 4
                y_4 = y_list[1]
            elif x_list[1] > x_list[0] and y_list[1] > y_list[0]:
                x_1 = x_list[0]
                x_2 = x_list[1]
                x_3 = x_2 + (y_list[1] - y_list[0]) / 2
                x_4 = x_2
                y_1 = y_list[0]
                y_2 = y_1
                y_3 = y_list[0] + (y_list[1] - y_list[0]) / 2
                y_4 = y_list[1]
            elif x_list[1] < x_list[0] and y_list[1] > y_list[0]:
                x_1 = x_list[0]
                x_2 = x_list[1]
                x_3 = x_2 - (y_list[1] - y_list[0]) / 2
                x_4 = x_2
                y_1 = y_list[0]
                y_2 = y_1
                y_3 = y_list[0] + (y_list[1] - y_list[0]) / 2
                y_4 = y_list[1]
            elif x_list[1] < x_list[0] and y_list[1] < y_list[0]:
                x_1 = x_list[0]
                x_2 = x_list[0] - (y_list[1] - y_list[0]) / 2
                x_3 = x_1
                x_4 = x_list[1]
                y_1 = y_list[0]
                y_2 = y_list[0] + (y_list[1] - y_list[0]) / 2
                y_3 = y_list[1]
                y_4 = y_list[1]
            elif x_list[1] > x_list[0] and y_list[1] < y_list[0]:
                x_1 = x_list[0]
                x_2 = x_list[0] + (y_list[1] - y_list[0]) / 2
                x_3 = x_1
                x_4 = x_list[1]
                y_1 = y_list[0]
                y_2 = y_list[0] + (y_list[1] - y_list[0]) / 2
                y_3 = y_list[1]
                y_4 = y_list[1]
            new_x.extend(([x_1, x_2], [x_2, x_3], [x_3, x_4]))
            new_y.extend(([y_1, y_2], [y_2, y_3], [y_3, y_4]))
        self.x, self.y = new_x, new_y

    def Make_Graph(self):
        plt.plot(self.x, self.y, color=self.variables["color"])
Пример #12
0
class SierpinskiCarpet(Sierpinski):
    def __init__(self, args={}):
        Sierpinski.__init__(self, [], [], args)

    def Sierpinski_Triangle(self, x, y):
        x_1 = x[0]
        x_2 = x_1 + (x[3] - x[0]) / 3
        x_3 = x_1 + (x[3] - x[0]) * 2 / 3
        x_4 = x[3]
        y_1 = y[0]
        y_2 = y_1 + (y[2] - y[0]) / 3
        y_3 = y_1 + (y[2] - y[0]) * 2 / 3
        y_4 = y[2]
        square_1_x = [x_1, x_1, x_2, x_2]
        square_2_x = [x_2, x_2, x_3, x_3]
        square_3_x = [x_3, x_3, x_4, x_4]
        square_4_x = square_1_x
        square_5_x = square_3_x
        square_6_x = square_1_x
        square_7_x = square_2_x
        square_8_x = square_3_x
        square_1_y = [y_1, y_2, y_2, y_1]
        square_2_y = square_1_y
        square_3_y = square_1_y
        square_4_y = [y_2, y_3, y_3, y_2]
        square_5_y = square_4_y
        square_6_y = [y_3, y_4, y_4, y_3]
        square_7_y = square_6_y
        square_8_y = square_6_y
        return ((square_1_x, square_2_x, square_3_x, square_4_x, square_5_x,
                 square_6_x, square_7_x, square_8_x),
                (square_1_y, square_2_y, square_3_y, square_4_y, square_5_y,
                 square_6_y, square_7_y, square_8_y))

    def Create_Vars(self, args={}):
        default_vars = {"times": 4, "size": 1, "color": "#000000", "value": 10}
        self.variables = self.Define_Vars(args, default_vars)
        self.iteration_number = 0
        self.x = [[0, 0, self.variables["size"], self.variables["size"]]]
        self.y = [[0, self.variables["size"], self.variables["size"], 0]]
        self.property_x, self.property_y = [], []
        self.passing = self.variables["size"] / self.variables["value"]

    def Create_Fractal(self):
        while self.iteration_number < self.variables["times"]:
            self.iteration_number += 1
            self.Setting_Function()
            # print("%d of %d" % (self.iteration_number, self.variables["times"]))
        self.Make_Graph()

    def Do_Area(self):
        self.new_x, self.new_y = [], []
        self.limit = len(self.x)
        for item in range(self.limit):
            self.property_perimeter = PropertyPerimeter(
                self.x[item] + [self.x[item][0]],
                self.y[item] + [self.y[item][0]])
            self.perimeter_x, self.perimeter_y = self.property_perimeter.Perimeter(
                self.passing)
            self.new_x.append(self.perimeter_x)
            self.new_y.append(self.perimeter_y)
        self.area_x, self.area_y = [], []
        for item in range(self.limit):
            self.area_x.extend(self.new_x[item])
            self.area_y.extend(self.new_y[item])
        self.property_area = PropertyArea(self.area_x,
                                          self.area_y,
                                          self.variables["value"],
                                          passing=self.passing)

    def First_Property(self):
        self.Create_Fractal()
        self.Do_Area()

    def Property_Dimension(self):
        self.First_Property()
        dimension_obj = Dimension(self.property_area.amount_of_marcked_squares,
                                  self.property_area.passing)
        self.dimension = dimension_obj.dimension

    def Progression_Property(self, first_property=False, make_graph=True):
        self.Create_Vars()
        while self.iteration_number < self.variables["times"]:
            self.iteration_number += 1
            self.Setting_Function()
            # print("%d of %d" % (self.iteration_number, self.variables["times"]))
            self.Do_Area()
            self.property_x.append(self.iteration_number)
            if first_property:
                self.property_y.append(
                    self.property_area.amount_of_marcked_squares)
            else:
                self.dimension_obj = Dimension(
                    self.property_area.amount_of_marcked_squares,
                    self.property_area.passing)
                self.property_y.append(self.dimension_obj.dimension)
        if first_property:
            description = {
                "title":
                "Progression of property area\nSierpinski Carpet Fractal",
                "label_x": "Iteration Number",
                "label_y": "Marcked Squares",
                "label_plot": "Sierpinski Carpet"
            }
        else:
            description = {
                "title":
                "Progression of property dimension\nSierpinski Carpet Fractal",
                "label_x": "Iteration Number",
                "label_y": "Dimension Fractal",
                "label_plot": "Sierpinski Carpet"
            }
        self.Assemble_Graph(self.property_x, self.property_y,
                            description["title"], description["label_x"],
                            description["label_y"], description["label_plot"],
                            make_graph)
Пример #13
0
class Flake(Fractal):
    def __init__(self, args={}):
        default_vars = {
            "times": 5,
            "amount_of_sides": 5,
            "scale": 1,
            "inwards_out_wards": True,
            "color": "#000000",
            "value": 10
        }
        self.variables = self.Define_Vars(args, default_vars)
        Fractal.__init__(self, [0, self.variables["scale"]], [0, 0])
        self.property_x, self.property_y = [], []

    def Create_Fractal(self):
        for iteration_number in range(self.variables["times"]):
            # print("%d of %d" % (iteration_number + 1, self.variables["times"]))
            self.x, self.y = self.Do_Calculation(iteration_number)
        self.Make_Graph()

    def Do_Area(self):
        self.passing = (max(self.x) - min(self.x)) / self.variables["value"]
        self.property_perimeter = PropertyPerimeter(self.x, self.y)
        self.x, self.y = self.property_perimeter.Perimeter(self.passing)
        self.property_area = PropertyArea(self.x,
                                          self.y,
                                          self.variables["value"],
                                          passing=self.passing)

    def First_Property(self):
        self.Create_Fractal()
        self.Do_Area()

    def Property_Dimension(self):
        self.First_Property()
        dimension_obj = Dimension(self.property_area.amount_of_marcked_squares,
                                  self.property_area.passing)
        self.dimension = dimension_obj.dimension

    def Progression_Property(self, first_property=False, make_graph=True):
        for iteration_number in range(self.variables["times"]):
            # print("%d of %d" % (iteration_number + 1, self.variables["times"]))
            self.x, self.y = self.Do_Calculation(iteration_number)
            self.Do_Area()
            self.property_x.append(iteration_number + 1)
            if first_property:
                self.property_y.append(
                    self.property_area.amount_of_marcked_squares)
            else:
                self.dimension_obj = Dimension(
                    self.property_area.amount_of_marcked_squares,
                    self.property_area.passing)
                self.property_y.append(self.dimension_obj.dimension)
        if first_property:
            description = {
                "title": "Progression of property area\nKoch Flake Fractal",
                "label_x": "Iteration",
                "label_y": "Marcked Squares",
                "label_plot": "Koch Flake"
            }
        else:
            description = {
                "title":
                "Progression of property dimension\nKoch Flake Fractal",
                "label_x": "Iteration",
                "label_y": "Dimension Fractal",
                "label_plot": "Koch Flake"
            }
        self.Assemble_Graph(self.property_x, self.property_y,
                            description["title"], description["label_x"],
                            description["label_y"], description["label_plot"],
                            make_graph)

    def Make_Graph(self):
        plt.plot(self.x, self.y, color=self.variables["color"])

    def Do_Calculation(self, iteration_number):
        sum_of_integer_angles = 180 * (self.variables["amount_of_sides"] - 2)
        angle = sum_of_integer_angles / self.variables[
            "amount_of_sides"] * math.pi / 180
        angle_backup = angle
        new_final_x, new_final_y = [], []
        limit = len(self.x) - 1
        for index in range(limit):
            difference_x = self.x[index + 1] - self.x[index]
            difference_y = self.y[index + 1] - self.y[index]
            distance_x_y = (difference_x**2 + difference_y**2)**0.5
            if difference_x < 0:
                distance_x_y *= -1
            if difference_x != 0:
                current_angle = math.atan(difference_y / difference_x)
            elif difference_y > 0:
                current_angle = math.pi / 2
            elif difference_y < 0:
                current_angle = 3 * math.pi / 2
            else:
                continue
            if iteration_number == 0:
                distance_x_y = 3 * distance_x_y
                new_x = [self.x[index]]
                new_y = [self.y[index]]
            else:
                new_x = [self.x[index] + difference_x / 3]
                new_y = [self.y[index] + difference_y / 3]
            counter_while = 0
            while counter_while < self.variables["amount_of_sides"] - 2:
                new_x += [
                    new_x[-1] +
                    (distance_x_y / 3) * math.cos(current_angle + angle)
                ]
                new_y += [
                    new_y[-1] +
                    (distance_x_y / 3) * math.sin(current_angle + angle)
                ]
                angle -= (math.pi - angle_backup)
                counter_while += 1
            angle = angle_backup
            if iteration_number == 0:
                new_x += [self.x[index + 1]]
                new_y += [self.y[index + 1]]
                new_x += [self.x[index]]
                new_y += [self.y[index]]
                if self.variables["inwards_out_wards"]:
                    new_x = new_x[::-1]
                    new_y = new_y[::-1]
            else:
                new_x += [self.x[index] + 2 * difference_x / 3]
                new_y += [self.y[index] + 2 * difference_y / 3]
                new_x = [self.x[index]] + new_x + [self.x[index + 1]]
                new_y = [self.y[index]] + new_y + [self.y[index + 1]]
            new_final_x.extend(new_x)
            new_final_y.extend(new_y)
        return new_final_x, new_final_y
Пример #14
0
class Tree(Fractal):
    def __init__(self, args = {}):
        default_vars = {"times": 10, "size": 1, "angle": 15, "z": 0, "zimp": 0, "w": 0, "wimp": 0, "value": 10, "color": "#000000"}
        self.variables = self.Define_Vars(args, default_vars)
        Fractal.__init__(self, [[0], [0]], [[0], [self.variables["size"]]])
        self.variables["theta"] = (self.variables["angle"] * math.pi) / 180
        self.variables["angle"] = [self.variables["theta"], -self.variables["theta"]]
        self.variables["z"] = 1 - self.variables["z"] / 100 + self.variables["z"] / 50
        self.variables["w"] = 1 - self.variables["w"] / 100 + self.variables["w"] / 50
        self.new_xx, self.new_yy = [], []
        self.property_x, self.property_y = [], []

    
    def Create_Fractal(self):
        for iteration_number in range(self.variables["times"]):
            self.Do_Calculation()
            # print("%d of %d" % (iteration_number + 1, self.variables["times"]))
        self.Make_Graph()

    
    def Do_Perimeter(self, paint_squares = False):
        self.passing = (max(self.x[-1]) - min(self.x[-1])) / self.variables["value"]
        self.Make_Graph_Property()
        self.property_square = PropertyPerSquare(self.new_xx, self.new_yy, self.variables["value"], paint_squares)

    
    def First_Property(self, paint_squares = True):
        self.noshow = not paint_squares
        for iteration_number in range(self.variables["times"]):
            self.Do_Calculation()
            # print("%d of %d" % (iteration_number + 1, self.variables["times"]))
        self.Do_Perimeter(paint_squares)        

    
    def Property_Dimension(self):
        self.First_Property(paint_squares = False)
        dimension_obj = Dimension(self.property_square.amount_of_marcked_squares, self.property_square.passing)
        self.dimension = dimension_obj.dimension

    
    def Progression_Property(self, first_property = False, make_graph = True):
        self.noshow = True
        self.Do_Calculation()
        self.property_x.append(1)
        self.property_y.append(self.variables["size"] / self.variables["value"])
        # print("%d of %d" % (1, self.variables["times"]))
        for iteration_number in range(1, self.variables["times"]):
            self.Do_Calculation()
            # print("%d of %d" % (iteration_number + 1, self.variables["times"]))
            self.Do_Perimeter()
            self.new_xx, self.new_yy = [], []
            self.property_x.append(iteration_number + 1)
            if first_property:
                self.property_y.append(self.property_square.amount_of_marcked_squares)
            else:
                self.dimension_obj = Dimension(self.property_square.amount_of_marcked_squares, self.property_square.passing)
                self.property_y.append(self.dimension_obj.dimension)
        if first_property:
            description = {"title": "Progression of property perimeter\nTree Fractal", "label_x": "Iteration Number", "label_y": "Marcked Squares", "label_plot": "Tree"}
        else:
            description = {"title": "Progression of property dimension\nTree Fractal", "label_x": "Iteration Number", "label_y": "Dimension Fractal", "label_plot": "Tree"}
        self.Assemble_Graph(self.property_x, self.property_y, description["title"], description["label_x"], description["label_y"], description["label_plot"], make_graph)


    def Make_Graph_Property(self):
        disposable_list = []
        list_x, list_of_list_x = [], []
        list_y, list_of_list_y = [], []
        maximum_size = len(self.x[-1])
        for item in self.x:
            while len(item) < maximum_size:
                for subitem in item:
                    disposable_list.extend((subitem, subitem))
                item = disposable_list
                disposable_list = []
            list_of_list_x.append(item)
        for item in self.y:
            while len(item) < maximum_size:
                for subitem in item:
                    disposable_list.extend((subitem, subitem))
                item = disposable_list
                disposable_list = []
            list_of_list_y.append(item)
        for item in range(maximum_size - 1):
            for subitem in range(len(self.x) - 1):
                list_x.append(list_of_list_x[subitem][item])
                list_y.append(list_of_list_y[subitem][item])
            self.property_perimeter = PropertyPerimeter(list_x, list_y)
            new_x, new_y = self.property_perimeter.Perimeter(self.passing)
            if self.noshow:
                pass
            else:
                plt.plot(list_x, list_y, color = self.variables["color"])
            self.new_xx.extend(new_x)
            self.new_yy.extend(new_y)
            list_x, list_y = [], [] ## Jamais comente essa linha POR FAVOR!!!!!


    def Make_Graph(self):
        disposable_list = []
        list_x, list_of_list_x = [], []
        list_y, list_of_list_y = [], []
        maximum_size = len(self.x[-1])
        for item in self.x:
            while len(item) < maximum_size:
                for subitem in item:
                    disposable_list.extend((subitem, subitem))
                item = disposable_list
                disposable_list = []
            list_of_list_x.append(item)
        for item in self.y:
            while len(item) < maximum_size:
                for subitem in item:
                    disposable_list.extend((subitem, subitem))
                item = disposable_list
                disposable_list = []
            list_of_list_y.append(item)
        for item in range(maximum_size - 1):
            for subitem in range(len(self.x) - 1):
                list_x.append(list_of_list_x[subitem][item])
                list_y.append(list_of_list_y[subitem][item])
            plt.plot(list_x, list_y, color = self.variables["color"])
            list_x, list_y = [], [] ## Jamais comente essa linha POR FAVOR!!!!!


    def Imperfectionate(self, w_z, wimp_zimp):
        if type(w_z) == int or type(w_z) == float:
            return w_z * 1 - wimp_zimp / 200 + (random.random() * wimp_zimp) / 100
        else:
            new_x = []
            for item in w_z:
                if type(item) == int or type(item) == float:
                    item *= 1 - wimp_zimp / 200 + (random.random() * wimp_zimp) / 100
                    new_x.append(item)
                else:
                    new_list_of_x = []
                    for subitem in item:
                        subitem *= 1 - wimp_zimp / 200 + (random.random() * wimp_zimp) / 100
                        new_list_of_x.append(subitem)
                    new_x.append(new_list_of_x)
            return new_x

        
    def Add_Angles(self):
        list_1, list_2 = [], []
        for item in self.variables["angle"]:
            list_1.append(item + self.variables["theta"])
            list_2.append(item - self.variables["theta"])
        self.variables["angle"] = list_1 + list_2


    def Do_Calculation(self):
        new_angle = []
        for item in self.variables["angle"]:
            item *= self.Imperfectionate(self.variables["w"], self.variables["wimp"])
            new_angle.append(item)
        self.variables["angle"] = new_angle
        new_x, new_y = [], []
        limit = len(self.x[-1])
        index = 0
        while index < limit:
            new_x.append(self.x[-1][index] + self.variables["size"] * self.Imperfectionate(self.variables["z"], self.variables["zimp"]) * math.sin(self.variables["angle"][2 * index]))
            new_x.append(self.x[-1][index] + self.variables["size"] * self.Imperfectionate(self.variables["z"], self.variables["zimp"]) * math.sin(self.variables["angle"][2 * index + 1]))
            new_y.append(self.y[-1][index] + self.variables["size"] * self.Imperfectionate(self.variables["z"], self.variables["zimp"]) * math.cos(self.variables["angle"][2 * index]))
            new_y.append(self.y[-1][index] + self.variables["size"] * self.Imperfectionate(self.variables["z"], self.variables["zimp"]) * math.cos(self.variables["angle"][2 * index + 1]))
            index += 1
        self.x.append(new_x)
        self.y.append(new_y)
        self.Add_Angles()
Пример #15
0
class HilbertCurve(Fractal):
    def __init__(self, args={}):
        default_vars = {
            "times": 5,
            "scale": 1,
            "color": "#000000",
            "value": 10
        }
        self.variables = self.Define_Vars(args, default_vars)
        x = [0, 0, self.variables["scale"], self.variables["scale"]]
        y = [self.variables["scale"], 0, 0, self.variables["scale"]]
        Fractal.__init__(self, x, y)
        self.iteration_number = 0
        self.property_x, self.property_y = [], []

    def Create_Fractal(self):
        while self.iteration_number < self.variables["times"]:
            self.iteration_number += 1
            self.Do_Calculation()
            # print("%d of %d" % (self.iteration_number, self.variables["times"]))
        self.Make_Graph()

    def Do_Perimeter(self, paint_squares=False):
        self.passing = (max(self.x) - min(self.x)) / self.variables["value"]
        self.property_perimeter = PropertyPerimeter(self.x, self.y)
        self.x, self.y = self.property_perimeter.Perimeter(self.passing)
        self.property_square = PropertyPerSquare(self.x, self.y,
                                                 self.variables["value"],
                                                 paint_squares)

    def First_Property(self, paint_squares=True):
        self.Create_Fractal()
        self.Do_Perimeter(paint_squares)

    def Property_Dimension(self):
        self.First_Property()
        dimension_obj = Dimension(
            self.property_square.amount_of_marcked_squares,
            self.property_square.passing)
        self.dimension = dimension_obj.dimension

    def Progression_Property(self, first_property=False, make_graph=True):
        while self.iteration_number < self.variables["times"]:
            self.iteration_number += 1
            self.Do_Calculation()
            # print("%d of %d" % (self.iteration_number, self.variables["times"]))
            self.Do_Perimeter()
            self.property_x.append(self.iteration_number)
            if first_property:
                self.property_y.append(
                    self.property_square.amount_of_marcked_squares)
            else:
                self.dimension_obj = Dimension(
                    self.property_square.amount_of_marcked_squares,
                    self.property_square.passing)
                self.property_y.append(self.dimension_obj.dimension)
        if first_property:
            description = {
                "title":
                "Progression of property perimeter\nHilbert Curve Fractal",
                "label_x": "Iteration",
                "label_y": "Marcked Squares",
                "label_plot": "Hilbert Curve"
            }
        else:
            description = {
                "title":
                "Progression of property dimension\nHilbert Curve Fractal",
                "label_x": "Iteration",
                "label_y": "Dimension Fractal",
                "label_plot": "Hilbert Curve"
            }
        self.Assemble_Graph(self.property_x, self.property_y,
                            description["title"], description["label_x"],
                            description["label_y"], description["label_plot"],
                            make_graph)

    def Make_Graph(self):
        plt.plot(self.x, self.y, color=self.variables["color"])

    def Reduces_Size(self):
        new_x, new_y = [], []
        for item in self.x:
            new_x.append(item / ((2**(self.iteration_number + 1) - 1) /
                                 ((2**(self.iteration_number + 1) - 2) / 2)))
        for item in self.y:
            new_y.append(item / ((2**(self.iteration_number + 1) - 1) /
                                 ((2**(self.iteration_number + 1) - 2) / 2)))
        self.x, self.y = new_x, new_y

    def Rotate_Counterclockwise(self):
        new_x, new_y = [self.x[0]], [self.y[0]]
        limit = len(self.x)
        for item in range(1, limit):
            new_x.append(new_x[-1] + self.y[-item] - self.y[-item - 1])
            new_y.append(new_y[-1] + self.x[-item] - self.x[-item - 1])
        return new_x, new_y

    def Rotate_Clockwise(self):
        new_x, new_y = [self.x[-1]], [self.y[-1]]
        limit = len(self.x)
        for item in range(1, limit):
            new_x.append(new_x[-1] + self.y[-item - 1] - self.y[-item])
            new_y.append(new_y[-1] - self.x[-item - 1] + self.x[-item])
        return new_x, new_y

    def Do_Calculation(self):
        size = self.x[-1] - self.x[0]
        disposable_list = []
        new_x, new_y = [], []
        self.Reduces_Size()
        addition = size / (2**(self.iteration_number + 1) - 1)
        x_3, y_3 = self.Rotate_Counterclockwise()
        x_4, y_4 = self.Rotate_Clockwise()
        for item in self.x:
            disposable_list.append(item + addition + (self.x[-1] - self.x[0]))
        x_2 = disposable_list[::]
        disposable_list = []
        for item in x_4:
            disposable_list.append(item + addition + (self.x[-1] - self.x[0]))
        x_4 = disposable_list[::]
        disposable_list = []
        for item in y_3:
            disposable_list.append(item + addition)
        y_3 = disposable_list[::]
        disposable_list = []
        for item in y_4:
            disposable_list.append(item + addition)
        y_4 = disposable_list[::]
        disposable_list = []
        for item in [x_3[::-1], self.x, x_2, x_4]:
            new_x.extend(item)
        for item in [y_3[::-1], self.y, self.y, y_4]:
            new_y.extend(item)
        self.x, self.y = new_x, new_y