Bitmap/Bézier curves/Quadratic: Difference between revisions
Content deleted Content added
→{{header|Lua}}: added Lua solution |
Thundergnat (talk | contribs) m syntax highlighting fixup automation |
||
Line 8: | Line 8: | ||
{{libheader|Action! Tool Kit}} |
{{libheader|Action! Tool Kit}} |
||
{{libheader|Action! Real Math}} |
{{libheader|Action! Real Math}} |
||
< |
<syntaxhighlight lang=Action!>INCLUDE "H6:RGBLINE.ACT" ;from task Bresenham's line algorithm |
||
INCLUDE "H6:REALMATH.ACT" |
INCLUDE "H6:REALMATH.ACT" |
||
Line 119: | Line 119: | ||
DO UNTIL CH#$FF OD |
DO UNTIL CH#$FF OD |
||
CH=$FF |
CH=$FF |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/B%C3%A9zier_curves_quadratic.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/B%C3%A9zier_curves_quadratic.png Screenshot from Atari 8-bit computer] |
||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
< |
<syntaxhighlight lang=ada>procedure Quadratic_Bezier |
||
( Picture : in out Image; |
( Picture : in out Image; |
||
P1, P2, P3 : Point; |
P1, P2, P3 : Point; |
||
Line 146: | Line 146: | ||
Line (Picture, Points (I), Points (I + 1), Color); |
Line (Picture, Points (I), Points (I + 1), Color); |
||
end loop; |
end loop; |
||
end Quadratic_Bezier;</ |
end Quadratic_Bezier;</syntaxhighlight> |
||
The following test |
The following test |
||
< |
<syntaxhighlight lang=ada> X : Image (1..16, 1..16); |
||
begin |
begin |
||
Fill (X, White); |
Fill (X, White); |
||
Quadratic_Bezier (X, (8, 2), (13, 8), (2, 15), Black); |
Quadratic_Bezier (X, (8, 2), (13, 8), (2, 15), Black); |
||
Print (X);</ |
Print (X);</syntaxhighlight> |
||
should produce; |
should produce; |
||
<pre> |
<pre> |
||
Line 176: | Line 176: | ||
{{works with|BBC BASIC for Windows}} |
{{works with|BBC BASIC for Windows}} |
||
[[Image:bezierquad_bbc.gif|right]] |
[[Image:bezierquad_bbc.gif|right]] |
||
< |
<syntaxhighlight lang=bbcbasic> Width% = 200 |
||
Height% = 200 |
Height% = 200 |
||
Line 226: | Line 226: | ||
GCOL 1 |
GCOL 1 |
||
LINE x%*2,y%*2,x%*2,y%*2 |
LINE x%*2,y%*2,x%*2,y%*2 |
||
ENDPROC</ |
ENDPROC</syntaxhighlight> |
||
=={{header|C}}== |
=={{header|C}}== |
||
Line 232: | Line 232: | ||
Interface (to be added to all other to make the final <tt>imglib.h</tt>): |
Interface (to be added to all other to make the final <tt>imglib.h</tt>): |
||
< |
<syntaxhighlight lang=c>void quad_bezier( |
||
image img, |
image img, |
||
unsigned int x1, unsigned int y1, |
unsigned int x1, unsigned int y1, |
||
Line 239: | Line 239: | ||
color_component r, |
color_component r, |
||
color_component g, |
color_component g, |
||
color_component b );</ |
color_component b );</syntaxhighlight> |
||
Implementation: |
Implementation: |
||
< |
<syntaxhighlight lang=c>#include <math.h> |
||
/* number of segments for the curve */ |
/* number of segments for the curve */ |
||
Line 292: | Line 292: | ||
} |
} |
||
#undef plot |
#undef plot |
||
#undef line</ |
#undef line</syntaxhighlight> |
||
=={{header|Commodore Basic}}== |
=={{header|Commodore Basic}}== |
||
< |
<syntaxhighlight lang=basic> |
||
10 rem bezier curve algorihm |
10 rem bezier curve algorihm |
||
20 rem translated from purebasic |
20 rem translated from purebasic |
||
Line 352: | Line 352: | ||
3160 next i |
3160 next i |
||
3170 return |
3170 return |
||
</syntaxhighlight> |
|||
</lang> |
|||
[https://www.worldofchris.com/assets/c64-bezier-curve.png Screenshot of Bézier curve on C64] |
[https://www.worldofchris.com/assets/c64-bezier-curve.png Screenshot of Bézier curve on C64] |
||
=={{header|D}}== |
=={{header|D}}== |
||
This solution uses two modules, from the Grayscale image and the Bresenham's line algorithm Tasks. |
This solution uses two modules, from the Grayscale image and the Bresenham's line algorithm Tasks. |
||
< |
<syntaxhighlight lang=d>import grayscale_image, bitmap_bresenhams_line_algorithm; |
||
struct Pt { int x, y; } // Signed. |
struct Pt { int x, y; } // Signed. |
||
Line 385: | Line 385: | ||
im.quadraticBezier(Pt(1,10), Pt(25,27), Pt(15,2), Gray.black); |
im.quadraticBezier(Pt(1,10), Pt(25,27), Pt(15,2), Gray.black); |
||
im.textualShow(); |
im.textualShow(); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>.................... |
<pre>.................... |
||
Line 411: | Line 411: | ||
Some code is shared with the cubic bezier task, but I put it here again to make it simple (hoping the two version don't diverge) |
Some code is shared with the cubic bezier task, but I put it here again to make it simple (hoping the two version don't diverge) |
||
Same remark as with cubic bezier, the points could go into a sequence to simplify stack shuffling |
Same remark as with cubic bezier, the points could go into a sequence to simplify stack shuffling |
||
< |
<syntaxhighlight lang=factor>USING: arrays kernel locals math math.functions |
||
rosettacode.raster.storage sequences ; |
rosettacode.raster.storage sequences ; |
||
IN: rosettacode.raster.line |
IN: rosettacode.raster.line |
||
Line 434: | Line 434: | ||
points-to-lines |
points-to-lines |
||
{R,G,B} swap image draw-lines ; |
{R,G,B} swap image draw-lines ; |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|FBSL}}== |
=={{header|FBSL}}== |
||
Line 440: | Line 440: | ||
'''Translation of BBC BASIC using pure FBSL's built-in graphics functions:''' |
'''Translation of BBC BASIC using pure FBSL's built-in graphics functions:''' |
||
< |
<syntaxhighlight lang=qbasic>#DEFINE WM_LBUTTONDOWN 513 |
||
#DEFINE WM_CLOSE 16 |
#DEFINE WM_CLOSE 16 |
||
Line 495: | Line 495: | ||
WEND |
WEND |
||
END SUB |
END SUB |
||
END SUB</ |
END SUB</syntaxhighlight> |
||
'''Output:''' [[File:FBSLBezierQuad.PNG]] |
'''Output:''' [[File:FBSLBezierQuad.PNG]] |
||
Line 503: | Line 503: | ||
(This subroutine must be inside the <code>RCImagePrimitive</code> module, see [[Bresenham's line algorithm#Fortran|here]]) |
(This subroutine must be inside the <code>RCImagePrimitive</code> module, see [[Bresenham's line algorithm#Fortran|here]]) |
||
< |
<syntaxhighlight lang=fortran>subroutine quad_bezier(img, p1, p2, p3, color) |
||
type(rgbimage), intent(inout) :: img |
type(rgbimage), intent(inout) :: img |
||
type(point), intent(in) :: p1, p2, p3 |
type(point), intent(in) :: p1, p2, p3 |
||
Line 528: | Line 528: | ||
end do |
end do |
||
end subroutine quad_bezier</ |
end subroutine quad_bezier</syntaxhighlight> |
||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
{{trans|BBC BASIC}} |
{{trans|BBC BASIC}} |
||
< |
<syntaxhighlight lang=freebasic>' version 01-11-2016 |
||
' compile with: fbc -s console |
' compile with: fbc -s console |
||
Line 594: | Line 594: | ||
Print : Print "hit any key to end program" |
Print : Print "hit any key to end program" |
||
Sleep |
Sleep |
||
End</ |
End</syntaxhighlight> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<syntaxhighlight lang=go>package raster |
||
const b2Seg = 20 |
const b2Seg = 20 |
||
Line 624: | Line 624: | ||
func (b *Bitmap) Bézier2Rgb(x1, y1, x2, y2, x3, y3 int, c Rgb) { |
func (b *Bitmap) Bézier2Rgb(x1, y1, x2, y2, x3, y3 int, c Rgb) { |
||
b.Bézier2(x1, y1, x2, y2, x3, y3, c.Pixel()) |
b.Bézier2(x1, y1, x2, y2, x3, y3, c.Pixel()) |
||
}</ |
}</syntaxhighlight> |
||
Demonstration program: |
Demonstration program: |
||
[[File:GoBez2.png|thumb|right]] |
[[File:GoBez2.png|thumb|right]] |
||
< |
<syntaxhighlight lang=go>package main |
||
import ( |
import ( |
||
Line 641: | Line 641: | ||
fmt.Println(err) |
fmt.Println(err) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang=haskell>{-# LANGUAGE |
||
FlexibleInstances, TypeSynonymInstances, |
FlexibleInstances, TypeSynonymInstances, |
||
ViewPatterns #-} |
ViewPatterns #-} |
||
Line 690: | Line 690: | ||
pt n p = pmap (*n) p |
pt n p = pmap (*n) p |
||
f (curvePoint -> p1) (curvePoint -> p2) = |
f (curvePoint -> p1) (curvePoint -> p2) = |
||
line i (toPixel p1) (toPixel p2) c</ |
line i (toPixel p1) (toPixel p2) c</syntaxhighlight> |
||
=={{header|J}}== |
=={{header|J}}== |
||
Line 700: | Line 700: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
This incorporates code from other relevant tasks in order to provide a runnable example. |
This incorporates code from other relevant tasks in order to provide a runnable example. |
||
< |
<syntaxhighlight lang=scala>// Version 1.2.40 |
||
import java.awt.Color |
import java.awt.Color |
||
Line 774: | Line 774: | ||
ImageIO.write(image, "jpg", qbFile) |
ImageIO.write(image, "jpg", qbFile) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
Starting with the code from [[Bitmap/Bresenham's line algorithm#Lua|Bitmap/Bresenham's line algorithm]], then extending: |
Starting with the code from [[Bitmap/Bresenham's line algorithm#Lua|Bitmap/Bresenham's line algorithm]], then extending: |
||
< |
<syntaxhighlight lang=lua>Bitmap.quadraticbezier = function(self, x1, y1, x2, y2, x3, y3, nseg) |
||
nseg = nseg or 10 |
nseg = nseg or 10 |
||
local prevx, prevy, currx, curry |
local prevx, prevy, currx, curry |
||
Line 795: | Line 795: | ||
bitmap:clear() |
bitmap:clear() |
||
bitmap:quadraticbezier( 1,1, 30,37, 59,1 ) |
bitmap:quadraticbezier( 1,1, 30,37, 59,1 ) |
||
bitmap:render({[0x000000]='.', [0xFFFFFFFF]='X'})</ |
bitmap:render({[0x000000]='.', [0xFFFFFFFF]='X'})</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>............................................................. |
<pre>............................................................. |
||
Line 820: | Line 820: | ||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang=Mathematica>pts = {{0, 0}, {1, -1}, {2, 1}}; |
||
Graphics[{BSplineCurve[pts], Green, Line[pts], Red, Point[pts]}]</ |
Graphics[{BSplineCurve[pts], Green, Line[pts], Red, Point[pts]}]</syntaxhighlight> |
||
Second solution using built-in function BezierCurve. |
Second solution using built-in function BezierCurve. |
||
< |
<syntaxhighlight lang=Mathematica>pts = {{0, 0}, {1, -1}, {2, 1}}; |
||
Graphics[{BezierCurve[pts], Green, Line[pts], Red, Point[pts]}]</ |
Graphics[{BezierCurve[pts], Green, Line[pts], Red, Point[pts]}]</syntaxhighlight> |
||
[[File:MmaQuadraticBezier.png]] |
[[File:MmaQuadraticBezier.png]] |
||
=={{header|MATLAB}}== |
=={{header|MATLAB}}== |
||
Note: Store this function in a file named "bezierQuad.mat" in the @Bitmap folder for the Bitmap class defined [[Bitmap#MATLAB|here]]. |
Note: Store this function in a file named "bezierQuad.mat" in the @Bitmap folder for the Bitmap class defined [[Bitmap#MATLAB|here]]. |
||
< |
<syntaxhighlight lang=MATLAB> |
||
function bezierQuad(obj,pixel_0,pixel_1,pixel_2,color,varargin) |
function bezierQuad(obj,pixel_0,pixel_1,pixel_2,color,varargin) |
||
Line 859: | Line 859: | ||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
Sample usage: |
Sample usage: |
||
This will generate the image example for the Go solution. |
This will generate the image example for the Go solution. |
||
< |
<syntaxhighlight lang=MATLAB> |
||
>> img = Bitmap(400,300); |
>> img = Bitmap(400,300); |
||
>> img.fill([223 255 239]); |
>> img.fill([223 255 239]); |
||
>> img.bezierQuad([20 150],[500 -100],[300 280],[63 143 239],21); |
>> img.bezierQuad([20 150],[500 -100],[300 280],[63 143 239],21); |
||
>> disp(img) |
>> disp(img) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{trans|Ada}} |
{{trans|Ada}} |
||
We use module “bitmap” for bitmap management and module “bresenham” to draw segments. |
We use module “bitmap” for bitmap management and module “bresenham” to draw segments. |
||
< |
<syntaxhighlight lang=Nim>import bitmap |
||
import bresenham |
import bresenham |
||
import lenientops |
import lenientops |
||
Line 900: | Line 900: | ||
img.fill(White) |
img.fill(White) |
||
img.drawQuadraticBezier((1, 7), (7, 12), (14, 1), Black) |
img.drawQuadraticBezier((1, 7), (7, 12), (14, 1), Black) |
||
img.print</ |
img.print</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 918: | Line 918: | ||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
< |
<syntaxhighlight lang=ocaml>let quad_bezier ~img ~color |
||
~p1:(_x1, _y1) |
~p1:(_x1, _y1) |
||
~p2:(_x2, _y2) |
~p2:(_x2, _y2) |
||
Line 956: | Line 956: | ||
in |
in |
||
by_pair pts (fun p0 p1 -> line ~p0 ~p1); |
by_pair pts (fun p0 p1 -> line ~p0 ~p1); |
||
;;</ |
;;</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 962: | Line 962: | ||
Requires new_image() from [[Bitmap#Phix|Bitmap]], bresLine() from [[Bitmap/Bresenham's_line_algorithm#Phix|Bresenham's_line_algorithm]], and write_ppm() from [[Bitmap/Write_a_PPM_file#Phix|Write_a_PPM_file]]. <br> |
Requires new_image() from [[Bitmap#Phix|Bitmap]], bresLine() from [[Bitmap/Bresenham's_line_algorithm#Phix|Bresenham's_line_algorithm]], and write_ppm() from [[Bitmap/Write_a_PPM_file#Phix|Write_a_PPM_file]]. <br> |
||
Results may be verified with demo\rosetta\viewppm.exw |
Results may be verified with demo\rosetta\viewppm.exw |
||
< |
<syntaxhighlight lang=Phix>-- demo\rosetta\Bitmap_BezierQuadratic.exw |
||
include ppm.e -- black, green, red, white, new_image(), write_ppm(), bresLine() -- (covers above requirements) |
include ppm.e -- black, green, red, white, new_image(), write_ppm(), bresLine() -- (covers above requirements) |
||
Line 989: | Line 989: | ||
img[100][200] = red |
img[100][200] = red |
||
img[200][1] = red |
img[200][1] = red |
||
write_ppm("BezierQ.ppm",img)</ |
write_ppm("BezierQ.ppm",img)</syntaxhighlight> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
This uses the 'brez' line drawing function from |
This uses the 'brez' line drawing function from |
||
[[Bitmap/Bresenham's line algorithm#PicoLisp]]. |
[[Bitmap/Bresenham's line algorithm#PicoLisp]]. |
||
< |
<syntaxhighlight lang=PicoLisp>(scl 6) |
||
(de quadBezier (Img N X1 Y1 X2 Y2 X3 Y3) |
(de quadBezier (Img N X1 Y1 X2 Y2 X3 Y3) |
||
Line 1,004: | Line 1,004: | ||
(setq DY (- (+ (*/ A Y1 1.0) (*/ B Y2 1.0) (*/ C Y3 1.0)) Y)) ) |
(setq DY (- (+ (*/ A Y1 1.0) (*/ B Y2 1.0) (*/ C Y3 1.0)) Y)) ) |
||
(inc 'X DX) |
(inc 'X DX) |
||
(inc 'Y DY) ) ) ) )</ |
(inc 'Y DY) ) ) ) )</syntaxhighlight> |
||
Test: |
Test: |
||
< |
<syntaxhighlight lang=PicoLisp>(let Img (make (do 200 (link (need 300 0)))) # Create image 300 x 200 |
||
(quadBezier Img 12 20 100 300 -80 260 180) |
(quadBezier Img 12 20 100 300 -80 260 180) |
||
(out "img.pbm" # Write to bitmap file |
(out "img.pbm" # Write to bitmap file |
||
Line 1,013: | Line 1,013: | ||
(mapc prinl Img) ) ) |
(mapc prinl Img) ) ) |
||
(call 'display "img.pbm")</ |
(call 'display "img.pbm")</syntaxhighlight> |
||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
< |
<syntaxhighlight lang=PureBasic>Procedure quad_bezier(img, p1x, p1y, p2x, p2y, p3x, p3y, Color, n_seg) |
||
Protected i |
Protected i |
||
Protected.f T, t1, a, b, c, d |
Protected.f T, t1, a, b, c, d |
||
Line 1,051: | Line 1,051: | ||
event = WaitWindowEvent() |
event = WaitWindowEvent() |
||
Until event = #PB_Event_CloseWindow |
Until event = #PB_Event_CloseWindow |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Python}}== |
=={{header|Python}}== |
||
Line 1,060: | Line 1,060: | ||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang=racket> |
||
#lang racket |
#lang racket |
||
(require racket/draw) |
(require racket/draw) |
||
Line 1,087: | Line 1,087: | ||
(draw-lines dc (bezier-points '(16 1) '(1 4) '(3 16))) |
(draw-lines dc (bezier-points '(16 1) '(1 4) '(3 16))) |
||
bm |
bm |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
Line 1,094: | Line 1,094: | ||
Uses pieces from [[Bitmap#Raku| Bitmap]], and [[Bitmap/Bresenham's_line_algorithm#Raku| Bresenham's line algorithm]] tasks. They are included here to make a complete, runnable program. |
Uses pieces from [[Bitmap#Raku| Bitmap]], and [[Bitmap/Bresenham's_line_algorithm#Raku| Bresenham's line algorithm]] tasks. They are included here to make a complete, runnable program. |
||
<lang |
<syntaxhighlight lang=raku line>class Pixel { has UInt ($.R, $.G, $.B) } |
||
class Bitmap { |
class Bitmap { |
||
has UInt ($.width, $.height); |
has UInt ($.width, $.height); |
||
Line 1,192: | Line 1,192: | ||
@points.map: { $b.dot( $_, color(255,0,0), 3 )} |
@points.map: { $b.dot( $_, color(255,0,0), 3 )} |
||
$*OUT.write: $b.P6;</ |
$*OUT.write: $b.P6;</syntaxhighlight> |
||
See [https://github.com/thundergnat/rc/blob/master/img/Bezier-quadratic-perl6.png example image here], (converted to a .png as .ppm format is not widely supported). |
See [https://github.com/thundergnat/rc/blob/master/img/Bezier-quadratic-perl6.png example image here], (converted to a .png as .ppm format is not widely supported). |
||
Line 1,206: | Line 1,206: | ||
{{TI-image-task}} |
{{TI-image-task}} |
||
< |
<syntaxhighlight lang=ti89b>Define cubic(p1,p2,p3,segs) = Prgm |
||
Local i,t,u,prev,pt |
Local i,t,u,prev,pt |
||
0 → pt |
0 → pt |
||
Line 1,218: | Line 1,218: | ||
EndIf |
EndIf |
||
EndFor |
EndFor |
||
EndPrgm</ |
EndPrgm</syntaxhighlight> |
||
=={{header|Vedit macro language}}== |
=={{header|Vedit macro language}}== |
||
Line 1,226: | Line 1,226: | ||
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. |
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. |
||
< |
<syntaxhighlight lang=vedit>// Daw a Cubic bezier curve |
||
// #20, #30 = Start point |
// #20, #30 = Start point |
||
// #21, #31 = Control point 1 |
// #21, #31 = Control point 1 |
||
Line 1,258: | Line 1,258: | ||
Call("DRAW_LINE") |
Call("DRAW_LINE") |
||
} |
} |
||
return</ |
return</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|DOME}} |
{{libheader|DOME}} |
||
Requires version 1.3.0 of DOME or later. |
Requires version 1.3.0 of DOME or later. |
||
< |
<syntaxhighlight lang=ecmascript>import "graphics" for Canvas, ImageData, Color, Point |
||
import "dome" for Window |
import "dome" for Window |
||
Line 1,337: | Line 1,337: | ||
static draw(alpha) {} |
static draw(alpha) {} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
[[File:QuadXPL0.png|right]] |
[[File:QuadXPL0.png|right]] |
||
< |
<syntaxhighlight lang=XPL0>include c:\cxpl\codes; \intrinsic 'code' declarations |
||
proc Bezier(P0, P1, P2); \Draw quadratic Bezier curve |
proc Bezier(P0, P1, P2); \Draw quadratic Bezier curve |
||
Line 1,367: | Line 1,367: | ||
if ChIn(1) then []; \wait for keystroke |
if ChIn(1) then []; \wait for keystroke |
||
SetVid(3); \restore normal text display |
SetVid(3); \restore normal text display |
||
]</ |
]</syntaxhighlight> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
Line 1,373: | Line 1,373: | ||
Add this to the PPM class: |
Add this to the PPM class: |
||
< |
<syntaxhighlight lang=zkl> fcn qBezier(p0x,p0y, p1x,p1y, p2x,p2y, rgb, numPts=500){ |
||
numPts.pump(Void,'wrap(t){ // B(t) |
numPts.pump(Void,'wrap(t){ // B(t) |
||
t=t.toFloat()/numPts; t1:=(1.0 - t); |
t=t.toFloat()/numPts; t1:=(1.0 - t); |
||
Line 1,381: | Line 1,381: | ||
__sSet(rgb,x,y); |
__sSet(rgb,x,y); |
||
}); |
}); |
||
}</ |
}</syntaxhighlight> |
||
Doesn't use line segments, they don't seem like an improvement. |
Doesn't use line segments, they don't seem like an improvement. |
||
< |
<syntaxhighlight lang=zkl>bitmap:=PPM(200,200,0xff|ff|ff); |
||
bitmap.qBezier(10,100, 250,270, 150,20, 0); |
bitmap.qBezier(10,100, 250,270, 150,20, 0); |
||
bitmap.write(File("foo.ppm","wb"));</ |
bitmap.write(File("foo.ppm","wb"));</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Same as the BBC BASIC image:[[Image:bezierquad_bbc.gif]] |
Same as the BBC BASIC image:[[Image:bezierquad_bbc.gif]] |