How to resolve the algorithm Bitmap/Bézier curves/Quadratic step by step in the PicoLisp programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Bitmap/Bézier curves/Quadratic step by step in the PicoLisp 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 one, draw a quadratic 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/Quadratic step by step in the PicoLisp programming language

Source code in the picolisp programming language

(scl 6)

(de quadBezier (Img N X1 Y1 X2 Y2 X3 Y3)
   (let (R (* N N)  X X1  Y Y1  DX 0  DY 0)
      (for I N
         (let (J (- N I)  A (*/ 1.0 J J R)  B (*/ 2.0 I J R)  C (*/ 1.0 I I R))
            (brez Img X Y
               (setq DX (- (+ (*/ A X1 1.0) (*/ B X2 1.0) (*/ C X3 1.0)) X))
               (setq DY (- (+ (*/ A Y1 1.0) (*/ B Y2 1.0) (*/ C Y3 1.0)) Y)) )
            (inc 'X DX)
            (inc 'Y DY) ) ) ) )

(let Img (make (do 200 (link (need 300 0))))       # Create image 300 x 200
   (quadBezier Img 12 20 100 300 -80 260 180)
   (out "img.pbm"                                  # Write to bitmap file
      (prinl "P1")
      (prinl 300 " " 200)
      (mapc prinl Img) ) )

(call 'display "img.pbm")

  

You may also check:How to resolve the algorithm Calculating the value of e step by step in the D programming language
You may also check:How to resolve the algorithm Flow-control structures step by step in the C programming language
You may also check:How to resolve the algorithm Bernoulli numbers step by step in the Delphi programming language
You may also check:How to resolve the algorithm Range expansion step by step in the Arturo programming language
You may also check:How to resolve the algorithm Rot-13 step by step in the ARM Assembly programming language