Bitmap/Bézier curves/Cubic: Difference between revisions
Content added Content deleted
(Updated D entry) |
(Added zkl) |
||
Line 1,041: | Line 1,041: | ||
SetVid(3); \restore normal text display |
SetVid(3); \restore normal text display |
||
]</lang> |
]</lang> |
||
=={{header|zkl}}== |
|||
[[File:CubicXPL0.png|right]] |
|||
Image cribbed from XPL0 |
|||
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl |
|||
Add this to the PPM class: |
|||
<lang zkl> fcn cBezier(p0x,p0y, p1x,p1y, p2x,p2y, p3x,p3y, rgb, numPts=500){ |
|||
numPts.pump(Void,'wrap(t){ // B(t) |
|||
t=t.toFloat()/numPts; t1:=(1.0 - t); |
|||
a:=t1*t1*t1; b:=t*t1*t1*3; c:=t1*t*t*3; d:=t*t*t; |
|||
x:=a*p0x + b*p1x + c*p2x + d*p3x + 0.5; |
|||
y:=a*p0y + b*p1y + c*p2y + d*p3y + 0.5; |
|||
__sSet(rgb,x,y); |
|||
}); |
|||
}</lang> |
|||
Doesn't use line segments, they don't seem like an improvement. |
|||
<lang zkl>bitmap:=PPM(200,150,0xff|ff|ff); |
|||
bitmap.cBezier(0,0, 30,100, 120,20, 160,120, 0); |
|||
bitmap.write(File("foo.ppm","wb"));</lang> |
|||
{{omit from|GUISS}} |
{{omit from|GUISS}} |