Hi all,
I don’t actually know much about Rhino (yet). I’ve been playing around on it for a few months now (the mac version). I recently coded a python script that generates snowflakes (using a simplified algorithm by Reiter). And I have success in that the code generates the ‘points’ in Rhino that look like unique snowflakes. However, I’m stuck currently with a bunch of points and need help to do the final steps to make this a solid item that I can eventually send to a 3d printer.
The options I see for turning this snowflake/group of points is either:
- If someone knows a trick (without scripting knowledge) to make this a solid object, that looks like the original snowflake?
- Someone can think of a better idea how to modify my code to instead of creating points, create another output in Rhino that would make it easier to create a solid shape after.
So I will show the code (first time using Python so excuse the inefficiencies in the code), I will also show you the zoomed in version of points and the zoomed out version of the points (that look like a unified snowflake). I have played with a few surface creating commands in Rhino but since I really am not too familiar with Rhino functions, I haven’t been able to catch the intricacies of the file.
ANY IDEAS? I appreciate the help much in advance!
Lauren
Here is the python code: snownewgrid-spacialfinal.py (4.9 KB)
Here is zoomed in, produced dots:
Here is zoomed out, dots (visual of what I hope to 3d print):
Here is the results after a few meshing/surface functions (you can see no intricacies in the tips of the snowflake):
Python/Rhino Code for Random Snowflake Generation (using Reiter Algorithm and referencing a code on the internet from another person).
NOTE: it takes about 10 minutes to compile, and I’m sorry for the formatting below… all the comments in python become bold below.
import rhinoscriptsyntax as rs
import random
import math
from operator import add
snowflake will differ depending on values of these parameters:
alpha = random.random()
beta = random.random() * 0.7
gamma = random.random()/100
#alpha=1
print('alpha ', alpha,'beta ',beta, 'gamma ',gamma)
#see snowflake space by testing out point generation
SPACIAL TESTING
mx=251 #left right in matrix (x axis, row value)
my=253 #up down size double the size of actual snowflake
z=1
xfactor=random.random()*5 #to make them orient at different spots each time
x1=1
x2=2
y1=1
points=
#mx is row
compute the cellular growth
flake=[[beta for x in range(0,my)] for y in range(0,mx)] #7 columns, 5 rows
#set all particles at the background value
#make every second element 0 and staggered in each row to accomodate hexagonal geometry
for x in range(0,mx): row x
for y in range(0,my): #column y
if x%2!=0 and y%2!=0: row is odd and column is odd, then only space holder
flake[y]=0
elif y%2==0 and x%2==0: row is even and column is even, then only space holder
flake[y]=0
if ((mx-1)//2)%2==0 and ((my-1)//2)%2==0:
print(‘your mx and my are not good, please select ones with even,odd center so that point exists’)
if ((mx-1)//2)%2!=0 and ((my-1)//2)%2!=0:
print(‘your mx and my are not good, please select ones with even,odd center so that point exists’)
flake[(mx-1)//2][(my-1)//2]=1 #at center there will be a 1
print(flake)
n=1
while n<100:
receptive=[[0 for x in range(my)] for y in range(mx)]
nreceptive=[[0 for x in range(my)] for y in range(mx)]
diff=[[beta for x in range(my)] for y in range(mx)]
for x in range(0,mx): row x
for y in range(0,my): #column y
if x%2!=0 and y%2!=0: row is odd and column is odd, then only space holder
receptive[y]=0
nreceptive[y]=0
diff[y]=0
elif y%2==0 and x%2==0: row is even and column is even, then only space holder
receptive[y]=0
nreceptive[y]=0
diff[y]=0
for x in range(0,mx): for y in range(0,my): if (x%2!=0 and y%2==0) or (x%2==0 and y%2!=0): #odd/even or even/odd row/column then exsts #find receptive cells if flake[x][y]>=1: # ice receptive[x][y]=1
# check up, down, left, right, diag up left, diag lower left (hexagon 3-axis diffusion) elif x>0 and y>0 and flake[x-1][y-1]>=1:#upper left point receptive[x][y]=1 elif x<(mx-1) and y>0 and flake[x+1][y-1]>=1:#down left point receptive[x][y]=1 elif y>1 and flake[x][y-2]>=1:#left receptive[x][y]=1 elif y<(my-2) and flake[x][y+2]>=1:#right receptive[x][y]=1 elif x>0 and y<(my-1) and flake[x-1][y+1]>=1:#upper right point receptive[x][y]=1 elif x<(mx-1) and y<(my-1) and y>0 and flake[x+1][y+1]>=1:#down right point receptive[x][y]=1 else: receptive[x][y]=0 nreceptive[x][y]=flake[x][y] flake[x][y]=0 print(receptive,nreceptive,flake)
# if receptive, add gamma humidity value (accounts for 3rd dimension humidity input) diffx=mx-1 #so don't breach boundaries of matrix for diffussion diffy=my-2 for x in range(1,diffx): for y in range(1,diffy): if (x%2!=0 and y%2==0) or (x%2==0 and y%2!=0): #odd/even or even/odd row/column then exsts diff[x][y]=(1-alpha)*nreceptive[x][y]+(alpha/6)*(nreceptive[x-1][y-1]+nreceptive[x+1][y-1]+nreceptive[x][y-2]+nreceptive[x][y+2]+nreceptive[x-1][y+1]+nreceptive[x+1][y+1])
#dont want to update nreceptive yet because used in calculation if receptive[x][y]==1: flake[x][y]=flake[x][y]+gamma for x in range(0,mx): for y in range(0,my): if (x%2!=0 and y%2==0) or (x%2==0 and y%2!=0): #odd/even or even/odd row/column then exsts flake[x][y]=flake[x][y]+diff[x][y] n=n+1
print(flake)
mxnew=mx-2
mynew=my-2
rs.EnableRedraw(False)
for x in range(0,mxnew):
for y in range(0,mynew):
if flake[y]>=1:
if flake[y]>=1: #if even, and ice (flake>1)
# original xy plot pt=(y0.7,x,z)
pt=(y0.7,x,z)
#x2=x2+2*x
points.append(pt)
rs.AddPoint(pt)
print points
#rs.AddPoint(pt)
#pt=(i-75,j-75,z)
points.append(pt)
#rs.AddPoint(pt)
rs.Redraw()