A coffee cup and a doughnut
GGB Script
#-------------------------
# Stuff for animation
# Based upon Bernat's work
#-------------------------
top = Slider(0, 4, 1, 1, 200, false, true, false, false)
SetValue(top, 4)
SetVisibleInView(top, 1, false)
speed = 0.89
k = Slider(0, top, 0.01, speed, 200, false, true, false, false)
SetCaption(k, "Change")
sl = Sequence(Max(0, Min(1, k - s)), s, 0, top-1)
mb = 1
mc = 2
#-------------------------
# Auxiliar base for cylinder
#-------------------------
A = (-2.5, 0, 0)
B = (-3.5, 0, -0.3) * Element(sl, mc) + (1 - Element(sl, mc)) * (-5, 0, -4)
C = (x(B) - x(B) * 0.06, y(B), z(B)) * Element(sl, mc) + (1 - Element(sl, mc)) * (x(B)- x(B) * 0.06, y(B), z(B))
#-------------------------
# Cup exterior
#-------------------------
r1 = 1 * Element(sl, mc) + (1 - Element(sl, mc)) * 2.5
max = 0.3 * Element(sl, mc) + (1 - Element(sl, mc)) * 3
min = -0.3 * Element(sl, mc) + (1 - Element(sl, mc)) * (-4)
gx(x, y) = r1 cos(x) - 2.5
gy(x, y) = r1 sin(x)
gz(x, y) = y
cylOut = Surface(gx(u, v), gy(u, v), gz(u,v), u, 0, 2pi, v, min, max)
#-------------------------
# Base
#-------------------------
BT = (x(B), y(B), z(B) + (max - min))
CT = (x(C), y(C), z(C) + (max - min))
f = PerpendicularLine(A, xOyPlane)
c = Circle(f, B)
#-------------------------
# First top cover
#-------------------------
AR = (-0.3, 0, 3)
BR = (0, 0, 3)
ARB = AR * Element(sl, mb) + (1 - Element(sl, mb)) * (-0.3, 0, -3.8)
d = Circle(f, ARB)
#-------------------------
# Cup interior
#-------------------------
r2 = (r1 - r1 * 0.1) * Element(sl, mc) + (1 - Element(sl, mc)) * (r1 - r1 * 0.1)
hx(x, y) = r2 cos(x) - 2.5
hy(x, y) = r2 sin(x)
hz(x, y) = y
cylIn = Surface(hx(u, v), hy(u, v), hz(u,v), u, 0, 2pi, v, min, max)
#-------------------------
# Second top cover
#-------------------------
u = Vector(CT, BT)
b = Curve(x(CT) + t x(u), y(CT) + t y(u), z(CT) + t z(u), t, 0, 1)
topCup = Surface(b, 2π, f)
cover = Circle(f, CT)
#-------------------------
# Finally the tori
#-------------------------
at = 1.5 * Element(sl, mc) + (1 - Element(sl, mc)) * 0.4
ct = 3 * Element(sl, mc) + (1 - Element(sl, mc)) * 2
fx(x, y) = (ct+ at * cos(y)) * cos(x)
fy(x, y) = -at * sin(y)
fz(x, y) = (ct+ at * cos(y)) * sin(x)
maxT = If(k<1, pi/2 + 0.05, pi)
#pi * Element(sl, 2) + (1 - Element(sl, 2)) * (pi/2 + 0.05)
minT = If(k<1, -pi/2 - 0.05, -pi)
#-pi * Element(sl, 2) + (1 - Element(sl, 2)) * (-pi/2 - 0.05)
t = Surface(fx(u, v), fy(u, v), fz(u,v), u, minT, maxT, v, -pi, pi+0.5)
tRot = If(2<k<=3, Rotate(t, -k*pi/2, xAxis), Rotate(t, -pi/2, xAxis))
acho = 1.5
ccho = 3
ex(x, y) = 1.0099 *(ccho+ acho * cos(y)) * cos(x)
ey(x, y) = 1.0099 *(ccho+ acho * cos(y)) * sin(x)
ez(x, y) = -1.0099 *acho * sin(y)
choc = Surface(ex(u, v), ey(u, v), ez(u,v), u, 0, 2 pi, v, pi, 2 pi)
#-------------------------
# Sprinkles
#-------------------------
Execute(Sequence("A"+k+" = choc(random() * 2 pi, RandomUniform(pi, 2 pi))", k, 1, 70))
Execute(Sequence("SetDynamicColor(A"+k+" , "+k+" /50, 1, 0.7)", k, 1, 70))
Execute(Sequence("ShowLabel(A"+k+" , false)", k, 1, 70))
Execute(Sequence("SetConditionToShowObject(A"+k+" , 3.3<k && k<=4)", k, 1, 70))
#-------------------------
# Some extra settings
#-------------------------
SetVisibleInView(A, -1, false)
SetVisibleInView(B, -1, false)
SetVisibleInView(C, -1, false)
SetVisibleInView(AR, -1, false)
SetVisibleInView(ARB, -1, false)
SetVisibleInView(BR, -1, false)
SetVisibleInView(BT, -1, false)
SetVisibleInView(CT, -1, false)
SetVisibleInView(gx, -1, false)
SetVisibleInView(gy, -1, false)
SetVisibleInView(gz, -1, false)
SetVisibleInView(hx, -1, false)
SetVisibleInView(hy, -1, false)
SetVisibleInView(hz, -1, false)
SetVisibleInView(fx, -1, false)
SetVisibleInView(fy, -1, false)
SetVisibleInView(fz, -1, false)
SetVisibleInView(ex, -1, false)
SetVisibleInView(ey, -1, false)
SetVisibleInView(ez, -1, false)
SetVisibleInView(u, -1, false)
SetVisibleInView(b, -1, false)
SetConditionToShowObject(t, k<=2)
SetConditionToShowObject(tRot, 2<k)
SetConditionToShowObject(cylIn, k<=2)
SetConditionToShowObject(cylOut, k<=2)
SetConditionToShowObject(topCup, k<=2)
SetConditionToShowObject(c, k<=2)
SetConditionToShowObject(choc, 3<k && k<=4)
SetConditionToShowObject(cover, k > 1)
SetConditionToShowObject(d, k <= 1)
SetLineThickness(c, 0.05)
SetLineThickness(cover, 0.05)
SetLineThickness(d, 0.05)
hue = If(k>=2, 336/360, 0)
sat = If(k>=2, 1, 0)
val = If(k>=2, 0.65, 0.9)
SetDynamicColor(c, hue, sat, val, 1)
SetDynamicColor(cover, hue, sat, val, 1)
SetDynamicColor(d, hue, sat, val, 1)
SetDynamicColor(cylIn, hue, sat, 0.8, 1)
SetDynamicColor(cylOut, hue, sat, val, 1)
SetDynamicColor(t, hue, sat, val, 1)
SetDynamicColor(topCup, hue, sat, val, 1)
SetDynamicColor(tRot, hue, sat, val, 1)
StartAnimation(k, true)