Created
June 2, 2015 17:18
-
-
Save adusak/8f6edb16ad3d7c791a91 to your computer and use it in GitHub Desktop.
Start
This file contains hidden or 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
import copy | |
import numpy as np | |
from python.common.point import Point | |
from python.common.svg import Svg | |
from python.less9.transformations import scaling | |
def star(size, iterations=1000): | |
transformations = [np.matrix([[0.255, 0.0, 0.3726], | |
[0.0, 0.255, 0.6714], | |
[0, 0, 1]]), | |
np.matrix([[0.255, 0.0, 0.1146], | |
[0.0, 0.255, 0.2232], | |
[0, 0, 1]]), | |
np.matrix([[0.255, 0.0, 0.6306], | |
[0.0, 0.255, 0.2232], | |
[0, 0, 1]]), | |
np.matrix([[0.370, -0.642, 0.6356], | |
[0.642, 0.370, -0.0061], | |
[0, 0, 1]])] | |
probabilities = [0.07, 0.30, 0.33, 0.30] | |
points = [] | |
current = Point(0, 0) | |
points.append(current) | |
for iteration in range(iterations): | |
index = np.random.choice(4, 1, p=probabilities)[0] | |
transformation = transformations[index] | |
copy_p = copy.deepcopy(current) | |
copy_p.apply_transformation(transformation) | |
current = copy_p | |
if iteration > 200: | |
points.append(copy_p) | |
svg = Svg() | |
list(map(lambda y: y.draw_to_svg(svg), map(lambda x: x.apply_transformation(scaling(size, size)), points))) | |
svg.save("output/" + "crystal") | |
star(1500, 100000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment