How to resolve the algorithm Bitmap/Bresenham's line algorithm step by step in the Vedit macro language programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Bitmap/Bresenham's line algorithm step by step in the Vedit macro language programming language

Table of Contents

Problem Statement

Using the data storage type defined on the Bitmap page for raster graphics images, draw a line given two points with Bresenham's line algorithm.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Bitmap/Bresenham's line algorithm step by step in the Vedit macro language programming language

Source code in the vedit programming language

//  Daw a line using Bresenham's line algorithm.
//  #1=x1, #2=y1; #3=x2, #4=y2

:DRAW_LINE:
Num_Push(31,35)
#31 = abs(#3-#1)    // x distance
#32 = abs(#4-#2)    // y distance
if (#4-#2 < -#31 || #3-#1 <= -#32) {
    #99=#1; #1=#3; #3=#99 // swap start and end points
    #99=#2; #2=#4; #4=#99
}
if (#1 < #3) { #34=1 } else { #34=-1 }  // x step
if (#2 < #4) { #35=1 } else { #35=-1 }  // y step

if (#32 > #31) {    // steep angle, step by Y
    #33 = #32 / 2   // error distance
    while (#2 <= #4) {
  Call("DRAW_PIXEL")
  #33 -= #31
  if (#33 < 0) {
      #1 += #34   // move right
      #33 += #32
  }
  #2++      // move up
    }
} else {      // not steep, step by X
    #33 = #31 / 2
    while (#1 <= #3) {
  Call("DRAW_PIXEL")
  #33 -= #32
  if (#33 < 0) {
      #2 += #35   // move up
      #33 += #31
  }
  #1++      // move right
    }
}
Num_Pop(31,35)
return

  

You may also check:How to resolve the algorithm Increment a numerical string step by step in the HicEst programming language
You may also check:How to resolve the algorithm Substring/Top and tail step by step in the Quackery programming language
You may also check:How to resolve the algorithm Loops/With multiple ranges step by step in the C programming language
You may also check:How to resolve the algorithm Pick random element step by step in the APL programming language
You may also check:How to resolve the algorithm Strip whitespace from a string/Top and tail step by step in the Lambdatalk programming language