%y

side = 0 (slider from 0 to 1, step 1)
f(x) = x^(3) / 3 - (2 * x^(2)) + 12
x1 = -2
x2 = 7
n = 20
dx: (x2 - x1) / n
fpoints = Sequence((x1 + ((i + side) * dx), f(x1 + ((i + side) * dx))), i, 0, n)
flines = Sequence(Segment[Element[fpoints, i] - (side * (dx, 0)), Element[fpoints, i] + ((1 - side) * (dx, 0))], i, 1, n)
D = (-0.19058672812471114, 10.040429664405792)
G = Element(First[RemoveUndefined[Sequence[Intersect[Element[flines, i], OrthogonalLine[(Max[x1, Min[x2, x(D)]], 0), xAxis]], i, 1, n]]], 1)
g: x = x1
h: x = x2
maxn = 1000
A = DynamicCoordinates(D, x(G), y(G))
E: (If[x(A)  <  x2 - dx, (floor((x(A) - x1) / dx) * dx) + x1, x2 - dx], y(A))
highlightseg1 = Segment(E, E + (dx, 0))
c: x(E)
fc: y(E)
poly1, e1, i, j, k = Polygon(E, E + (dx, 0), (x(E) + dx, 0), (x(E), 0))
fcdx: (fc * dx)
cp1: c + dx
rsum = RectangleSum(f, x1, x2, n, side)
defint = Integral(f, x1, x2)
xmax = 7.610547990878307
xmin = -2.6617536266908846
ymin = -4.290651119751125
ymax = 32.56069946808095
LL = Corner(1)
UR = Corner(3)
leftRightSum: "" + (If[side ≟ 1, "right", "left"]) + " sum"
fEquation: "f(x)=" + (LaTeX[f]) + ""
xcEquation: "x=" + (LaTeX[c]) + ""
xcp1Equation: "x=" + (LaTeX[cp1]) + ""
fcp1: f(cp1)
xRectHeight = If(side ≟ 1, cp1, c)
rectHeight: f(xRectHeight)
rectangleHeightEquation: "f(" + xRectHeight + ") = " + rectHeight + ""
rectArea: (rectHeight * dx)
DeltaxEquation: "\Delta x=" + (LaTeX[dx]) + ""
leftRight = If(side ≟ 1, "right", "left")
x1Equation: "x = " + x1
x2Equation: "x=" + x2
nEquation: "n=" + n
riemannSumCalculation: "\begin{align*}\text{Area} &= \sum_{i=1}^{" + n + "}f(x_i)\Delta x =" + rsum + "\end{align*}"
definiteIntegralEquation: "\begin{align*}\text{Area} = \int_{" + x1 + "}^{" + x2 + "} f(x)\,dx = " + defint + "\end{align*}"
intervalEquation: "[a,b]=[" + (LaTeX[x1]) + "," + (LaTeX[x2]) + "]"
rectangleAreaCalculation: "\begin{align*}\text{Rectangle area} &= f(" + xRectHeight + ")\Delta x\\&= " + (LaTeX[rectHeight]) + "\cdot " + (LaTeX[dx]) + "=" + (LaTeX[rectArea]) + "\end{align*}"