Skip to content

Instantly share code, notes, and snippets.

@Derfies
Created December 27, 2016 01:01
Show Gist options
  • Save Derfies/3c3b36c4891033173162ed79e8252810 to your computer and use it in GitHub Desktop.
Save Derfies/3c3b36c4891033173162ed79e8252810 to your computer and use it in GitHub Desktop.
# 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 )
@Derfies
Copy link
Author

Derfies commented Dec 27, 2016

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.

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