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

Added XPL0
(Added XPL0)
Line 1:
{{task|Raster graphics operations}}
 
Using the data storage type defined [[Basic_bitmap_storage|on this page]] for raster images, and the <tt>draw_line</tt> function defined in [[Bresenham's_line_algorithm|this other one]], draw a '''cubic bezier curvescurve'''
([[wp:Bezier_curves#Cubic_B.C3.A9zier_curves|definition on Wikipedia]]).
 
Line 855:
EndFor
EndPrgm</lang>
 
=={{header|XPL0}}==
[[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
real P0, P1, P2, P3;
def Segments = 8;
int I;
real T, A, B, C, D, X, Y;
[Move(fix(P0(0)), fix(P0(1)));
for I:= 1 to Segments-1 do
[T:= float(I)/float(Segments);
A:= Power((1.-T), 3.);
B:= 3.*T*Power((1.-T), 2.);
C:= 3.*Power(T, 2.)*(1.-T);
D:= Power(T, 3.);
X:= A*P0(0) + B*P1(0) + C*P2(0) + D*P3(0);
Y:= A*P0(1) + B*P1(1) + C*P2(1) + D*P3(1);
Line(fix(X), fix(Y), $00FFFF); \cyan line segments
];
Line(fix(P3(0)), fix(P3(1)), $00FFFF);
Point(fix(P0(0)), fix(P0(1)), $FF0000); \red control points
Point(fix(P1(0)), fix(P1(1)), $FF0000);
Point(fix(P2(0)), fix(P2(1)), $FF0000);
Point(fix(P3(0)), fix(P3(1)), $FF0000);
];
 
[SetVid($112); \set 640x480x24 video graphics
Bezier([0., 0.], [30., 100.], [120., 20.], [160., 120.]);
if ChIn(1) then []; \wait for keystroke
SetVid(3); \restore normal text display
]</lang>
 
{{omit from|GUISS}}
772

edits