Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives To practice function implementation, stack usage, and memory operations Description Create a program that draws a stick figure using the Bresenham line and circle

Objectives
To practice function implementation, stack usage, and memory operations
Description
Create a program that draws a stick figure using the Bresenham line and circle algorithms. The pseudo-code for the algorithms is provided below. These drawing functions are interesting in the fact that they only use integer operations and do not require any fractional math.
In your main program, execute the following commands to draw a stick figure:
Circle(30,100,20) #head
Line(30,80,30,30) #body
Line(20,1,30,30) #left leg
Line(40,1,30,30) #right leg
Line(15,60,30,50) #left arm
Line(30,50,45,60) #right arm
Circle(24,105,3) #left eye
Circle(36,105,3) #right eye
Line(25,90,35,90) #mouth center
Line(25,90,20,95) #mouth left
Line(35,90,40,95) #mouth right
Requirements
Enable the bitmap display under Tools->Bitmap Display
Click Connect to Program
Set the display width and height to 256x256
Starting in the upper left, the display layout is row-by-row:
Address 0x10010000 is row 0, column 0
Address 0x10010004 is row 0, column 1
Address 0x10010008 is row 0, column 2....and so on
Each word holds a 3-byte RGB value and you can make a pixel white with the value 0xFFFFFF
All pixel values should be 0xFFFFFF
Your code should have the following functions
plot
abs - absolute value
circle
line
swap() does not have to be a function
Your main should have calls to circle and line to draw the figure as listed above
If you need more space to hold local variables, you can store them on the stack
Static data should only be used for the graphics display
You do not need to handle invalid arguments to any of the functions
You may have additional files, but your main program should be contain in stick_figure.asm.
For full credit, your stick figure must appear upright and not upside down.
The pseudocode for the line algorithm is:
def Line (x0, y0, x1, y1){
if abs(y1- y0)> abs(x1- x0){
st =1
} else {
st =0
}
if st ==1{
swap(x0, y0)
swap(x1, y1)
}
if x0> x1{
swap(x0, x1)
swap(y0, y1)
}
deltax = x1- x0
deltay = abs(y1- y0)
error =0
y = y0
if y0< y1{
ystep =1
} else {
ystep =-1
}
for x from x0 to x1{//include x0 and x1
if st ==1{
plot(y,x)
} else {
plot(x,y)
}
error = error + deltay
if 2*error >= deltax {
y = y + ystep
error = error - deltax
}//end if
}//end for loop
}//end function
The pseudocode for the circle algorithm is:
def Circle(xc, yc, r){//xc = center x coordinate, yc = center y coordinate, r = radius
x =0
y = r
g =3-2*r
diagonalInc =10-4*r
rightInc =6
while x <= y {
plot (xc+x, yc+y)//plot the circle points
plot (xc+x, yc-y)
plot (xc-x, yc+y)
plot (xc-x, yc-y)
plot (xc+y, yc+x)
plot (xc+y, yc-x)
plot (xc-y, yc+x)
plot (xc-y, yc-x)
if g >=0{
g += diagonalInc
diagonalInc +=8
y -=1
} else {
g += rightInc
diagonalInc +=4
}
rightInc +=4
x +=1
}//end while loop
}//end function

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

Define the term threshold.

Answered: 1 week ago