Bitmap/Bézier curves/Quadratic: Difference between revisions
Content added Content deleted
(Added solution for MATLAB) |
(Added XPL0) |
||
Line 1: | Line 1: | ||
{{task|Raster graphics operations}} |
{{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 one]], draw a ''quadratic bezier |
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 one]], draw a ''quadratic bezier curve'' |
||
([[wp:Bezier_curves#Quadratic_B.C3.A9zier_curves|definition on Wikipedia]]). |
([[wp:Bezier_curves#Quadratic_B.C3.A9zier_curves|definition on Wikipedia]]). |
||
Line 556: | Line 556: | ||
} |
} |
||
return</lang> |
return</lang> |
||
=={{header|XPL0}}== |
|||
[[File:QuadXPL0.png|right]] |
|||
<lang XPL0>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 |
|||
]</lang> |
|||
{{omit from|GUISS}} |
{{omit from|GUISS}} |