Skip to content

Instantly share code, notes, and snippets.

@JokerMartini
Last active July 5, 2017 14:18
Show Gist options
  • Save JokerMartini/126f9334c6ec4b93ce22 to your computer and use it in GitHub Desktop.
Save JokerMartini/126f9334c6ec4b93ce22 to your computer and use it in GitHub Desktop.
Maxscript: This code demonstrates how to create a curve both inward and outward, allowing users to transition between the outer curve - linear - inner curve.
try(destroyDialog rlTest)catch()
rollout rlTest "test"
(
spinner uiWidth "Width" range:[-1e6,1e6,15.0] type:#worldUnits
spinner uiHeight "Height" range:[-1e6,1e6,5.0] type:#worldUnits
spinner uiSmoothness "Smoothness" range:[-1e3,1e3,0] type:#float
spinner uiSamples "Samples" range:[1,1e4,6] type:#integer
spinner uiDegrees "Degrees" range:[0,180,180] type:#float
fn BuildArc =
(
numSteps = uiSamples.value --20
height = uiHeight.value --radius
width = uiWidth.value--30.0 --radius
smoothness = uiSmoothness.value
degrees = uiDegrees.value
delete objects
for i = 0 to numSteps do
(
ang = (degrees / numSteps) * i
/* Circular Calculations */
xCircular = -1 * width/2.0 * cos(ang) --multiplied by -1 to flip horizontal
yCircular = height * sin(ang)
/* Inverted Calculations */
halfwidth = width * 0.5
if ang > 90 then
(
xAstroid = -halfWidth * cos(ang - 90) + halfWidth
yAstroid = -height * sin(ang - 90) + height
)
else
(
xAstroid = halfWidth * cos(ang - 90) - halfWidth
yAstroid = height * sin(ang - 90) + height
)
posC = [xCircular,yCircular,0] + [width/2.0,0,0]
point pos:posC size:1 cross:true box:false wirecolor:green
posA = [xAstroid,yAstroid,0] + [width/2.0,0,0]
point pos:posA size:1 cross:true box:false wirecolor:yellow
/* Blend Calculations */
smoothy = (smoothness * .5 ) + .5 --normalize smooth value to 0 is linear
posB = ((posC - posA)*smoothy) + posA
point pos:posB size:1 cross:true box:true wirecolor:red
)
--circle radius:15 pos:[0,15,0]
--circle radius:15 pos:[15,0,0]
)
on uiWidth changed val do
(
BuildArc()
completeRedraw()
)
on uiHeight changed val do
(
BuildArc()
completeRedraw()
)
on uiSmoothness changed val do
(
BuildArc()
completeRedraw()
)
on uiSamples changed val do
(
BuildArc()
completeRedraw()
)
on uiDegrees changed val do
(
BuildArc()
completeRedraw()
)
)
createdialog rlTest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment