How to resolve the algorithm Bitmap/Bézier curves/Quadratic step by step in the XPL0 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Bitmap/Bézier curves/Quadratic step by step in the XPL0 programming language
Table of Contents
Problem Statement
Using the data storage type defined on this page for raster images, and the draw_line function defined in this one, draw a quadratic bezier curve (definition on Wikipedia).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Bitmap/Bézier curves/Quadratic step by step in the XPL0 programming language
Source code in the xpl0 programming language
include c:\cxpl\codes; \intrinsic 'code' declarations
proc Bezier(P0, P1, P2); \Draw quadratic Bezier curve
real P0, P1, P2;
def Segments = 8;
int I;
real T, A, B, C, X, Y;
[Move(fix(P0(0)), fix(P0(1)));
for I:= 1 to Segments do
[T:= float(I)/float(Segments);
A:= sq(1.-T);
B:= 2.*T*(1.-T);
C:= sq(T);
X:= A*P0(0) + B*P1(0) + C*P2(0);
Y:= A*P0(1) + B*P1(1) + C*P2(1);
Line(fix(X), fix(Y), $00FFFF); \cyan line segments
];
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);
];
[SetVid($112); \set 640x480x24 video graphics
Bezier([0., 0.], [80., 100.], [160., 20.]);
if ChIn(1) then []; \wait for keystroke
SetVid(3); \restore normal text display
]
You may also check:How to resolve the algorithm String concatenation step by step in the R programming language
You may also check:How to resolve the algorithm Greatest subsequential sum step by step in the Lua programming language
You may also check:How to resolve the algorithm Show ASCII table step by step in the Ecstasy programming language
You may also check:How to resolve the algorithm I'm a software engineer, get me out of here step by step in the Wren programming language
You may also check:How to resolve the algorithm Tree from nesting levels step by step in the Phix programming language