Bitmap/Bézier curves/Cubic: Difference between revisions

→‎{{header|XPL0}}: More efficient version
(→‎{{header|XPL0}}: More efficient version)
Line 1,009:
[[File:CubicXPL0.png|right]]
<lang XPL0>include c:\cxpl\codes; \intrinsic 'code' declarations
func real Power(X, Y); \X raised to the Y power; (X > 0.0)
real X, Y;
return Exp(Y * Ln(X));
 
proc Bezier(P0, P1, P2, P3); \Draw cubic Bezier curve
Line 1,017 ⟶ 1,014:
def Segments = 8;
int I;
real S1, T, AT2, BT3, CU, DU2, U3, B, C, X, Y;
[Move(fix(P0(0)), fix(P0(1)));
S1:= 1./float(Segments);
T:= 0.;
for I:= 1 to Segments-1 do
[T:= float(I)/float(Segments)T+S1;
AT2:= Power((1.-T), 3.)*T;
BT3:= 3.T2*T*Power((1.-T), 2.);
CU:= 3.*Power(T, 2.)*(1.-T);
DU2:= Power(T, 3.)U*U;
XU3:= AU2*P0(0) + B*P1(0) + C*P2(0) + D*P3(0)U;
YB:= A3.*P0(1) + B*P1(1) + C*P2(1) + DT*P3(1)U2;
C:= 3.*T2*U;
X:= U3*P0(0) + B*P1(0) + C*P2(0) + T3*P3(0);
Y:= U3*P0(1) + B*P1(1) + C*P2(1) + T3*P3(1);
Line(fix(X), fix(Y), $00FFFF); \cyan line segments
];
772

edits