Skip to content

Instantly share code, notes, and snippets.

@zarazum
Created September 1, 2014 10:18
Show Gist options
  • Save zarazum/0db3f6681077e524c255 to your computer and use it in GitHub Desktop.
Save zarazum/0db3f6681077e524c255 to your computer and use it in GitHub Desktop.
subdivtri.py
from scene import *
from random import random
from math import sin, cos, pi
class zScene (Scene):
def setup(self):
# This will be called before the first frame is drawn.
# Set up the root layer and one other layer:
self.root_layer = Layer(self.bounds)
r = min(self.bounds.w,self.bounds.h)/2
center = self.bounds.center()
self.layer = Layer(Rect(center.x - r, center.y - r, 2*r, 2*r))
self.layer.background = Color(1, 1, 1)
self.layer.stroke = Color(0,0,0)
self.layer.stroke_weight = 1
self.root_layer.add_layer(self.layer)
def draw(self):
# Update and draw our root layer. For a layer-based scene, this
# is usually all you have to do in the draw method.
background(0, 0, 0)
self.root_layer.update(self.dt)
self.root_layer.draw()
def touch_began(self, touch):
#x = touch.location.x
#y = touch.location.y
if not (touch.layer == self. root_layer):
tf=touch.layer.frame
w2=tf.w/2
h2=tf.h/2
R = w2
r=R*sin(pi/3)
tx=tf.x
ty=tf.y
cx=tf.center().x
cy=tf.center().y
#touch.layer.frame = Rect(tx, ty, w2, h2)
ss="""
for i in range(4):
lx=tx+(i&1)*w2
ly=ty+(i&2)/2*h2
layer=Layer(Rect(lx,ly,w2,h2))
layer.background = Color(1,1,1)
layer.stroke = Color(0,0,0)
layer.stroke_weight = 1
self.root_layer.add_layer(layer)"""
#fill(0.5,1,0.5,0.8)
cr = R * (1-sin(pi/3)/2)
rot = 2 * pi * random()
for i in range(3):
x = cx + cr*cos(i*2*pi/3+rot) - r/2
y = cy + cr*sin(i*2*pi/3+rot) - r/2
layer=Layer(Rect(x,y,r,r))
#ellipse(x,y,r,r)
layer.background = Color(0.5,1,0.5,0.8)
#layer.stroke = Color(1,1,1,0.5)
#layer.stroke_weight = 1
self.root_layer.add_layer(layer)
touch.layer.remove_layer()
def touch_moved(self, touch):
pass
def touch_ended(self, touch):
pass
run(zScene())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment