PDA

View Full Version : Basic-256 or ( Kids Basic )



zak
21-01-2011, 18:23
basic-256 called sometimes kidsbasic , i know it from allbasic site, it is realy beautifull, its site http://www.basic256.org/index_en it has a free ebook :http://www.basicbook.org/Book , it is designed for teaching kids programming, but can be used by everyone. currently it lacks sub and Functions and the ability to call libs and dlls, instead of subs there is Gosub ... return like the old Dos GWBASIC "who remember it !!". one of the major features is that the graphics window attached to the ide but by clicking on its top right it can float separately.
try this example :
say 1234567 and it will say in words the number, so open the speaker
say 2+3 and it will say Five, so it is a fun for kids.
i have tried one of its examples fractal forces in thinbasic but i can't implement the line "stamp x,y,q,v,f" and i have replaced it by a line draw instead of a thin polygon reduced and rotated.
http://doc.basic256.org/doku.php?id=galleryjoelkahn
the graphic window designed using qt library from nokia company. and the language designed with c++ . available as windows Installer or Source Code (LINUX and Mac OS X).

Uses "UI","math"
Dim ScreenWidth As Long = 800
Dim ScreenHeight As Long = 600
Dim hWin As DWord '---Handle of the canvas window
Dim colr, colrFill,xs,xm,ys,ym,d As Long
Dim q,qq,v,vv,br,bi,tr,ti,x,y,c,ar,ai,lin As Double
hWin = Canvas_Window("Parrot Fractal", 1, 1, ScreenWidth, ScreenHeight )
Canvas_Attach(hWin, 0, %TRUE) ' <- double buffer

'---Init canvas
Canvas_Clear(%BLACK)

q=1.0
qq=0.9997
v=0.01
vv=0.0004
xs=750
xm=650
ys=730
ym=180
c=0
br=-0.7393
bi=0.117
ar=0
ai=0
For d=1 To 9000
tr=ar*ar-ai*ai+br
ti=2*ar*ai+bi
x=tr*xs+xm
y=ti*ys+ym
v=v+vv
q=q*qq
c=d^2.1
'stamp x,y,q,v,{0,0,50,0,50,1,0,1}

Canvas_Line((x,y),(x+50*q,y+v),c)
'Canvas_Redraw
ar=tr
ai=ti
Next d
Canvas_Redraw
Canvas_WaitKey
Canvas_Window End


http://img6.imageshack.us/img6/9864/parrot.png

Petr Schreiber
21-01-2011, 19:25
Hi Zak,

thanks for your code.

Looking at the stamp:

stamp x,y,q,v,{0,0,50,0,50,1,0,1}The polygon it draws is in fact 50px long line of width 2. You can set width in ThinBASIC canvas by:


Canvas_Width(2)
The parameter q is scale and v angle in radians. We can calculate the angle transformation using COS for X and SIN for Y.

So the equivalent of stamp line becomes:


Canvas_Line( (x, y) , (x + (Cos(v)*50*q), y + (Sin(v)*50*q)) )
The final code is then:


Uses "UI"

Dim ScreenWidth As Long = 700
Dim ScreenHeight As Long = 500
Dim hWin As DWord '---Handle of the canvas window
Dim colr, colrFill,xs,xm,ys,ym,d As Long
Dim q,qq,v,vv,br,bi,tr,ti,x,y,c,ar,ai,lin As Double

hWin = Canvas_Window("Parrot Fractal", 1, 1, ScreenWidth, ScreenHeight )
Canvas_Attach(hWin, 0, %TRUE) ' <- double buffer

'---Init canvas
Canvas_Clear(%BLACK)
Canvas_Width(2)

q = 1.0
qq = 0.9997
v = 0.01
vv = 0.0004
xs = 750
xm = 650
ys = 730
ym = 180
c = 0
br = -0.7393
bi = 0.117
ar = 0
ai = 0

For d = 1 To 15000

tr = ar * ar - ai * ai + br
ti = 2 * ar * ai + bi
x = tr * xs + xm
y = ti * ys + ym
v = v + vv
q = q * qq
c = d ^ 2.1

Canvas_Color(c)
Canvas_Line((x,y),(x+(Cos(v)*50*q),y+(Sin(v)*50*q)))

ar = tr
ai = ti
Next

Canvas_Redraw
Canvas_WaitKey
Canvas_Window End

zak
21-01-2011, 20:19
you are marvelous Petr thank you, your code produced the supposed picture from the original code . my brain stuck on the coordinate geometry.
best wishes