How to resolve the algorithm Bitmap/Bézier curves/Cubic step by step in the zkl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Bitmap/Bézier curves/Cubic step by step in the zkl 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 other one, draw a cubic 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/Cubic step by step in the zkl programming language
Source code in the zkl programming language
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);
});
}
bitmap:=PPM(200,150,0xff|ff|ff);
bitmap.cBezier(0,149, 30,50, 120,130, 160,30, 0);
bitmap.write(File("foo.ppm","wb"));
You may also check:How to resolve the algorithm Loops/Infinite step by step in the PostScript programming language
You may also check:How to resolve the algorithm Bernoulli numbers step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Miller–Rabin primality test step by step in the Maxima programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the SPL programming language
You may also check:How to resolve the algorithm GUI component interaction step by step in the Run BASIC programming language