Created
June 21, 2016 17:49
-
-
Save auxiliary/c25256fea72771a4e3581b243d34ca8f 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
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, 20, 5) | |
setfreeform(a) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment