Hi, i am playing a bit around while learning DB Pro. Currently i study a bit math and physics and make this basic vector drawing code. Is nothing finished, but maybe somebody is interested on how to draw a grid or coordinate system.
Rem Project: Vector Drawing
Rem Created: Thursday, January 22, 2015
Rem ***** Main Source File *****
// define colors
#constant cRed = rgb(255,0,0)
#constant cGreen = rgb(0,255,0)
#constant cBlue = rgb(0,0,255)
#constant cGray = rgb(200,200,200)
set display mode 800,600,32,1
set window on
cls rgb(255,255,255)
set text font "Arial"
set text size 8
// screen middle is the zero point
// of the coordinate system
global mX as integer
global mY as integer
mX = screen width() / 2
mY = screen height() / 2
// draw coordinate system (y-positive downwards)
drawCS()
// draw vector
ink cBlue,0
line mx,my,mx+150,my-120
wait key
end
function drawCS()
// 1 unit = 1 * resolution
resolution = 10
// size of unit marker
mSize = 2
// set the length of the axis from zero point
x_AxisLength = 40 * resolution
y_AxisLength = 30 * resolution
// draw grid
ink cGray,0
gridX = mx - x_AxisLength
gridY = my - y_AxisLength
x_AxisTotal = x_AxisLength * 2
y_AxisTotal = y_AxisLength * 2
for i = 0 to x_AxisTotal
newX = gridX + (i * resolution)
line newX,gridY,newX,y_AxisTotal
next
for i = 0 to y_AxisTotal
newY = gridY + (i * resolution)
line gridX,newY,x_AxisTotal,newY
next
// draw the coordinate system
ink cGreen,0
circle mx,my,3
line mx,my,mx + x_AxisLength,my
line mx,my,mx - x_AxisLength,my
line mx,my,mx,my + y_AxisLength
line mx,my,mx,my - y_AxisLength
// draw unit markers on axis
ink cRed,0
mSizeTemp = mSize
axisDir = 1
for j = 1 to 2
for i = 1 to (x_AxisLength / resolution)
newX = mx + (i * resolution) * axisDir
if not (i mod 5)
mSize = mSize + 2
text newX - 5, my + msize + 5, str$((i * resolution) * axisDir)
else
mSize = mSizeTemp
endif
line newX,my - mSize,newX,my + mSize
next
for i = 1 to (y_AxisLength / resolution)
newY = my + (i * resolution) * axisDir
if not (i mod 5)
mSize = mSize + 2
text mx - msize - 20, newY - 3, str$((i * resolution) * axisDir)
else
mSize = mSizeTemp
endif
line mx - mSize,newY,mx + mSize,newY
next
axisDir = -1
next
endfunction
Back to the Basic Roots - Dark Power Inside