Saltar a contenido

La Espiral de fibonacci

La construcción en GeoGebra

Animación en P5

Code (manim)

Text Only
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
from manim import *

class Fibonacci(MovingCameraScene):
    #Dinuja cada cuadrado size: lado, pos1: movimiento1, pos2.movimiento2
    def sectionSquare(self, size, pos1, pos2, color):
        square = Square(size, fill_opacity=0.3)
        square.set_fill(color = color, opacity = 0.3)
        square.shift(pos1)
        square.shift(pos2)
        #self.play(Create(square))
        self.play(DrawBorderThenFill(square))
        self.writeNumber(size, pos1, pos2)
        return square

  def writeNumber(self, text, pos1, pos2):
      text = Text(str(text), font="Noto Sans")
      text.shift(pos1)
      text.shift(pos2)
      self.play(Write(text))

  def construct(self):
      #construcción de ejes y primera cámara
      self.ejes()

      self.play(self.camera.frame.animate.move_to(RIGHT).move_to(UP).set(width=6))
      #primer y sefgundo cuadrado
      #1
      square1=self.sectionSquare(1, RIGHT*1/2, UP*1/2, '#FF2135')
      self.play(self.camera.frame.animate.move_to(RIGHT).move_to(UP).set(width=6))
      #1
      square2 =self.sectionSquare(1, UP*1/2, RIGHT*3/2, '#FF2135')
      #centramos cámara
      self.play(self.camera.frame.animate.move_to(RIGHT).move_to(UP).set(width=9))
      #2
      square3=self.sectionSquare(2, 2*UP, 1*RIGHT, '#FF2135')

      self.play(self.camera.frame.animate.move_to(0.5*LEFT).move_to(1.5*UP).set(width=11))
      #3
      square4=self.sectionSquare(3, 1.5*UP, 1.5*LEFT, '#FF2135')

      self.play(self.camera.frame.animate.move_to(0.5*LEFT).move_to(DOWN).set(width=16))

      #5
      square5=self.sectionSquare(5, (5/2)*DOWN, LEFT*0.5, '#FF2135')

      self.play(self.camera.frame.animate.set(width=square1.width * 25))

      square6=self.sectionSquare(8, DOWN, RIGHT*6, '#FF2135')

      self.play(self.camera.frame.animate.set(width=square1.width * 60).move_to(square3))

      square7=self.sectionSquare(13, UP*9.5, RIGHT*3.5, '#FF2135')

      self.wait(1)
      self.play(self.camera.frame.animate.set(width=square1.width*15).move_to(square3))

      arco1=Arc(radius=-1, angle=PI, arc_center=[1, 1, 0.])
      self.play(Create(arco1))

      arco2=Arc(radius=2, angle=PI/2, arc_center=[0, 1, 0.])
      self.play(Create(arco2))

      arco3=Arc(radius=3, start_angle=PI/2, angle=PI/2, arc_center=[0, 0, 0.])
      self.play(Create(arco3))


      self.play(self.camera.frame.animate.set(width=square1.width * 25))


      arco4=Arc(radius=5, start_angle=PI, angle=PI/2, arc_center=[2, 0, 0.])
      self.play(Create(arco4))



      self.play(self.camera.frame.animate.set(width=square1.width * 25))


      arco5=Arc(radius=8, start_angle=3*PI/2, angle=PI/2, arc_center=[2, 3, 0.])
      self.play(Create(arco5))


      self.camera.frame.save_state()
      self.play(self.camera.frame.animate.set(width=square1.width * 70))

      #self.play(Restore(self.camera.frame))

      arco6=Arc(radius=13, start_angle=0, angle=PI/2, arc_center=[-3, 3, 0.])
      self.play(Create(arco6))

      self.play(self.camera.frame.animate.move_to(square7))
      self.play(self.camera.frame.animate.set(width=square1.width * 62))

      self.wait(3)



  def ejes(self):
      number_plane = NumberPlane(
          x_range=[-30, 30, 1],
          y_range=[-30, 30, 1],
          background_line_style={
              "stroke_color": '#4e9ed3',
              "stroke_width": 3  ,
              "stroke_opacity": 0.9
          }
      )
      dot = Dot(ORIGIN)
      self.add(number_plane, dot)

  def fibonacci(num):
      arr = [0,1]
      while(len(arr)