A coffee cup and a doughnut

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

Information: A coffee cup and a doughnut