How to resolve the algorithm Bitmap/Bresenham's line algorithm step by step in the Commodore BASIC 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 Commodore BASIC 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 Commodore BASIC programming language
Source code in the commodore programming language
10 rem bresenham line algorihm
20 rem translated from purebasic
30 x0=10 : rem start x co-ord
40 y0=15 : rem start y co-ord
50 x1=30 : rem end x co-ord
60 y1=20 : rem end y co-ord
70 se=0 : rem 0 = steep 1 = !steep
80 ns=25 : rem num segments
90 dim pt(ns,2) : rem points in line
100 sc=1024 : rem start of screen memory
110 sw=40 : rem screen width
120 sh=25 : rem screen height
130 pc=42 : rem plot character '*'
140 gosub 1000
150 end
1000 rem plot line
1010 if abs(y1-y0)>abs(x1-x0) then se=1:tp=y0:y0=x0:x0=tp:tp=y1:y1=x1:x1=tp
1020 if x0>x1 then tp=x1:x1=x0:x0=tp:tp=y1:y1=y0:y0=tp
1030 dx=x1-x0
1040 dy=abs(y1-y0)
1050 er=dx/2
1060 y=y0
1070 ys=-1
1080 if y0
1090 for x=x0 to x1
1100 if se=1 then p0=y: p1=x:gosub 2000:goto 1120
1110 p0=x: p1=y: gosub 2000
1120 er=er-dy
1130 if er<0 then y=y+ys:er=er+dx
1140 next x
1150 return
2000 rem plot individual point
2010 rem p0 == plot point x
2020 rem p1 == plot point y
2030 sl=p0+(p1*sw)
2040 rem make sure we dont write beyond screen memory
2050 if sl<(sw*sh) then poke sc+sl,pc
2060 return
You may also check:How to resolve the algorithm Active Directory/Search for a user step by step in the Run BASIC programming language
You may also check:How to resolve the algorithm Interactive programming (repl) step by step in the Haskell programming language
You may also check:How to resolve the algorithm Loops/Do-while step by step in the Axe programming language
You may also check:How to resolve the algorithm Resistor mesh step by step in the REXX programming language
You may also check:How to resolve the algorithm Bulls and cows step by step in the Elena programming language