The Spiral Program

This program shows you a nice spiral.

There is no scale command in gambas. Therefore the xy coordinates are transformed in the program. The coordinate system reaches from xmin = - 2 to xmax = 2 and ymin = - 2 to ymax = 2.

You need a Drawingarea and a Commandbutton to get the example going.

How does this look ? See it here prgspir.png

The code:

PUBLIC SUB Button1_Click()
DIM dymax AS Integer
DIM dymin AS Integer 
DIM ymax AS Integer
DIM ymin AS Integer
DIM y AS Float
DIM dy AS Float
DIM dyi AS Integer
DIM dxmax AS Integer
DIM dxmin AS Integer 
DIM xmax AS Integer
DIM xmin AS Integer
DIM x AS Float
DIM dx AS Float
DIM dxi AS Integer
DIM k AS Float 
DIM a AS Float 
DIM w AS Float

dymax = DrawingArea1.Height
dymin = 0 
ymax = 2
ymin = -2

dxmax = DrawingArea1.Width
dxmin = 0 
xmax = 2
xmin = -2 
'x-axis is drawn 
FOR x = xmin TO xmax STEP 0.005
y = 0 
dy = CFloat(y - ymin) / (ymax - ymin ) * (dymax - dymin) + dymin 
dx = CFloat(x - xmin) / (xmax - xmin ) * (dxmax - dxmin) + dxmin 
dyi = Fix(dy)
dxi = Fix(dx) 
Draw.Begin(DrawingArea1)
Draw.Point(dxi,DrawingArea1.Height- dyi)
Draw.End
NEXT 
'y - Axis is drawn
FOR y = ymin TO ymax STEP 0.005
x = 0 
dy = CFloat(y - ymin) / (ymax - ymin ) * (dymax - dymin) + dymin 
dx = CFloat(x - xmin) / (xmax - xmin ) * (dxmax - dxmin) + dxmin 
dyi = Fix(dy)
dxi = Fix(dx) 
Draw.Begin(DrawingArea1)
Draw.Point(dxi,DrawingArea1.Height- dyi)
Draw.End
NEXT 

'Here the spiral starts
FOR k = -100 TO 150 STEP 0.5
a = 0.97
'Distance from 0,0 to the point 
w = 0.15
'Angle under whiche the point is seen from the origin
a = a ^k 
w = w * k 
x = a * Cos(w)
'x coordinate of each point
y = a * Sin(w)
'y coordinate of each point
dy = CFloat(y - ymin) / (ymax - ymin ) * (dymax - dymin) + dymin 
dx = CFloat(x - xmin) / (xmax - xmin ) * (dxmax - dxmin) + dxmin 
dyi = Fix(dy)
dxi = Fix(dx) 
Draw.Begin(DrawingArea1)
Draw.Point(dxi,DrawingArea1.Height- dyi)
Draw.End
NEXT
END

-- ReinerHoffmann - 01 Feb 2004