Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawing Objects in Assembly

Status
Not open for further replies.

cc5381

Technical User
Dec 1, 2004
2
US
I am having trouble drawing a star inside of a square. Can anybody help
 
Please,

Can you post more information?, like compiler (masm, fasm, tasm, etc), o.s. flavor (where you want to run your program dos, windows, linux, etc), how far have you reached into your code, drawing a square is pretty easy :)

Apart from that... drawing with assembler could be as easy as set up a video mode and write directly to video memory,

regards,

Rick
 
The compiler is masm and the program must run in dos. I haven't gotten real far because I'm lost and don't know what to do. The box must be centered and the star must have 5 points. Can you help??
 
Square should be easy...

CenterX and CenterY would be width/2 and height / 2 of square respectively...

you could get 5 points with SIN and COS calls...
360 degrees / 5 = 72

pt1 = 72 * 0 = 0 deg
pt2 = 72 * 1 = 72 deg
pt3 = 72 * 2 = 144 deg
pt4 = 72 * 3 = 216 deg
pt5 = 72 * 4 = 288 deg

rad = pi / 180 (precalculate this and make it a constant)
rad = 0.017453292519943295769236907684886 (pick a precision)

x = centerx + cos(deg * rad) * Radius
y = centery + sin(deg * rad) * Radius

but you could swap them to get the point to point up...
x = centerx + sin(deg * rad) * Radius
y = centery + cos(deg * rad) * Radius

Then there are methods to draw lines and fill between lines in assembly...

You might also look into drawing filled triangles... (used commonly with 3D apps...)

I'll leave writing the assembly to you, for practice...

Basics...
Code:
load the Deg (or calculate) into AX
Multply By rad
Execute sin/cos function on result
multiply result by radius
add result to Center X/Y
push value
repeat for opposite x/y value
repeat for other 4 points

*Note there are examples of all of the above available on the net, if you can Google the right way ;-)

Have Fun, Be Young... Code BASIC
-Josh

cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top