Snakes / worms

Post Reply
DrChip
Posts: 167
Joined: Wed Oct 22, 2014 3:26 pm
My devices: iPhone 4 to 6+,iPad mini to iPad air 2

Snakes / worms

Post by DrChip »

REM
REM worms/snakes v1.0
REM iPhone 6 plus / 8.3 b1
REM real quick in the parking lot. :)

graphics
'screen area
scw = Screen_Width()
sch = Screen_Height()
csw = scw/2
csh = sch/2

sn=5 'number of snakes

DIM x(sn+1),y(sn+1),k(sn+1),l(sn+1),c(sn+1),d(sn+1)
DIM x1(sn+1),x2(sn+1),x3(sn+1),x4(sn+1),x5(sn+1),x6(sn+1),x7(sn+1)
DIM x8(sn+1),x9(sn+1),x10(sn+1),x11(sn+1),x12(sn+1),x13(sn+1),x14(sn+1)
DIM x15(sn+1),x16(sn+1),x17(sn+1),x18(sn+1)
DIM x19(sn+1),x20(sn+1),x21(sn+1)
DIM y1(sn+1),y2(sn+1),y3(sn+1),y4(sn+1),y5(sn+1),y6(sn+1),y7(sn+1)
DIM y8(sn+1),y9(sn+1),y10(sn+1),y11(sn+1),y12(sn+1),y13(sn+1),y14(sn+1)
DIM y15(sn+1),y16(sn+1),y17(sn+1),y18(sn+1)
DIM y19(sn+1),y20(sn+1),y21(sn+1)

PI=3.1415
ang=PI/180
dc1 = 1
dc2 = 1
dc3 = 1
c1=100
c2=150
c3=200
FOR a=1 TO sn
c(a)=RND(scw)
d(a)=RND(sch)
NEXT a
'PRINT "done randomizing..."


loop:
refresh off
'graphics clear 0,0,0
vm=1-vm

'PAUSE 0.021

FOR a=1 TO sn

k(a)=l(a)
c1=c1+dc1 'red
c2=c2+dc2 'green
c3=c3+dc3 'blue
IF c1>255 OR c1 < 1 THEN
dc1=-dc1
END IF
IF c2>255 OR c2 < 1 THEN
dc2=-dc2
END IF
IF c3>255 OR c3 < 1 THEN
dc3=-dc3
END IF

worm:
l(a)=INT(RND(36))

IF l(a) > ABS(k(a)-34) AND l(a) < ABS(k(a)-2) THEN
GOTO worm
END IF
IF l(a) > ABS(k(a)+2) AND l(a) < ABS(k(a)+34) THEN
GOTO worm
END IF
x(a)=c(a)
y(a)=d(a)
IF x(a)>scw THEN
x(a)=0
'y(a)=RND(sch)
END IF
IF x(a)<0 THEN
x(a)=scw
END IF
IF y(a)>sch THEN
y(a)=0
END IF
IF y(a)<0 THEN
y(a)=sch
END IF
d(a)=SIN(8*l(a)*ang)*8+y(a)
c(a)=COS(8*l(a)*ang)*8+x(a)

x21(a)=x20(a)
x20(a)=x19(a)
x19(a)=x18(a)
x18(a)=x17(a)
x17(a)=x16(a)
x16(a)=x15(a)
x15(a)=x14(a)
x14(a)=x13(a)
x13(a)=x12(a)
x12(a)=x11(a)
x11(a)=x10(a)
x10(a)=x9(a)
x9(a)=x8(a)
x8(a)=x7(a)
x7(a)=x6(a)
x6(a)=x5(a)
x5(a)=x4(a)
x4(a)=x3(a)
x3(a)=x2(a)
x2(a)=x1(a)
x1(a)=x(a)
y21(a)=y20(a)
y20(a)=y19(a)
y19(a)=y18(a)
y18(a)=y17(a)
y17(a)=y16(a)
y16(a)=y15(a)
y15(a)=y14(a)
y14(a)=y13(a)
y13(a)=y12(a)
y12(a)=y11(a)
y11(a)=y10(a)
y10(a)=y9(a)
y9(a)=y8(a)
y8(a)=y7(a)
y7(a)=y6(a)
y6(a)=y5(a)
y5(a)=y4(a)
y4(a)=y3(a)
y3(a)=y2(a)
y2(a)=y1(a)
y1(a)=y(a)

'erase tail
fill COLOR 0,0,0
fill CIRCLE x21(a),y21(a) size 8
'head
fill COLOR 1,1,1
fill CIRCLE x1(a),y1(a) size 7
'draw
fill COLOR c1/255,c2/255,c3/255
fill CIRCLE x(a),y(a) size 7

NEXT a
refresh on
GOTO loop
Attachments
image.jpg
image.jpg (109.45 KiB) Viewed 2204 times
image.jpg
image.jpg (104.31 KiB) Viewed 2204 times
image.jpg
image.jpg (109.41 KiB) Viewed 2204 times

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Snakes / worms

Post by Mr. Kibernetik »

Looks very cool! :D

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Snakes / worms

Post by Henko »

The same program, just my style of coding. ;)

Code: Select all

REM worms/snakes v1.0
REM iPhone 6 plus / 8.3 b1
REM real quick in the parking lot. :)

graphics ! refresh off ! option base 1
scw = Screen_Width() ! sch = Screen_Height()
csw = scw/2 ! csh = sch/2

sn=5 'number of snakes
DIM xj(sn,21),yj(sn,21)
dim x(sn),y(sn),k(sn),l(sn),c(sn),d(sn),col(3),dcol(3)

PI=3.1415 ! ang=PI/180 
for i=1 to 3 ! col(i)=50*(i+1) ! dcol(i)=1 ! next i
for a=1 TO sn ! c(a)=RND(scw) ! d(a)=RND(sch) ! next a
'PRINT "done randomizing..."

loop:
vm=1-vm ! 'PAUSE 0.021

FOR a=1 TO sn
k(a)=l(a)
for i=1 to 3
  if col(i)>255 or col(i)<1 then dcol(i)=-dcol(i)
  col(i)+=dcol(i)
  next i

worm:
l(a)=INT(RND(36))
IF l(a) > ABS(k(a)-34) AND l(a) < ABS(k(a)-2) THEN GOTO worm
IF l(a) > ABS(k(a)+2) AND l(a) < ABS(k(a)+34) THEN GOTO worm
x(a)=c(a) ! y(a)=d(a)
IF x(a)>scw THEN x(a)=0 ! IF x(a)<0 THEN x(a)=scw
IF y(a)>sch THEN y(a)=0 ! IF y(a)<0 THEN y(a)=sch
d(a)=SIN(8*l(a)*ang)*8+y(a) ! c(a)=COS(8*l(a)*ang)*8+x(a)
for j=20 to 1 step -1 ! xj(a,j+1)=xj(a,j) ! yj(a,j+1)=yj(a,j) ! next j
xj(a,1)=x(a) ! yj(a,1)=y(a)
fill COLOR 0,0,0 ! fill CIRCLE xj(a,21),yj(a,21) size 8  'erase tail
fill COLOR 1,1,1 ! fill CIRCLE xj(a,1),yj(a,1) size 7    ' head
fill COLOR col(1)/255,col(2)/255,col(3)/255
fill CIRCLE x(a),y(a) size 7                             ' draw

NEXT a ! refresh
GOTO loop

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Snakes / worms

Post by Mr. Kibernetik »

QUADRATISCH. PRAKTISCH. GUT. :!:

DrChip
Posts: 167
Joined: Wed Oct 22, 2014 3:26 pm
My devices: iPhone 4 to 6+,iPad mini to iPad air 2

Re: Snakes / worms

Post by DrChip »

Nice!

Post Reply