Created
December 27, 2016 01:01
-
-
Save Derfies/3c3b36c4891033173162ed79e8252810 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Cantor set done with nodebox-opengl. | |
# https://github.com/nodebox/nodebox-opengl/tree/master/nodebox/graphics | |
import random | |
import nodebox.graphics as nbg | |
STEP_HEIGHT = 20 | |
BUF_HEIGHT = 5 | |
MAX_DEPTH = 8 | |
def cantor( x, y, d, canvas ): | |
rx = x * canvas.width | |
ry = y * (STEP_HEIGHT + BUF_HEIGHT) | |
rd = d * canvas.width | |
nbg.rect( x=rx, y=ry, width=rd, height=STEP_HEIGHT ) | |
if y >= MAX_DEPTH: | |
return | |
y += 1 | |
newD = (d / 3.0) | |
cantor( x, y, newD, canvas ) | |
cantor( x + d * 2.0 / 3.0, y, newD, canvas ) | |
def draw( canvas ): | |
canvas.clear() | |
cantor( 0, 0, 1.0, canvas ) | |
nbg.canvas.size = 500, 500 | |
nbg.canvas.run( draw ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First attempt at doing some work with fractals. The cantor set seemed like an obvious choice and the nodebox-opengl lib makes drawing stuff nice and easy.