Skip to content

Instantly share code, notes, and snippets.

View AndersDeleuran's full-sized avatar

Anders Holden Deleuran AndersDeleuran

View GitHub Profile
foo = ["060X","059B","59","1"]
for i,item in enumerate(foo):
if len(item) == 2:
foo[i] = "0" + item
elif len(item) == 1:
foo[i] = "00" + item
if n:
b = ""
while (n>0):
nm = int(n%2)
b = str(nm)+b
n = (n-nm)/2
else:
b = "0"
if n:
b = ""
while (n>0):
nm = int(n%2)
b = str(nm)+b
n = (n-nm)/2
else:
b = "0"
foo = []
for i in range(3):
bar = []
for j in range(3):
bar.append(i*j)
foo.append(bar)
print foo
@AndersDeleuran
AndersDeleuran / gist:0fbe6512f5ef542ef1bd
Created May 3, 2015 09:51
MassAddition using For Loop
Sum = 0
Results = []
for v in Values:
Sum += v
Results.append(Sum)
""" Read the Grasshopper Datatree "tree" and translates it to
a nested Python list """
pyList = [list(b) for b in tree.Branches]
import Grasshopper as gh
def listToTree(nestedList):
""" Convert a nested python iterable to a datatree """
dt = gh.DataTree[object]()
for i,l in enumerate(nestedList):
dt.AddRange(l,gh.Kernel.Data.GH_Path(i))
import Rhino as rc
def mapValuesAsColors(values,srcMin,srcMax,targetMin,targetMax):
""" Make a list of HSL colors where the values are mapped onto a
targetMin-targetMax hue domain. Meaning that low values will be red, medium
values green and large values blue if targetMin: 0.0 and targetMax: 0.7 """
# Remap numbers into new numeric domain
remappedValues = []
from scriptcontext import sticky as st
import Rhino as rc
def customDisplay(toggle,component):
""" Make a custom display which is unique to the component and lives in sticky """
# Make unique name and custom display
displayGuid = "customDisplay_" + str(component.InstanceGuid)
if displayGuid not in st:
def sortCurvesByEuclideanCoords(crvs,t):
""" Sort a list of curves by Euclidean coordinates """
ptsOnCrvs = [crv.PointAt(t) for crv in crvs]
sortedBoth = sorted(zip(ptsOnCrvs,crvs))
sortedCrvs = [l[1] for l in sortedBoth]
return sortedCrvs