Created
September 4, 2014 08:09
-
-
Save zarazum/79ea753040448086bb8c to your computer and use it in GitHub Desktop.
subdivtriviz.py
This file contains 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
from scene import * | |
from random import random | |
from math import sin, cos, pi | |
BOXFILL = Color(0.5,1,0.5,0.8) | |
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 = BOXFILL | |
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) | |
#visualize stuff | |
x=0 | |
for l in self.root_layer.sublayers: | |
stroke(0,1,0) | |
stroke_weight(1) | |
line(x,0,x,l.frame.h) | |
stroke(0,0,1) | |
line(x,l.frame.h+1,x,l.frame.h+1+l.rotation/360*40) | |
x += 2 | |
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 = BOXFILL | |
layer.rotation = rot/2/pi*360 | |
#layer.stroke = Color(1,1,1,0.5) | |
#layer.stroke_weight = 1 | |
self.root_layer.add_layer(layer) | |
# print(len(self.root_layer.sublayers)) | |
touch.layer.remove_layer() | |
def touch_moved(self, touch): | |
pass | |
def touch_ended(self, touch): | |
pass | |
run(zScene(),PORTRAIT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment