Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - backspace

Pages: 1 [2]
16
Hi, I'm still kinda new to this, but it seems that GLBasic converts the Basic code into c++ code. So i've read. Is it in any way possible to see the c++ code that gets produced ?
Thanks.

17
Code Snippets / 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

Pages: 1 [2]