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

Content deleted Content added
m Fixed lang tags.
Line 6:
 
=={{header|Ada}}==
<lang ada>procedure Quadratic_Bezier
procedure Quadratic_Bezier
( Picture : in out Image;
P1, P2, P3 : Point;
Line 29 ⟶ 28:
Line (Picture, Points (I), Points (I + 1), Color);
end loop;
end Quadratic_Bezier;</lang>
</lang>
The following test
<lang ada> X : Image (1..16, 1..16);
X : Image (1..16, 1..16);
begin
Fill (X, White);
Quadratic_Bezier (X, (8, 2), (13, 8), (2, 15), Black);
Print (X);</lang>
</lang>
should produce;
<pre>
Line 129 ⟶ 125:
(This subroutine must be inside the <code>RCImagePrimitive</code> module, see [[Bresenham's line algorithm#Fortran|here]])
 
<lang fortran> subroutine quad_bezier(img, p1, p2, p3, color)
type(rgbimage), intent(inout) :: img
type(point), intent(in) :: p1, p2, p3
type(rgb), intent(in) :: color
 
integer :: i, j
real :: pts(0:N_SEG,0:1), t, a, b, c, x, y
 
do i = 0, N_SEG
t = real(i) / real(N_SEG)
a = (1.0 - t)**2.0
b = 2.0 * t * (1.0 - t)
c = t**2.0
x = a * p1%x + b * p2%x + c * p3%x
y = a * p1%y + b * p2%y + c * p3%y
pts(i,0) = x
pts(i,1) = y
end do
 
do i = 0, N_SEG-1
j = i + 1
call draw_line(img, point(pts(i,0), pts(i,1)), &
point(pts(j,0), pts(j,1)), color)
end do
 
end subroutine quad_bezier</lang>
 
=={{header|Haskell}}==
Line 272 ⟶ 268:
{{TI-image-task}}
 
<prelang style="font-family:'TI Uni'"ti89b>Define cubic(p1,p2,p3,segs) = Prgm
Local i,t,u,prev,pt
0 → pt
Line 284 ⟶ 280:
EndIf
EndFor
EndPrgm</prelang>
 
=={{header|Vedit macro language}}==
Line 292 ⟶ 288:
Constant recursion depth is used here. Recursion depth of 5 seems to give accurate enough result in most situations. In real world implementations, some adaptive method is often used to decide when to stop recursion.
 
<lang vedit>// Daw a Cubic bezier curve
// Daw a Cubic bezier curve
// #20, #30 = Start point
// #21, #31 = Control point 1
Line 325 ⟶ 320:
Call("DRAW_LINE")
}
return</lang>
</lang>