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:
|
||||
"""
|
||||
|
||||
|
||||
import math
|
||||
import time
|
||||
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
import tkinter as Tk
|
||||
|
||||
|
||||
class Figures():
|
||||
"""A lot of function to create some well-know shapes
|
||||
@ -204,14 +201,14 @@ class Figures():
|
||||
else:
|
||||
self._koch_curve(length)
|
||||
|
||||
class Turtle(Tk.Tk):
|
||||
|
||||
class Turtle():
|
||||
|
||||
### Fonctions internes ###
|
||||
|
||||
def _calcCentre(self, taille):
|
||||
return (taille[0] / 2, taille[1] / 2)
|
||||
|
||||
|
||||
# self.canvas.update()
|
||||
|
||||
def _avance(self, distance):
|
||||
@ -219,11 +216,6 @@ class Turtle(Tk.Tk):
|
||||
self._etat.get("coordx")
|
||||
AC = (distance * math.sin(math.radians(self._etat.get("angle")))) + \
|
||||
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._setCoords((AB, AC))
|
||||
# self.canvas.update()
|
||||
@ -255,8 +247,8 @@ class Turtle(Tk.Tk):
|
||||
self._etat["angle"] = self._etat.get("angle") - 360
|
||||
|
||||
def _clear(self):
|
||||
self.canvas.delete("all")
|
||||
self.canvas.update()
|
||||
pass
|
||||
|
||||
### Fonction publiques ###
|
||||
|
||||
def _clearIMG(self):
|
||||
@ -276,12 +268,6 @@ class Turtle(Tk.Tk):
|
||||
"coordy": self._config.get("centre")[1],
|
||||
"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.image = Image.new(
|
||||
'RGB',
|
||||
@ -290,7 +276,6 @@ class Turtle(Tk.Tk):
|
||||
255,
|
||||
255))
|
||||
self.draw = ImageDraw.Draw(self.image)
|
||||
self.sauvegarde = sauvegarde
|
||||
self.resolution = resolution
|
||||
|
||||
def avance(self, distance):
|
||||
@ -308,21 +293,16 @@ class Turtle(Tk.Tk):
|
||||
self._tourne(-angle)
|
||||
|
||||
def goto(self, coordonnees):
|
||||
self.canvas.create_line(self._etat.get("coordx"),
|
||||
self._etat.get("coordy"),
|
||||
coordonnees[0],
|
||||
coordonnees[1])
|
||||
self._setCoords(coordonnees)
|
||||
if self.sauvegarde:
|
||||
self.draw.line(coordonnees)
|
||||
|
||||
def _setCoords(self, coordonnees):
|
||||
self._etat["coordx"] = coordonnees[0]
|
||||
self._etat["coordy"] = coordonnees[1]
|
||||
|
||||
|
||||
def clear(self):
|
||||
self._clear()
|
||||
|
||||
# ## Accès aux variables ##
|
||||
|
||||
def setPosition(self, coordonnees):
|
||||
@ -350,9 +330,10 @@ class Turtle(Tk.Tk):
|
||||
def save(self, chemin, typeIMG=None):
|
||||
self.image.save(chemin, typeIMG)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
t = Turtle()
|
||||
t.Init()
|
||||
t.setPosition((0, 0))
|
||||
t.fractale.outline(6, 2, 5)
|
||||
t.mainloop()
|
||||
t.save("test.bmp")
|
||||
|
Loading…
Reference in New Issue
Block a user