Created
April 18, 2011 04:16
-
-
Save xydrolase/924806 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import math | |
## SETTINGS BELOW ## | |
# how many radiation lines to generate | |
DEGREE_STEP = 10 | |
# this detemines if the glass pattern is sparse or dense | |
POINTS_ON_RADIATION = 20 | |
# how much would the radiation line be twisted | |
TWISTING_ANGLE = 30 | |
# radius for the circle | |
R = 150 | |
# radius for drawing the dots | |
DOT_RADIUS = 1 | |
# draw auxiliary lines or not? | |
AUX_LINES = 0 | |
## CODE BELOW ## | |
size(4*R, 4*R) | |
translate(2*R, 2*R) | |
background(0.2) | |
stroke(0.4) | |
nofill() | |
fontsize(10) | |
# Reference circle | |
if AUX_LINES: | |
oval(-R, -R, 2*R, 2*R) | |
real_t_ang = 90 - TWISTING_ANGLE | |
offset_ang = 45 | |
for deg in range(0, 360, DEGREE_STEP): | |
rad = math.pi * deg / 180 | |
end_x, end_y = math.cos(rad) * R, math.sin(rad) * R | |
if AUX_LINES: | |
stroke(0.3) | |
line(0, 0, end_x, end_y) | |
R_bar = 0.5 * R / math.cos(real_t_ang*math.pi/180) | |
if TWISTING_ANGLE % 180 != 0: | |
ctrl_x, ctrl_y = R_bar * math.cos((deg-real_t_ang)*math.pi/180),\ | |
R_bar * math.sin((deg-real_t_ang)*math.pi/180) | |
# Draw the circle for twisted radiation | |
rel_x = end_x - ctrl_x | |
rel_y = end_y - ctrl_y | |
if rel_x > 0 and rel_y > 0: | |
end_rad = math.atan(rel_y/rel_x) | |
elif rel_x > 0 and rel_y < 0: | |
end_rad = math.atan(rel_y/rel_x) | |
elif rel_x < 0 and rel_y > 0: | |
end_rad = math.pi - abs(math.atan(rel_y/rel_x)) | |
else: | |
end_rad = math.pi + math.atan(rel_y/rel_x) | |
start_rad = end_rad + 2 * TWISTING_ANGLE * math.pi / 180 | |
stroke(0.3) | |
if AUX_LINES: | |
oval(ctrl_x-R_bar, ctrl_y-R_bar, R_bar*2, R_bar*2) | |
stroke(1.0) | |
for i in xrange(POINTS_ON_RADIATION): | |
seed_rad = start_rad + random() * (end_rad - start_rad) | |
x, y = math.cos(seed_rad) * R_bar + ctrl_x, \ | |
-(math.sin(seed_rad) * R_bar + ctrl_y) | |
oval(x-DOT_RADIUS, y-DOT_RADIUS, DOT_RADIUS*2, DOT_RADIUS*2) | |
else: | |
for i in xrange(POINTS_ON_RADIATION): | |
seed = random() | |
oval(seed*end_x-DOT_RADIUS, seed*end_y-DOT_RADIUS, | |
DOT_RADIUS*2, DOT_RADIUS*2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment