Snake 2 (Script)
- Author:
- Thijs
Creating Script (button: buttCreate)
#===========================================================
# Create Regular Dodecahedron.
# Why do it the easy way when you can do it difficult?
#===========================================================
ϕ = (1+sqrt(5))/2
LP04= Zip(Zip((sx*ϕ, sy/ϕ, 0), sx,{-1,1}), sy,{-1,1})
LP12= Zip(Rotate(LP04, k*120°, Line((0,0,0),(1,1,1))), k,0…2)
LP08= Zip(Zip(Zip((sx,sy,sz), sx,{-1,1}), sy,{-1,1}), sz,{-1,1})
LP20= Rotate(1.5*Join({Flatten(LP08), Flatten(LP12)}), atand(1/ϕ), xAxis)
Lmn = RemoveUndefined(Flatten(Zip(Zip(If(m>n, (m,n)), n,1…20), m,1…20)))
Lseg= Zip(Segment(LP20(x(mn)), LP20(y(mn))), mn,Lmn)
Dodeca= RemoveUndefined(Zip(If(S<2, S), S,Lseg))
#===========================================================
# The Route, Velocity and Acceleration of the snake.
#===========================================================
Rx(t)= (cos(5t) + 2)*cos(2t)
Ry(t)= (cos(5t) + 2)*sin(2t)
Rz(t)= -sin(5t)
R(t) = Curve((Rx(t), Ry(t), Rz(t)), t, 0, 2*pi)
V(t) = Derivative(R, 1)
A(t) = Derivative(R, 2)
#===========================================================
# Tangent, Normal and Binormal of the route.
#===========================================================
LV(t) = sqrt( x(V(t))^2 + y(V(t))^2 + z(V(t))^2)
VxA(t) = Curve(Cross(V(t),A(t)), t, 0, 2*pi)
LVxA(t)= sqrt( x(VxA(t))^2 + y(VxA(t))^2 + z(VxA(t))^2)
T(t) = Curve(V(t) / LV(t), t, 0, 2*pi)
B(t) = Curve(VxA(t) / LVxA(t), t, 0, 2*pi)
N(t) = Curve(Cross(B(t),T(t)), t, 0, 2*pi)
#===========================================================
# The moving Snake.
#===========================================================
t = Slider(0°, 360°, 0.1°, 0.5, 100, true, true, true)
Lf = Zip(0.93^k, k, 0…40)
snake = Zip(Sphere(R(t+f), f / 2), f, Lf)
skel = Zip(Vector(R(t+f) - 0.55*f*B(t+f), R(t+f) + 0.9*f*B(t+f)), f,Lf)
eye1 = Sphere(R(t+1) + 0.3*T(t+1) + 0.25*N(t+1) + 0.25*B(t+1), 0.1)
eye2 = Sphere(R(t+1) + 0.3*T(t+1) - 0.25*N(t+1) + 0.25*B(t+1), 0.1)
mouth = Sphere(R(t+1) + 0.1*T(t+1) - 0.05*B(t+1), 0.375 + 0.035*sin(7t))
#===========================================================
# Settings.
#===========================================================
L1={"ϕ","LP04","LP12","LP08","Lmn","Lseg","Rx","Ry","Rz"}
L2={"R","V","A","LV","VxA","LVxA","T","B","N"}
L3={"LP20","Dodeca","snake","skel","eye1","eye2","mouth"}
Execute[Zip["SetConditionToShowObject["+L+",false]", L,L1]]
Execute[Zip["SetConditionToShowObject["+L+",false]", L,L2]]
Execute[Zip["ShowLabel["+L+",false]", L,L3]]
Delete[L1]
Delete[L2]
Delete[L3]
SetActiveView[-1]
SetBackgroundColor[0, 0, 0.05]
CenterView[(0, 0 ,0)]
ShowAxes[false]
SetColor(LP20 , "#FFEFD5")
SetColor(Dodeca, "#FFFACD")
SetColor(snake , "#FFCC33")
SetColor(skel , "#FFFFFF")
SetColor(eye1 , "#DC143C")
SetColor(eye2 , "#DC143C")
SetColor(mouth , "#330000")
SetFilling[snake, 1]
SetFilling[eye1 , 0.85]
SetFilling[eye2 , 0.85]
SetFilling[mouth, 1]
SetPointSize[LP20, 3]
SetLineThickness[Dodeca, 8]
SetLineThickness[skel , 9]
SetSpinSpeed[-1]
StartAnimation[t,true]
#===========================================================
# t: Animation Repeat => Increasing
# Perspective: Distance from screen: 800
# Clipping box size: Large
# button: Edit: \ovalbox{Rotate}
# Medium, Bold
# LaTeX formula
# Color: White
# Location: Graphics and 3D Graphics
# Position: Absolute Position on Screen
# Scripting: SetSpinSpeed[-1]
# StartAnimation[t,true]
#===========================================================