Skip to content

Instantly share code, notes, and snippets.

@auxiliary
Created July 1, 2016 20:07
Show Gist options
  • Save auxiliary/1ecbf36bf689e1f75e90e9569573d97d to your computer and use it in GitHub Desktop.
Save auxiliary/1ecbf36bf689e1f75e90e9569573d97d to your computer and use it in GitHub Desktop.
def seto(x, width, height):
c = GaussianControlPointList()
p = GaussianControlPoint()
p.x = x
p.width = width
p.height = height
c.AddControlPoints(p)
v = GetPlotOptions()
v.SetOpacityControlPoints(c)
SetPlotOptions(v)
def setfreeform(op):
v = GetPlotOptions()
v.SetFreeformOpacity(op)
SetPlotOptions(v)
def smoothCurve(opacities, factor=None, threshold = None):
opacities = list(opacities)
if factor == None:
factor = 1
if threshold == None:
threshold = 0.0
for _ in range(factor):
for i in range(1, len(opacities) - 1):
temp = (0.2 * opacities[i - 1]) + (0.6 * opacities[i]) + (0.2 * opacities[i + 1])
opacities[i] = 255.0 if temp > 255.0 else temp
opacities[i] = 0.0 if opacities[i] < threshold else opacities[i]
return tuple(opacities)
import itertools
# Best solution for the boston teapot
a = [0, 8, 0, 0, 6, 8, 8, 7, 94, 136, 181, 139, 127, 33, 181, 216]
a = tuple(itertools.chain.from_iterable([ [i]*16 for i in a ]))
a = smoothCurve(a, 1000)
setfreeform(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment