TGC Codebase Backup



Rewritten DB 2D functions by David T

20th Sep 2003 8:15
Summary

Very simple - darkbasic functions that mimic built-in function like cirle, ellipse, box and a new function that will create an N sided polygon.



Description

- Box
- Circle
- Ellipse
- Polygon
- Triangle (in there but not showcased)

Very simple set of functions. Written as a learning activity a while back.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    sync rate 50
sync on

x=320
y=240
ang=0

do

  cls

  rem Draw shapes and add description
  set cursor 0,420
  DBInk(200,200,0)
  print "Circle ::";
  DBCircle(mousex(),mousey(),25)

  DBInk(200,200,100)
  print " Ellipse ::";
  DBEllipse(320,240,mousex()/2,mousey()/2)

  DBInk(200,0,0)
  print " 11 sided polygon ::";
  DBPolygon(mousex(),mousey(),100,11)

  DBInk(200,0,200)
  print " Box ::";
  DBBox(0,0,mousex(),mousey())

  DBInk(0,200,100)
  print " "+str$(int(r))+" sided polygon"
  inc i
  r = abs((sin(i)*20.0) + 2)
  DBPolygon(320,240,100,r)

  print screen fps();" frames per second out of 50"

  sync

loop

Function DBInk(r,g,b)
  ink rgb(r,g,b),0
EndFunction

Function DBCircle(x,y,r)

  for i = 1 to 361
    nx = x+sin(i)*r
    ny = y+cos(i)*r

    if i <> 1 then line nx,ny,oldx,oldy

    oldx = nx
    oldy = ny
  next i

EndFunction


Function DBEllipse(x,y,xr,yr)

  for i = 1 to 361
    nx = x+sin(i)*xr
    ny = y+cos(i)*yr

    if i <> 1 then line nx,ny,oldx,oldy

    oldx = nx
    oldy = ny
  next i

Endfunction

Function DBPolygon(x,y,r,sides)

  for i = 1 to 361 step int(360/sides)

    nx = x+sin(i)*r
    ny = y+cos(i)*r

    if i = 1 then bx = nx : by = ny
    if i <> 1 then line nx,ny,oldx,oldy

    oldx = nx
    oldy = ny

  next i

  rem Finish Off
  line bx,by,nx,ny

EndFunction

Function DBBox(x,y,x2,y2)
  line x,y,x2,y
  line x,y,x,y2
  line x,y2,x2,y2
  line x2,y,x2,y2
Endfunction

Function DBTriangle(x,y,x2,y2,x3,y3)
  line x,y,x2,y3
  line x2,y2,x3,y3
  line x3,y3,x,y
Endfunction