Skip to content

Instantly share code, notes, and snippets.

@kmcallister
Created June 14, 2017 22:40
Show Gist options
  • Select an option

  • Save kmcallister/0f18b776ad1be05bf99d02fe48b1139e to your computer and use it in GitHub Desktop.

Select an option

Save kmcallister/0f18b776ad1be05bf99d02fe48b1139e to your computer and use it in GitHub Desktop.
oscilloscope sierpinski triangle
#!/usr/bin/env python
import sys
import struct
import random
funcs = [
lambda (x, y): (x/2.0, y/2.0 + 1.0),
lambda (x, y): (x/2.0 - 1.0, y/2.0),
lambda (x, y): (x/2.0 + 1.0, y/2.0),
]
point = (0.0, 0.0)
scale = int((2**15 - 1) / 2.0)
while True:
sys.stdout.write(struct.pack('<hh',
int(point[0] * scale),
int(point[1] * scale)))
point = random.choice(funcs)(point)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment