Monday, March 25, 2013

News (1)

Found this interesting article about cbm Hand BASIC on the web:

http://www.wickensonline.co.uk/rc2012sc/2012/07/29/messing-with-cbmhandbasic-for-the-ipad/

Thursday, March 21, 2013

Text Wave-Example (2)


This program teaches the basics of animation by animating text with sine wave. To keep program simple I made many parameters fixed.

Things to try:
- change the animated text or better make the user enter the text (LINE 50)
- change sine wave magnitude (LINE 2020)
- change the animation resolution D (LINE 1130)
- change the wave frequency F (LINE 1120)

full program:

10 SCREEN 1
20 TITLE "Text Wave"
30 W = 1024
40 H = 768-20
50 T$ = "CBM Hand BASIC"
60 L = LEN(T$)
70 DIM CC(5)
80 CC(0) = 3
90 CC(1) = 1
100 CC(2) = 6
110 CC(3) = 3
120 CC(4) = 2
130 CC(5) = 1
140 DIM P(20, 3)
150 FSET "Commodore_64_Angled", 64
1000 C = 0
1010 FOR I = 0 TO L-1
1020 E$ = MID$(T$, I+1, 1)
1030 P(I, 0) = ASC(E$)
1040 P(I, 1) = CC(C)
1050 P(I, 2) = 180 + 50 * I
1060 P(I, 3) = 0
1070 IF P(I, 0) <> 32 THEN C = C + 1 
1080 IF C = 6 THEN C = 0
1090 NEXT I
1100 PI = 3.14159
1110 T = PI * 3/4
1120 F = PI / 8
1130 D = PI / 220
2000 REM [WAVE MOVE]
2010 FOR I = 0 TO L-1
2020 P(I, 3) = H/2 + 120*SIN(T - F * I)
2030 T = T + D
2040 IF T >= 2*PI THEN T = T - 2 * PI
2050 NEXT I
3000 REM [DRAW]
3010 BEGINFRAME
3020 CLS
3030 FOR I = 0 TO L-1
3040 R$ = CHR$( P(I, 0) )
3050 C = P(I, 1)
3060 X = P(I, 2)
3070 Y = P(I, 3)
3080 GPRINT R$, X, Y, C
3090 NEXT I
3100 ENDFRAME
4000 GOTO 2000

Friday, March 8, 2013

Polar Plotter-Example (1)


This program plots polar functions of the form
radius = f(angle)
Program settings are made for iPad. To run on iPhone/iPod Touch change:
W = 320
H = 460
U = 20

change line 160 to plot other polar functions
160 DEF FN F(T) = 5
160 DEF FN F(T) = T / (2 * PI)
160 DEF FN F(T) = 5 * SIN(4 * T)
160 DEF FN F(T) = 4 * SIN(6 * T) + 4

to understand math behind polar plotting I recommened Wikipedia: Go Wiki

full program:

10 REM POLAR PLOT PROGRAM
20 REM INIT
30 SCREEN 1
40 W = 768
50 H = 1024-20
60 U = 40
70 XC = W / 2
80 YC = H / 2
90 DEF FN MX(X) = XC + X * U
100 DEF FN MY(Y) = YC - Y * U
110 S = 1 / U
120 PI = 3.1415926
130 REM DRAW AXIS
140 GOSUB 1000
150 REM SET PARAMETERS
160 DEF FN F(T) = 5*SIN(6*T)-1
170 C = 3
180 TS = 0
190 TF = 2 * PI
200 GPRINT "r = 5 sin(6 theta)-1", 10, 80, C
210 REM PLOT
220 GOSUB 2000
230 SLEEP 15000
240 END
1000 REM [DRAW AXIS]
1010 CLS
1020 N = INT(XC / U)
1030 FOR I = 1 TO N
1040 CIRCLE XC, YC, I * U, 15, 0
1050 NEXT I
1060 LINE XC, 0, XC, H, 1
1070 LINE 0, YC, W, YC, 1
1080 RETURN
2000 REM [PLOT]
2010 T = TS
2020 R = FN F(T)
2030 X = R * COS(T)
2040 Y = R * SIN(T)
2050 XX = FN MX(X)
2060 IF XX < 0 THEN XX = 0
2070 YY = FN MY(Y)
2080 IF YY < 0 THEN YY = 0
2090 MOVETO XX, YY
2100 T = T + S
2110 R = FN F(T)
2120 X = R * COS(T)
2130 Y = R * SIN(T)
2140 XX = FN MX(X)
2150 IF XX < 0 THEN XX = 0
2160 YY = FN MY(Y)
2170 IF YY < 0 THEN YY = 0
2180 LINETO XX, YY, C
2190 IF T <= TF THEN 2100
2200 FRAME 0, 0, W-1, H-1, 0
2210 RETURN