Extended drawing library

Previous topic - Next topic

backspace

Here's an extended drawing library that adds a few extra drawing primitives.
Objects include line, lineto, rectangle, filledrectangle, circle, filledcircle, oval, filledoval. pixel
Just comment out the "test" function, add the file to your project, and call the required functions. Use the test function as and example
Setting _drawcolor will set the color for all subsequent drawing calls
line and pixel save the last x,y location - for using lineto function.

Code (glbasic) Select
// --------------------------------- //
// Project: DrawingObjects

test()

TYPE _DSTORE
x
y
color
ENDTYPE

GLOBAL _dstore AS _DSTORE; _dstore.x=0; _dstore.y=0; _dstore.color = RGB(255,255,255)

FUNCTION _drawcolor: r,g,b
_dstore.color = RGB(r,g,b)
ENDFUNCTION

FUNCTION _line: x1, y1, x2, y2
DRAWLINE x1, y1, x2, y2, _dstore.color
_dstore.x = x2
_dstore.y = y2
ENDFUNCTION

FUNCTION _lineto: x,y
DRAWLINE _dstore.x, _dstore.y, x, y, _dstore.color
_dstore.x = x
_dstore.y = y
ENDFUNCTION

FUNCTION _rectangle: x,y,w,h
_line(x,y,x+w-1,y)
_lineto(x+w-1,y+h-1)
_lineto(x,y+h-1)
_lineto(x,y)
ENDFUNCTION

FUNCTION _filledrectangle: x, y, w, h
DRAWRECT x, y, w, h, _dstore.color
ENDFUNCTION

FUNCTION _pixel: x,y
SETPIXEL x,y,_dstore.color
_dstore.x = x
_dstore.y = y
ENDFUNCTION

FUNCTION _circle: x,y,r
_pixel((SIN(0)*r)+x , (COS(0)*r)+y)
FOR i = 1 TO 360 STEP 10
_lineto( (SIN(i)*r)+x , (COS(i)*r)+y)
NEXT
_lineto( (SIN(0)*r)+x , (COS(0)*r)+y)
ENDFUNCTION

FUNCTION _filledcircle: x,y,r
LOCAL lx,rx,yy
FOR i = 0 TO 180 STEP 0.5
lx = (SIN(i)*r)+x
rx = (SIN(360-i)*r)+x
yy = (COS(i)*r)+y
_line(lx,yy,rx,yy)
NEXT
ENDFUNCTION

FUNCTION _oval: x,y,w,h
_pixel((SIN(0)*w/2)+x , (COS(0)*h/2)+y)
FOR i = 1 TO 360 STEP 10
_lineto( (SIN(i)*w/2)+x , (COS(i)*h/2)+y)
NEXT
_lineto( (SIN(0)*w/2)+x , (COS(0)*h/2)+y)
ENDFUNCTION

FUNCTION _filledoval: x,y,w,h
LOCAL lx,rx,yy
FOR i = 0 TO 180 STEP 0.5
lx = (SIN(i)*w/2)+x
rx = (SIN(360-i)*w/2)+x
yy = (COS(i)*h/2)+y
_line(lx,yy,rx,yy)
NEXT
ENDFUNCTION

FUNCTION test:
WHILE TRUE
_drawcolor(200,100,50)
_line(300,50,200,100)
_lineto(200,200)
_lineto(400,200)
_lineto(400,100)
_lineto(300,50)
_filledrectangle(140,240,200,100)
_rectangle(400,250,100,50)
_pixel(500,100)
_drawcolor(255,40,100)
_circle(500,100,50)
_filledcircle(500,400,60)
_oval(500,100,90,50)
_drawcolor(0,50,255)
_filledoval(500,400,50,95)

SHOWSCREEN
WEND
ENDFUNCTION
I came, I saw, I coded.

fuzzy70

Thanks for sharing that, could come in handy :)

Lee

Sent from my GT-I5700 using Tapatalk 2

"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

mentalthink

Hi bakcSpace I don't see to yet this library... I think very Usefully, for make some Editor or something for Paint...
Thanks a lot...!!!

backspace

#3
Quote from: mentalthink on 2012-Dec-29
Hi bakcSpace I don't see to yet this library... I think very Usefully, for make some Editor or something for Paint...
Thanks a lot...!!!

It's the source code in the first post.
If you make for example a project with 2 files. Paste the source into the first file. but delete the function named "test". Also delete the call to the function.
In the second file paste only the function name "test". Add a call to the function.
The "test" function is an example of how to use the first file, which is the "library". Name it anything you wish.
Hope this helps.

I actually want to make a paint program, but I still have a lot to learn. Maybe one day I will. :)
I came, I saw, I coded.

mentalthink

Thanks I take a look to the Soirce code, becuase the fill  Circle and Ellipse it's very interesting...

Regards,