Dark Bit Factory & Gravity

PROGRAMMING => Other languages => Yabasic => Topic started by: bikemadness on November 01, 2008

Title: RE: Letter Scrambler
Post by: bikemadness on November 01, 2008
Nothing has changed from the last attempt: It still uses a LOT of IF statements.
But I did notice a pattern (been a while) and made it run faster (noticable on PS2)
I now notice another pattern and am unsure of implementing the method.

X to go


open window 640,512
a$="DBFINTERACTIVEISTHETOPS"
L=len(a$)
cen=(640-(L*15))/2
speed=1 rem 2 is fast
dim xm(26),xs(26),ym(26),sp(26),jump(26)
for a=1 to 26
xs(a)=a
xm(a)=a
ym(a)=230
text xm(a)*15+cen,ym(a),mid$(a$,a,1)
next a
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window
setrgb 1,256,256,0
fill rectangle 0,0 to 640,512
D=peek("port1")
go=go+1
if go>20 go=20
for a=1 to 26
if speed=1 then
if xm(a)>xs(a) xm(a)=xm(a)-0.2
if xm(a)<xs(a) xm(a)=xm(a)+0.2
jump(a)=abs(xm(a)-xs(a))/2
ym(a)=ym(a)-sp(a)
sp(a)=sp(a)-0.2
if ym(a)>230 ym(a)=230
if ym(a)=230 sp(a)=0
endif
if speed=2 xm(a)=xs(a)
if and(D,16384)>0 sp(a)=jump(a)
if and(D,16384)>0 and go=20 then
go=0
1 xs(1)=int(ran(L))+1
2 xs(2)=int(ran(L))+1
if xs(2)=xs(1) goto 2
3 xs(3)=int(ran(L))+1
for a=1 to 2
if xs(3)=xs(a) goto 3
next a
if L=3 goto fin
4 xs(4)=int(ran(L))+1
for a=1 to 3
if xs(4)=xs(a) goto 4
next a
if L=4 goto fin
5 xs(5)=int(ran(L))+1
for a=1 to 4
if xs(5)=xs(a) goto 5
next a
if L=5 goto fin
6 xs(6)=int(ran(L))+1
for a=1 to 5
if xs(6)=xs(a) goto 6
next a
if L=6 goto fin
7 xs(7)=int(ran(L))+1
for a=1 to 6
if xs(7)=xs(a) goto 7
next a
if L=7 goto fin
8 xs(8)=int(ran(L))+1
for a=1 to 7
if xs(8)=xs(a) goto 8
next a
if L=8 goto fin
9 xs(9)=int(ran(L))+1
for a=1 to 8
if xs(9)=xs(a) goto 9
next a
if L=9 goto fin
10 xs(10)=int(ran(L))+1
for a=1 to 9
if xs(10)=xs(a) goto 10
next a
if L=10 goto fin
11 xs(11)=int(ran(L))+1
for a=1 to 10
if xs(11)=xs(a) goto 11
next a
if L=11 goto fin
12 xs(12)=int(ran(L))+1
for a=1 to 11
if xs(12)=xs(a) goto 12
next a
if L=12 goto fin
13 xs(13)=int(ran(L))+1
for a=1 to 12
if xs(13)=xs(a) goto 13
next a
if L=13 goto fin
14 xs(14)=int(ran(L))+1
for a=1 to 13
if xs(14)=xs(a) goto 14
next a
if L=14 goto fin
15 xs(15)=int(ran(L))+1
for a=1 to 14
if xs(15)=xs(a) goto 15
next a
if L=15 goto fin
16 xs(16)=int(ran(L))+1
for a=1 to 15
if xs(16)=xs(a) goto 16
next a
if L=16 goto fin
17 xs(17)=int(ran(L))+1
for a=1 to 16
if xs(17)=xs(a) goto 17
next a
if L=17 goto fin
18 xs(18)=int(ran(L))+1
for a=1 to 17
if xs(18)=xs(a) goto 18
next a
if L=18 goto fin
19 xs(19)=int(ran(L))+1
for a=1 to 18
if xs(19)=xs(a) goto 19
next a
if L=19 goto fin
20 xs(20)=int(ran(L))+1
for a=1 to 19
if xs(20)=xs(a) goto 20
next a
if L=20 goto fin
21 xs(21)=int(ran(L))+1
for a=1 to 20
if xs(21)=xs(a) goto 21
next a
if L=21 goto fin
22 xs(22)=int(ran(L))+1
for a=1 to 21
if xs(22)=xs(a) goto 22
next a
if L=22 goto fin
23 xs(23)=int(ran(L))+1
for a=1 to 22
if xs(23)=xs(a) goto 23
next a
if L=23 goto fin
24 xs(24)=int(ran(L))+1
for a=1 to 23
if xs(24)=xs(a) goto 24
next a
if L=24 goto fin
25 xs(25)=int(ran(L))+1
for a=1 to 24
if xs(25)=xs(a) goto 25
next a
if L=25 goto fin
26 xs(26)=int(ran(L))+1
for a=1 to 25
if xs(26)=xs(a) goto 26
next a
if L=26 goto fin
endif
label fin
setrgb 1,0,0,0
text xm(a)*15+cen,ym(a),mid$(a$,a,1)
next a
until (1=0)

Title: Re: RE: Letter Scrambler
Post by: rain_storm on October 11, 2009
Quote from: bikemadness on November 01, 2008
It still uses IF statements.

Not any more it doesn't


open window 640,512
a$="DBFINTERACTIVEISTHETOPS"
L=len(a$)
cen=(640-(L*15))/2
speed=1 rem 2 is fast
dim xm(26),xs(26),ym(26)
for a=1 to 26
xs(a)=a
xm(a)=a
ym(a)=230
text xm(a)*15+cen,ym(a),mid$(a$,a,1)
next a
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window
setrgb 1,256,256,0
fill rectangle 0,0 to 640,512
D=peek("port1")
go=go+1
if go>20 go=20
for a=1 to 26
if speed=1 then
if xm(a)>xs(a) then
xm(a)=xm(a)-0.25
ym(a)=ym(a)-5
if ym(a)<222 ym(a)=222
if xm(a)=xs(a) ym(a)=230
endif
if xm(a)<xs(a) then
xm(a)=xm(a)+0.25
ym(a)=ym(a)+5
if ym(a)>238 ym(a)=238
if xm(a)=xs(a) ym(a)=230
endif
endif
if speed=2 xm(a)=xs(a)
if and(D,16384)>0 and go=20 then
go=0

for l = 0 to L
0 xs(l) = int(ran(L))+1
  for a=0 to l
    if (a <> l) and (xs(l) = xs(a)) goto 0
  next a
next l
goto fin
endif

label fin
setrgb 1,0,0,0
text xm(a)*15+cen,ym(a),mid$(a$,a,1)
next a
until (1=0)

Title: Re: RE: Letter Scrambler
Post by: bikemadness on October 12, 2009
Wow! Thanks.
Do you know how long it would have taken me to see that! (if at all.)
It took me ages to shorten my first version.
And I would still need to see it that way to understand it in future.
I use this as a tool all the time.
Had to write my own, since I couldn't find a version.