Voilà un script qui génère le flocon de von koch
This commit is contained in:
parent
3d49e9050f
commit
af3fc330cc
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
.idea/
|
||||||
|
Pipfile.lock
|
12
Pipfile
Normal file
12
Pipfile
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[[source]]
|
||||||
|
url = "https://pypi.org/simple"
|
||||||
|
verify_ssl = true
|
||||||
|
name = "pypi"
|
||||||
|
|
||||||
|
[packages]
|
||||||
|
pillow = "*"
|
||||||
|
|
||||||
|
[dev-packages]
|
||||||
|
|
||||||
|
[requires]
|
||||||
|
python_version = "3.6"
|
@ -19,14 +19,11 @@ A new turtle which is faster.
|
|||||||
:undoc-members:
|
:undoc-members:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import math
|
import math
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw
|
||||||
|
|
||||||
import tkinter as Tk
|
|
||||||
|
|
||||||
|
|
||||||
class Figures():
|
class Figures():
|
||||||
"""A lot of function to create some well-know shapes
|
"""A lot of function to create some well-know shapes
|
||||||
@ -204,14 +201,14 @@ class Figures():
|
|||||||
else:
|
else:
|
||||||
self._koch_curve(length)
|
self._koch_curve(length)
|
||||||
|
|
||||||
class Turtle(Tk.Tk):
|
|
||||||
|
class Turtle():
|
||||||
|
|
||||||
### Fonctions internes ###
|
### Fonctions internes ###
|
||||||
|
|
||||||
def _calcCentre(self, taille):
|
def _calcCentre(self, taille):
|
||||||
return (taille[0] / 2, taille[1] / 2)
|
return (taille[0] / 2, taille[1] / 2)
|
||||||
|
|
||||||
|
|
||||||
# self.canvas.update()
|
# self.canvas.update()
|
||||||
|
|
||||||
def _avance(self, distance):
|
def _avance(self, distance):
|
||||||
@ -219,11 +216,6 @@ class Turtle(Tk.Tk):
|
|||||||
self._etat.get("coordx")
|
self._etat.get("coordx")
|
||||||
AC = (distance * math.sin(math.radians(self._etat.get("angle")))) + \
|
AC = (distance * math.sin(math.radians(self._etat.get("angle")))) + \
|
||||||
self._etat.get("coordy")
|
self._etat.get("coordy")
|
||||||
self.canvas.create_line(self._etat.get("coordx"),
|
|
||||||
self._etat.get("coordy"),
|
|
||||||
AB,
|
|
||||||
AC)
|
|
||||||
if self.sauvegarde:
|
|
||||||
self._avanceIMG(distance)
|
self._avanceIMG(distance)
|
||||||
self._setCoords((AB, AC))
|
self._setCoords((AB, AC))
|
||||||
# self.canvas.update()
|
# self.canvas.update()
|
||||||
@ -255,8 +247,8 @@ class Turtle(Tk.Tk):
|
|||||||
self._etat["angle"] = self._etat.get("angle") - 360
|
self._etat["angle"] = self._etat.get("angle") - 360
|
||||||
|
|
||||||
def _clear(self):
|
def _clear(self):
|
||||||
self.canvas.delete("all")
|
pass
|
||||||
self.canvas.update()
|
|
||||||
### Fonction publiques ###
|
### Fonction publiques ###
|
||||||
|
|
||||||
def _clearIMG(self):
|
def _clearIMG(self):
|
||||||
@ -276,12 +268,6 @@ class Turtle(Tk.Tk):
|
|||||||
"coordy": self._config.get("centre")[1],
|
"coordy": self._config.get("centre")[1],
|
||||||
"couleur": (0, 0, 0),
|
"couleur": (0, 0, 0),
|
||||||
}
|
}
|
||||||
self.title(self._config.get("titre"))
|
|
||||||
self.canvas = Tk.Canvas(self,
|
|
||||||
width=self._config.get("taille")[0],
|
|
||||||
height=self._config.get("taille")[1],
|
|
||||||
background='white')
|
|
||||||
self.canvas.pack()
|
|
||||||
self.fractale = Figures(self)
|
self.fractale = Figures(self)
|
||||||
self.image = Image.new(
|
self.image = Image.new(
|
||||||
'RGB',
|
'RGB',
|
||||||
@ -290,7 +276,6 @@ class Turtle(Tk.Tk):
|
|||||||
255,
|
255,
|
||||||
255))
|
255))
|
||||||
self.draw = ImageDraw.Draw(self.image)
|
self.draw = ImageDraw.Draw(self.image)
|
||||||
self.sauvegarde = sauvegarde
|
|
||||||
self.resolution = resolution
|
self.resolution = resolution
|
||||||
|
|
||||||
def avance(self, distance):
|
def avance(self, distance):
|
||||||
@ -308,21 +293,16 @@ class Turtle(Tk.Tk):
|
|||||||
self._tourne(-angle)
|
self._tourne(-angle)
|
||||||
|
|
||||||
def goto(self, coordonnees):
|
def goto(self, coordonnees):
|
||||||
self.canvas.create_line(self._etat.get("coordx"),
|
|
||||||
self._etat.get("coordy"),
|
|
||||||
coordonnees[0],
|
|
||||||
coordonnees[1])
|
|
||||||
self._setCoords(coordonnees)
|
self._setCoords(coordonnees)
|
||||||
if self.sauvegarde:
|
|
||||||
self.draw.line(coordonnees)
|
self.draw.line(coordonnees)
|
||||||
|
|
||||||
def _setCoords(self, coordonnees):
|
def _setCoords(self, coordonnees):
|
||||||
self._etat["coordx"] = coordonnees[0]
|
self._etat["coordx"] = coordonnees[0]
|
||||||
self._etat["coordy"] = coordonnees[1]
|
self._etat["coordy"] = coordonnees[1]
|
||||||
|
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self._clear()
|
self._clear()
|
||||||
|
|
||||||
# ## Accès aux variables ##
|
# ## Accès aux variables ##
|
||||||
|
|
||||||
def setPosition(self, coordonnees):
|
def setPosition(self, coordonnees):
|
||||||
@ -350,9 +330,10 @@ class Turtle(Tk.Tk):
|
|||||||
def save(self, chemin, typeIMG=None):
|
def save(self, chemin, typeIMG=None):
|
||||||
self.image.save(chemin, typeIMG)
|
self.image.save(chemin, typeIMG)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
t = Turtle()
|
t = Turtle()
|
||||||
t.Init()
|
t.Init()
|
||||||
t.setPosition((0, 0))
|
t.setPosition((0, 0))
|
||||||
t.fractale.outline(6, 2, 5)
|
t.fractale.outline(6, 2, 5)
|
||||||
t.mainloop()
|
t.save("test.bmp")
|
||||||
|
Loading…
Reference in New Issue
Block a user