Zack Aman

15 Feb 2015

Parametric Jellyfish by @zackaman is a rhinopython script for generating jellyfish with different bodies and tentacles.

The idea for the parametric jellyfish actually started as a flower.flower and vase

 

I thought a flower with a variable number and shape of petals along with some swirly stamens would make for a nice parametric object.  After doing the first (non-parametric) sketch above, however, I realized I mostly wanted to focus on the swirly bits, so I decided to turn it upside down and make it a jellyfish.

The script takes several variables: body height and width, number of tentacles, tentacle height, tentacle swirl, and tentacle bend. The tentacles are generated by creating an interpolated arc for each tentacle, and generating the points with a circle per bend, plus some randomness in height between circles and radius.

Some sketches (can’t figure out how to make WordPress not rotate these images):

A basic jellyfish, with a plain head, five tentacles, no swirl, and no bend in the tentacles:

jellyfish6

A slightly more complicated jellyfish, with three tentacles, no swirl, but a fair amount of bend:

jellyfish5

A nice pancake top jellyfish.  This one has a wide but shallow body and just a slight swirl and bend:

pancake

A complex jellyfish, with many tentacles, a large amount of bend a large amount of swirl:

jellyfish3

Python script code:

import rhinoscriptsyntax as rs
import math
import random

origin = (0,0,0)


#make jellyfish body
#get radius
#get height
bodyRadius = rs.GetInteger("Set radius (1-10)", 5, 1, 10)
print(bodyRadius)
bodyHeight = rs.GetInteger("Set body height (1-20)", 5, 1, 20)
print(bodyHeight)

#set three points to make interpolated curve: origin, origin + radius / height, some midpoint (half of height, random radius added)
bodyList = []
bodyList.append(origin)
midRadius = random.random() * bodyRadius
midpoint = (0, midRadius, 0 - (bodyHeight / 2))
bodyList.append(midpoint)
endpoint = (0, bodyRadius, 0 - bodyHeight)
bodyList.append(endpoint)
print(bodyList)
bodyLine = rs.AddInterpCurve(bodyList)

bodyAxis = [(0,0,0), (0,0,1)]
bodySurface = rs.AddRevSrf(bodyLine, bodyAxis)
print("bodySurface")
print(bodySurface)

#bodySolid = rs.OffsetSurface(bodySurface, 10, 0.01, False, True)
if rs.IsSurface(bodySurface):
    print("is a surface")
    #bodySolid = rs.OffsetSurface(bodySurface, 1)
    centerLine = rs.AddLine(bodyAxis[0], bodyAxis[1])
    bodySolid = rs.ExtrudeSurface(bodySurface, centerLine)
print("bodySolid")
print(bodySolid)


#make jellyfish tentacles
#get number of tentacles
tentacleNum = rs.GetInteger("How many tentacles? (1-10)", 5, 1, 10)
print(tentacleNum)
#get swirliness - 0 : num tentacles, governs how far over the tentacle wil move to the next circle
tentacleSwirl = rs.GetInteger("How much swirl? (0 - "+str(tentacleNum)+")", 0, 0, tentacleNum)
print(tentacleSwirl)
#get bendiness
tentacleBend = rs.GetInteger("How much bendiness in tentacles? (2-10)", 3, 2, 10)
print(tentacleBend)
#get height - use variation from 75% - 125%
tentacleHeight = rs.GetInteger("Set tentacle height (5-50)", 20, 5, 50)
print(tentacleHeight)

curHeight = -0.5
tentacleArc = math.radians(360 / tentacleNum)
curAngle = 0
tentaclePoints = []

#for bendiness, set up circle of points
for i in range(0, tentacleBend):
    #set up circle
    
    print(curHeight)
    bendPoints = []
    
    #place points around circle
    for j in range(0, tentacleNum):
        if(i == 0):
            curPoint = (0, 0, -1)
            bendPoints.append(curPoint)
        else:
            curRadius = random.randint(50, 150) / 100 * bodyRadius
            curPoint = (math.cos(curAngle)*curRadius,math.sin(curAngle)*curRadius,curHeight)
            bendPoints.append(curPoint)
            curAngle += tentacleArc
    
    tentaclePoints.append(bendPoints)
    
    curHeight -= abs(tentacleHeight/tentacleBend * 5 * random.random())
    
print tentaclePoints

#for each tentacle
for i in range(0, tentacleNum):
    curTentacle = []
    curIndex = i
    for j in range(0, tentacleBend):
        curTentacle.append(tentaclePoints[j][curIndex])
        curIndex += tentacleSwirl
        if(curIndex >= tentacleNum):
            curIndex = curIndex % tentacleNum
    
    print(curTentacle)
    
    
    
    tentacleRail = rs.AddInterpCurve(curTentacle)
    
    #tentacleCross = rs.AddCircle([(1,0,-1),(1,0, -1),(10,-1,-1), (0,1,-1)], 1)
    tentacleCross = rs.AddCircle((0,0,-1), 1)
    
    newTentacle = rs.AddSweep1(tentacleRail, [tentacleCross])
    rs.ExtrudeSurface(newTentacle, centerLine)

Repository with script and miscellaneous screenshots available on GitHub.

Embeds:

[sketchfab id=”03d454fa1d164dc7b3aea6b0f2cebf4a” start=”1″ spin=”1″ controls=”1″]

[sketchfab id=”a87d3265b3d147a1b3d7ac9fb26b667c” start=”1″ spin=”1″ controls=”1″]