May 07, 2024, 12:17:41 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Celebration for Creative Basic

Started by GWS, November 07, 2007, 02:49:46 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

Here's a little program I created in 10 minutes - (well I must admit I'd developed the algorithms previously  :)).

I posted it elsewhere as a challenge to 'C++' programmers to see if they could emulate it.  I suspect it would prove difficult. :)

Anyway, I like to show off little CBasic, and this shows how easy it is to use.  The code might be useful as a template for starting any new windows program.


def win:WINDOW

def textW,textH,meanx,meany,sdev,c:int
def x,y,run:int
def pstep,pi,ret:float
def a$:string

autodefine "off"

window win,-800,0,800,600,@SYSMENU,0,"CBasic example",winh

control win,"B,Exit,(800-70)/2,470,70,30,@CTLBTNFLAT,1"
setfont win, "MS Sans Serif",12,600,0,1
setcontrolcolor win,1,rgb(100,200,250),rgb(10,10,100)

' draw a gradient fill in main window ..
pstep = 600.0 / 256 + 1
for band = 0 To 255
rect win, 0, int(band * pstep), 800, int((band+1) * pstep), rgb(0,0,band), rgb(0,0,band)
next band

pi = 4 * atan(1)

' set intro text ..
a$ = "Creative Basic Rocks"
frontpen win, RGB(60,60,255)
drawmode win,@TRANSPARENT
setfont win, "Arial",30,700, @SFITALIC
gettextsize win, a$, textW, textH
move win,(800-textW)/2,40
print win,a$

centerwindow win

' create some coloured spots ...
for i = 1 to 20
meanx = rnd(500)+150
meany = rnd(300)+50
sdev = 20
c = rgb(rnd(250)+50,rnd(250)+50,rnd(250)+50)
for j = 1 to 400
x = splot() * sdev + meanx
y = splot() * sdev + meany
pset win, x, y , c
next j
next i

' set intro text ..
a$ = "Creative Basic Rocks"
frontpen win, RGB(60,60,255)
drawmode win,@TRANSPARENT
setfont win, "Arial",30,700, @SFITALIC
gettextsize win, a$, textW, textH
move win,(800-textW)/2,40
print win,a$

run = 1

waituntil run = 0
closewindow win

END

sub winh
select @class
case @idclosewindow
run = 0
case @idcontrol
if @controlid = 1 then run = 0
endselect
return

sub splot()
def x1,x2:float
' routine to give a random value from the normal distribution ..
x1 = rnd(1)
x2 = rnd(1)
' catch very small values of x1 ..
if (x1 < 1.E-5) then x1 = 1.E-5
' the Normal curve value ..
ret = sqrt(-2.0*log(x1)) * cos(2*pi*x2)

return ret



all the best, :)

Graham
Tomorrow may be too late ..