Author Topic: Extended drawing library  (Read 2754 times)

Offline backspace

  • Mr. Drawsprite
  • **
  • Posts: 53
    • View Profile
Extended drawing library
« on: 2012-Dec-14 »
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.

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
Re: Extended drawing library
« Reply #1 on: 2012-Dec-14 »
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)

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3372
  • Integrated Brain
    • View Profile
Re: Extended drawing library
« Reply #2 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...!!!

Offline backspace

  • Mr. Drawsprite
  • **
  • Posts: 53
    • View Profile
Re: Extended drawing library
« Reply #3 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. :)
« Last Edit: 2012-Dec-29 by backspace »
I came, I saw, I coded.

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3372
  • Integrated Brain
    • View Profile
Re: Extended drawing library
« Reply #4 on: 2012-Dec-29 »
Thanks I take a look to the Soirce code, becuase the fill  Circle and Ellipse it's very interesting...

Regards,