Skip to content

Instantly share code, notes, and snippets.

@co60ca
Last active August 29, 2015 14:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save co60ca/5f697917c0f8cfe4ec66 to your computer and use it in GitHub Desktop.
Save co60ca/5f697917c0f8cfe4ec66 to your computer and use it in GitHub Desktop.
'''
See more of my content at https://co60.ca
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Usage: import the module, run main
'''
from tkinter import *
WIDTH = 1366
HEIGHT= 768
SPACING = 10
LINE_WIDTH = 3
master = Tk()
w = Canvas(master, width=WIDTH, height=HEIGHT, bg="#000000")
w.pack()
stack = []
def main(depth):
stack.append((WIDTH/2, HEIGHT/2, True, depth))
while stack:
nextitem = stack.pop(0)
try:
stack.index(nextitem)
stack.remove(nextitem)
except ValueError:
draw_fract_lines(nextitem[0], nextitem[1], nextitem[2], nextitem[3])
def draw_fract_lines(startx, starty, verticle, depth):
'''Stop fractalizing at depth = 0, draw two lines from
startx, starty, in a verticle manor
'''
if (verticle):
x1 = startx
x2 = startx
y1 = starty + SPACING
y2 = starty - SPACING
else:
x1 = startx + SPACING
x2 = startx - SPACING
y1 = starty
y2 = starty
w.create_line(x1, y1, x2, y2, fill="#ffffff", width=LINE_WIDTH)
if (depth > 0):
stack.append((x1, y1, not verticle, depth - 1))
stack.append((x2, y2, not verticle, depth - 1))
@co60ca
Copy link
Author

co60ca commented May 20, 2015

Now is iterative so does not fail after 52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment