Wednesday, October 31, 2012

Walk on by


# A rough attempt to model human walking
clg
graphsize 900,300
Fastgraphics
Dim limb(8)
limb = {0, 0, 0, 100, 10, 100,10,0}
y=140
people=10
Dim x(people)
Dim dx(people)
Dim r(people)
Dim g(people)
Dim b(people)
For n=0 to people-1
x[n]=int(rand*900)
dx[n]=(-1)^int(rand*2+1)
r[n]=int(rand*255)
g[n]=int(rand*255)
b[n]=int(rand*255)
next n
For p=0 to 10000
gosub walkman
next p
walkman:
clg
For n=0 to people-1
color r[n],g[n],b[n]
x[n]=x[n]+dx[n]
if x[n]<0 then x[n]=900
if x[n]>900 then x[n]=0
ywable=-10*abs(sin(x[n]*.03+pi/2))
xwable=-30*abs(sin(x[n]*.03))
leftrot=sin(x[n]*.03)/2
rightrot=sin(x[n]*.03+pi)/2
circle x[n]-xwable+5,y+ywable-25,15
stamp x[n]-xwable,y+60+ywable,1,leftrot,limb
stamp x[n]-xwable,y+ywable,.8,leftrot,limb
color r[n],0,b[n]
rect x[n]-10-xwable,y+ywable,30,70
color rgb( r[n],g[n],b[n])
stamp x[n]-xwable,y+60+ywable,1,rightrot,limb
stamp x[n]-xwable,y+ywable,.8,rightrot,limb
next n
refresh
return

Saturday, October 20, 2012

Krypto - make the target number


# This program uses the new functions and subroutines from version 0.9.9.1










cls
clg
dim n(4)
dim op$(4)
target = int (rand*60)
n[0]=int (rand*10)+1
n[1]=int (rand*10)+1
n[2]=int (rand*10)+1
n[3]=int (rand*10)+1
graphsize 600,200
font "arial",40,100
text 0,20, "Target number is : "+ target
text 0,100, "Use only: "+ n[0]+", "+n[1]+", "+n[2]+", "+n[3]
counter=0
op$[0]="+"
op$[1]="-"
op$[2]="*"
op$[3]="/"
for turn = 1 to 2
For t1 = 0 to 3
For t2 = 0 to 3
For t3 = 0 to 3
For t4 = 0 to 3
For t5 = 0 to 3
For t6 = 0 to 3
For t7 = 0 to 3
if t1<>t3 and t3<>t5 and t5<>t7 and t1<>t5 and t3<>t7 and t1<>t7 then
a=eval(op$[t2],n[t1],n[t3])
c=eval(op$[t6],n[t5],n[t7])
ac=eval(op$[t4],a,c)
if ac = target and turn =2 then Print "("+ n[t1]+op$[t2]+n[t3]+")"+op$[t4]+"("+ n[t5]+op$[t6]+n[t7]+")="+ac
if ac = target and turn =1 then counter = counter +1
b=eval(op$[t4],n[t3],n[t5])
ba=eval(op$[t2],n[t1],b)
bac=eval(op$[t6],ba,n[t7])
if bac= target and turn =2 then Print "(("+ n[t1]+op$[t2]+"("+n[t3]+op$[t4]+n[t5]+"))"+op$[t6]+n[t7]+"="+bac
if bac = target and turn =1 then counter = counter +1
bc=eval(op$[t6],b,n[t7])
bca=eval(op$[t2],n[t1],bc)
if bca= target and turn =2 then Print n[t1]+op$[t2]+"(("+n[t3]+op$[t4]+n[t5]+")"+op$[t6]+n[t7]+")="+bca
if bca = target and turn =1 then counter = counter +1
ab=eval(op$[t4],a,n[t5])
abc=eval(op$[t6],ab,n[t7])
if abc= target and turn =2 then Print "(("+ n[t1]+op$[t2]+n[t3]+")"+op$[t4]+n[t5]+")"+op$[t6]+n[t7]+"="+abc
if abc = target and turn =1 then counter = counter +1
cb=eval(op$[t4],n[t3],c)
cba=eval(op$[t2],n[t1],cb)
if cba = target and turn =2 then Print n[t1]+op$[t2]+"("+n[t3]+op$[t4]+"("+n[t5]+op$[t6]+n[t7]+"))="+cba
if cba = target and turn =1 then counter = counter +1
end if
next t7
next t6
next t5
next t4
next t3
next t2
next t1
print "Number of solutions "+counter
input "press any key to get solutions",a
next turn
function eval(e$,x,y)
if e$="*" then eval = x*y
if e$="/" and y<>0 then eval = x/y
if e$="/" and y=0 then eval = 10000000
if e$="-" then eval = x-y
if e$="+" then eval = x+y
end function

Friday, October 12, 2012

Multiparticle collider


Rem 2D collisions
fastgraphics
m=6
n=m^2
Dim x(n)
Dim y(n)
Dim vx(n)
Dim vy(n)
Dim mass(n)
Dim colisionflag(n,n)
ed=1
u=0
rem initial variables
for a = 0 to m-1
for b = 0 to m-1
x[u]=50*a+10
y[u]=50*b+10
vx[u]=rand-.5
vy[u]=rand-.5
mass[u]=7
u=u+1
next b
next a
Rem main loop
While 1=1
for u = 0 to n-1
If x[u]<mass[u] or x[u]>(300-mass[u]) then vx[u]=-vx[u]
If y[u]<mass[u] or y[u]>(300-mass[u]) then vy[u]=-vy[u]
x[u]=x[u]+vx[u]
y[u]=y[u]+vy[u]
color rgb (u*7,0,255-u*7)
circle x[u],y[u],mass[u]
next u
refresh
clg
gosub colision
end while
colision:
rem collision detection
for u1 = 0 to n-2
for u2 = u1+1 to n-1
dx = x[u2]-x[u1]
dy = y[u2]-y[u1]
distance = (dx*dx+dy*dy)^.5
if distance < (mass[u1]+mass[u2]) then
if colisionflag[u1,u2]=0 then
rem vx and vy calc
ax=dx/distance
ay=dy/distance
va1=vx[u1]*ax+vy[u1]*ay
vb1=-vx[u1]*ay+vy[u1]*ax
va2=vx[u2]*ax+vy[u2]*ay
vb2=-vx[u2]*ay+vy[u2]*ax
vaP1=va1 + (1+ed)*(va2-va1)/(1+mass[u1]/mass[u2])
vaP2=va2 + (1+ed)*(va1-va2)/(1+mass[u2]/mass[u1])
vx[u1]=vaP1*ax-vb1*ay
vy[u1]=vaP1*ay+vb1*ax
vx[u2]=vaP2*ax-vb2*ay
vy[u2]=vaP2*ay+vb2*ax
colisionflag[u1,u2]=1
end if
else
colisionflag[u1,u2]=0
end if
next u2
next u1
return