Friday, January 11, 2013
Thursday, January 10, 2013
Trigonometric Functions
graphsize 500,350
hip ={0,0,60,0,60,3,0,3,0,0}
fastgraphics
for n = 0 to pi*2 step .01
color black
circle 70,70,62
color white
circle 70,70,58
color black
stamp 70,70,1,-n,hip
rect 140,70,400,3
rect 140,250,400,3
color red
if cos(n)>0 then rect 70,70,60*cos(n),3
if cos(n)<0 then rect 70-60*cos(n+pi),70,60*cos(n+pi),3
color blue
if sin(n)>0 then stamp 70+cos(n)*60,70,sin(n),-pi/2,hip
if sin(n)<0 then stamp 70+cos(n)*60,70,sin(pi+n),pi/2,hip
color blue
circle n*50+140,50*sin(n+pi)+70,2
color red
circle n*50+140,50*cos(n+pi)+250,2
refresh
next n
Tuesday, January 8, 2013
Sprites
![]() |
| Town |
![]() |
| Cars |
clg
# For this program to work you need to copy the pictures and save in your disk/pen, and then change the path in imgload if necessary.
# This is the sprite sheet
imgload 150,75,"G:\cars.png"
spritedim 16
n=0
fastgraphics
# slicing vehicles from the sprite sheet
for y = 0 to 112.5 step 37.5
for x = 0 to 225 step 75
spriteslice n,x,y,75,37.5
n=n+1
next x
next y
pause 2
graphsize 600,300
#Backgroud image
imgload 300,150,"G:\town.png"
# Placing vehicles
for n = 0 to 3
spriteplace n,int(rand*20)+n*100,260
spriteshow n
next n
for n = 4 to 7
spriteplace n,int(rand*20)+n*100-300,265
spriteshow n
next n
for n = 8 to 11
spriteplace n,int(rand*20)+n*100-700,275
spriteshow n
next n
for n = 12 to 15
spriteplace n,int(rand*20)+n*100-1100,280
spriteshow n
next n
# Makes sprites move
loop:
for n = 0 to 7
if n>-1 and n<4 then spritemove n,1.2,0
if n>3 and n<8 then spritemove n,.8,0
if spritex (n) = 600 then spritemove n,-600,0
next n
for n = 8 to 15
if n>7 and n<12 then spritemove n,-1.2,0
if n>11 and n<16 then spritemove n,-.8,0
if spritex (n) = 0 then spritemove n,600,0
next n
refresh
goto loop
Charater count
# Gives a count of each character from t$
t$ = "Les Misérables, is a sung-through musical play based on the novel of the same name by French poet and playwright Victor Hugo. It has music by Claude-Michel Schönberg, original French lyrics by Alain Boublil and Jean-Marc Natel, with an English-language libretto by Herbert Kretzmer(...)"
font("arial",11,100)
t$ = lower(t$)
clg
long= length (t$)
dim letters(255)
for n=1 to long
for x = 0 to 254
if chr(x)= mid(t$,n,1)then letters[x]=letters[x]+1
next x
next n
#Frequency table
for x = 0 to 254
if letters[x]>0 then print chr(x)+" "+letters[x]
next x
# Bar chart (onlny for plain letters)
bar = 0
for x = 97 to 125
if letters[x]>0 then
Text 0,bar*12,chr(x)
rect 13,bar*12+6,letters[x],8
bar=bar+1
end if
next x
t$ = "Les Misérables, is a sung-through musical play based on the novel of the same name by French poet and playwright Victor Hugo. It has music by Claude-Michel Schönberg, original French lyrics by Alain Boublil and Jean-Marc Natel, with an English-language libretto by Herbert Kretzmer(...)"
font("arial",11,100)
t$ = lower(t$)
clg
long= length (t$)
dim letters(255)
for n=1 to long
for x = 0 to 254
if chr(x)= mid(t$,n,1)then letters[x]=letters[x]+1
next x
next n
#Frequency table
for x = 0 to 254
if letters[x]>0 then print chr(x)+" "+letters[x]
next x
# Bar chart (onlny for plain letters)
bar = 0
for x = 97 to 125
if letters[x]>0 then
Text 0,bar*12,chr(x)
rect 13,bar*12+6,letters[x],8
bar=bar+1
end if
next x
Sunday, January 6, 2013
Friday, January 4, 2013
Famous characters 1
#Complete the two famous characters. And post your code as a comment.
fastgraphics
color darkgreen
rect 0,0,300,300
call hairyhead(80,150,40,60,yellow)
call hairyhead(220,150,55,45,orange)
color black
rect 55,120,50,6
Rem put the rest of the code here
refresh
subroutine hairyhead (x,y,xradius,yradius,cor)
color cor
for r = 0 to 1 step .001
arc x-r*xradius,y-r*yradius,2*r*xradius,2*r*yradius,0,pi*2
next r
for n = -17*(xradius/yradius) to 17*(xradius/yradius) step .02
color black
stamp n+x,y-yradius*.9,rand*3,pi+rand*3.6-1.8,{0,0,0,10,0,0}
next n
end subroutine
Engine
#engine parts made with stampmaker
graphsize 720,300
rod={2,1,2,-1,1,-2,-13,-2,-14,-1,-14,1,-13,2,1,2,2,1}
piston={-1,1,-1,-1,0,-2,5,-2,6,-3,13,-3,13,3,6,3,5,2,0,2,-1,1}
cylinder={-3,3,10,3,10,-3,-3,-3,-3,-4,11,-4,13,0,11,4,-3,4,-3,3}
cross={-1,4,1,4,1,1,4,1,4,-1,1,-1,1,-4,-1,-4,-1,-1,-4,-1,-4,1,-1,1,-1,4}
fastgraphics
for x = 0 to 10000 step .1
clg
color rgb(80,80,80)
stamp 480+35*cos(x),150,10,sin(x)/4,rod
color rgb(20,20,20)
circle 360,150,50
color rgb(120,120,120)
stamp 360,150,10,-x,cross
color rgb(80,80,80)
stamp 240+35*(-cos(x)),150,10,-sin(-x)/4+pi,rod
color rgb(20,20,20)
stamp 480+35*cos(x),150,10,piston
stamp 240+35*(-cos(x)),150,10,pi,piston
stamp 560,150,10,cylinder
stamp 160,150,10,pi,cylinder
color rgb(120*(sin(x))+125,127,120*(sin(x+pi))+125)
rect 61,121,35*(-cos(x))+49,59
rect 611-35*(-cos(x)),121,35*(-cos(x))+52,59
refresh
rem pause .01
next x
Stampmaker
# Draw a shape then copy the array and use it for Stamps
graphsize 800,500
fastgraphics
print "Shape={";
oldx=0
oldy=0
n=2
dim shape(2)
init= true
fin = false
clickclear
decimal(0)
loop:
gosub drawgraph
circle mousex,mousey,3
color red
circle shape[0],shape[1],4
color black
refresh
clg
x=clickx/20-20
y=-clicky/20+12
if n>3 and shape[n-2]=shape[0] and shape[n-1]=shape[1]then fin=true
# Checks for new click
if oldx<>clickx or oldy<>clicky then
if init = true then print x+","+y;
if init = false then
print ","+x+","+y;
n=n+2
end if
init= false
redim shape(n)
shape[n-2]= round (clickx,20)
shape[n-1]= round (clicky,20)
end if
oldx=clickx
oldy=clicky
if n > 3 then call draw (ref(shape),n,fin)
goto loop
subroutine draw(ref(shape),n,fin)
for p = 4 to n step 2
line shape[p-4],shape[p-3],shape[p-2],shape[p-1]
next p
if fin = true then
refresh
Print "}"
stamp 0,0,shape
refresh
print "Copy paste and run"
end
end if
end subroutine
drawgraph:
color black
for y= 0 to 480 step 20
for x= 0 to 800 step 20
circle x,y,2
next x
next y
line 0,240,800,240
line 400,0,400,480
return
function round(number,nearest)
if number%nearest<nearest/2 then
round = int (number/nearest)*nearest
else
round = int (number/nearest)*nearest+nearest
end if
end function
Wednesday, January 2, 2013
Mr Winky
# requires BASIC256 version 0.9.9.25 or later
# New functions (chord , arc , pie) showcase. Based on Jim's program
clg
color yellow
circle 150,150,150
color black
circle 100,100,20
circle 100,100,20
chord 50,50,200,200, radians(135), radians(90)
arc 190,80,40,40,radians(90),radians(180)
pie 110,90,80,80,radians(135),radians(90)
end
Sunday, December 30, 2012
Saturday, December 29, 2012
Rosetta Code example
# This is a code example in basic 256 that you can find in Rosetta code website http://rosettacode.org/wiki/Greyscale_bars/Display. There you will find this program (and more) in many other languages such as Java Python and C, and that is a very good way to learn new programming languages.
h=ceil(graphheight/4)
for row=1 to 4
w=ceil(graphwidth/(8*row))
c=255/(8*row-1)
for n = 0 to (8*row-1)
color rgb(255-c*n,255-c*n,255-c*n)
if row/2 = int(row/2) then color rgb(c*n,c*n,c*n)
rect n*w,h*(row-1),w,h
next n
next row
Friday, December 28, 2012
Gears
clg
fastgraphics
dim x(3)
dim y(3)
dim rad(3)
dim init(3)
x[0]=150
y[0]=150
rad[0]=70
init[0]=0
x[1]=220
y[1]=220
rad[1]=35
init[1]=-.15
x[2]=90
y[2]=90
rad[2]=21
init[2]=.2
for rot = 0 to 100000
for w = 0 to 2
circle x[w],y[w],rad[w]-8
tri = {0, 0, -5, rad[w], 5, rad[w]}
for r = 0 to 2*pi step pi*7/rad[w]
if w=1 or w=2 then clock = -rot
if w=0 then clock = rot
stamp x[w],y[w],1,r+init[w]+clock/(7*rad[w]),tri
next r
next w
refresh
clg
next rot
Saturday, December 22, 2012
Flags 2
# Union jack
color blue
rect 0,0,300,300
color white
poly {0,20,0,0,20,0,300,280,300,300,280,300}
poly {280,0,300,0,300,20,20,300,0,300,0,280}
color red
poly {0,10,0,0,10,0,300,290,300,300,290,300}
poly {290,0,300,0,300,10,10,300,0,300,0,290}
color white
rect 120,0,60,300
rect 0,120,300,60
color red
rect 130,0,40,300
rect 0,130,300,40
pause 2
# Stars and Stripes
for n = 0 to 13 step 2
color red
rect 0,n*23,300,23
color white
rect 0,(n+1)*23,300,23
next n
font "arial",15,100
color blue
rect 0,0,120,7*23
color white
for x = 1 to 6
for y = 1 to 5
text x*18-8,y*34-27,"*"
next y
next x
for x = 1 to 5
for y = 1 to 4
text x*18,y*34-10,"*"
next y
next x
Rem Триколор
color white
rect 0,0,300,100
color blue
rect 0,100,300,100
color red
rect 0,200,300,100
Thursday, December 20, 2012
Train
# by C&F
fastgraphics
x=0
speed=1
loop:
x=x+speed
speed=speed+.03
if x>1 then speed=2
clg
pause .01
color black
if x > 400 then x=-100
rect 10+x,160,30,60
color orange
rect 10+x,195,120,50
color grey
circle 70+x,250,15
circle 110+x,250,15
circle 35+x,250,15
color black
circle 70+x,250,5
circle 110+x,250,5
circle 35+x,250,5
colour black
rect -30+x,220,40,10
color red
rect -100+x,195,75,50
color grey
circle -80+x,250,15
circle -40+x,250,15
color black
circle -80+x,250,5
circle -40+x,250,5
refresh
goto loop
fastgraphics
x=0
speed=1
loop:
x=x+speed
speed=speed+.03
if x>1 then speed=2
clg
pause .01
color black
if x > 400 then x=-100
rect 10+x,160,30,60
color orange
rect 10+x,195,120,50
color grey
circle 70+x,250,15
circle 110+x,250,15
circle 35+x,250,15
color black
circle 70+x,250,5
circle 110+x,250,5
circle 35+x,250,5
colour black
rect -30+x,220,40,10
color red
rect -100+x,195,75,50
color grey
circle -80+x,250,15
circle -40+x,250,15
color black
circle -80+x,250,5
circle -40+x,250,5
refresh
goto loop
Blimp
# Blimp by R
clg
fastgraphics
x=0
y=60
font "arial",15,50
loop:
x=x+.2
if x>300 then x = -220
color grey
circle 150-x,70+y,50
circle 120-x,70+y,50
circle 180-x,70+y,50
color black
rect 100-x,100+y,100,40
Text 120-x,70+y,"R&S Inc."
color white
circle 120-x,120+y,5
circle 150-x,120+y,5
circle 180-x,120+y,5
refresh
clg
goto loop
Cool person
# Cool person by R
clg
color 255,160,160
circle(150,50,50)
color 255,160,160
rect(146,100,10,10)
color blue
circle(130,40,5)
color blue
circle(170,40,5)
color yellow
x=120
y=15
poly {x+25,y+25,x+50,y+50,x+25,y+50}
color red
rect(140,80,30,10)
color green
rect(100,110,110,75)
color red
rect (130,75,10,10)
color red
rect (170,75,10,10)
Ambulance
# Ambulance by V
fastgraphics
x=0
y=0
loop:
x=x+1
if x>1000 then x = 0
colour darkgreen
rect 0,0,900,300
colour red
circle 950-x,225+y,10
color White
rect 910-x,270+y,60,20
rect 930-x,230+y,70,60
color red
rect 950-x,250+y,30,10
color red
rect 960-x,240+y,10,30
color black
circle 925-x,290+y,10
circle 990-x,290+y,10
refresh
clg
goto loop
fastgraphics
x=0
y=0
loop:
x=x+1
if x>1000 then x = 0
colour darkgreen
rect 0,0,900,300
colour red
circle 950-x,225+y,10
color White
rect 910-x,270+y,60,20
rect 930-x,230+y,70,60
color red
rect 950-x,250+y,30,10
color red
rect 960-x,240+y,10,30
color black
circle 925-x,290+y,10
circle 990-x,290+y,10
refresh
clg
goto loop
Sunday, December 2, 2012
Venny
#Venn diagrams and logical operators
Font "Arial",30,100
Font "Arial",30,100
For s = 1 to 5
clg
Text 20,20 ,"A"
Text 260,20 ,"B"
gosub circles
For n = 1 to 2000
x=rand*300
y=rand*300
A=0
B=0
gosub checkA
gosub checkB
if s = 1 then gosub one
if s = 2 then gosub two
if s = 3 then gosub three
if s = 4 then gosub four
if s = 5 then gosub five
next n
next s
end
one:
Text 140,250 ,"A"
if A=1 then circle x,y,2
return
two:
Text 100,250 ," A"+chr(1352)+"B"
if A=1 and B=1 then circle x,y,2
return
three:
Text 100,250 ," A"+chr(1357)+"B"
if A=1 or B=1 then circle x,y,2
return
four:
Text 120,250 ,"A'"
if not A=1 then circle x,y,2
return
five:
Text 100,250 ,"(A"+chr(1357)+"B)'"
if not (A=1 or B=1) then circle x,y,2
return
checkA:
if (x-100)^2+(y-150)^2<10000 then A=1
Return
checkB:
if (x-200)^2+(y-150)^2<10000 then B=1
Return
circles:
For x = 1 to 300
y=(-(x-200)^2+10000)^.5+150
circle x,y,2
circle x,-y+300,2
circle x-100,y,2
circle
x-100,-y+300,2
next x
return
Wednesday, November 28, 2012
Sunday, November 11, 2012
3D Bounce
graphsize 900,450
fastgraphics
vx=2
vy=3
vz=5
x=10
y=10
z=14
Loop:
color darkred
rect 0,0,900,450
color rgb(0,123,0)
poly{0,300,450,450,900,300,450,150}
color rgb(0,83,0)
poly{0,300,450,150,450,0,0,150}
color rgb(0,103,0)
poly{900,300,450,150,450,0,900,150}
color red
vz=vz-.05
x=x+vx
y=y+vy
z=z+vz
vz=vz-.05
h=(x+y)*cos(1/3)
v=300-(-x+y)*sin(1/3)
if x>465 then vx=-vx
if x<0 then vx=-vx
if y>465 then vy=-vy
if y<0 then vy=-vy
if z<0 then vz=-vz
color black
rect h,v,10,2
color red
circle h,v-z,10
refresh
clg
goto Loop
Friday, November 9, 2012
Golden Waves
graphsize 600,600
fastgraphics
for t=1 to 60 step .1
color darkred
rect 0,0,600,600
For y1 = 0 to 24
For x1 = 0 to 24
x=12*(24-x1)+12*y1
y=-6*(24-x1)+6*y1+300
d= ((10-x1)^2+(10-y1)^2)^.5
h=60*sin(x1/4+t)+65
if t>10 and t<20 then h=60*sin(y1/4+t)+65
if t>20 and t<30 then h=60*sin((x1-y1)/4+t)+65
if t>30 and t<40 then h=30*sin(x1/2+t)+30*sin(y1/2+t)+65
if t>40 and t<50 then h=60*sin((x1+y1)/4+t)+65
if t>50 and t<60 then h=60*sin(d*.3+t)+65
color rgb(100+h,100+h,h)
poly{x,y-h,x+10,y+5-h,x+20,y-h,x+10,y-5-h}
color rgb(60,60,0)
poly{x,y-h,x+10,y+5-h,x+10,y,x,y-5}
color rgb(150,150,0)
poly{x+10,y+5-h,x+10,y,x+20,y-5,x+20,y-h}
next x1
next y1
refresh
clg
next t
Thursday, November 1, 2012
Flags
# By C
color orange
rect (50,250,20,50)
color darkblue
rect (50,50,1000,220)
color orange
rect (100,270,20,30)
color red
rect (0,0,1000,750)
color white
rect (0,110,1000,100)
color blue
rect(0,200,1000,750)
Pause 2
color orange
rect (50,250,20,50)
color darkblue
rect (50,50,1000,220)
color orange
rect (100,270,20,30)
color red
rect (0,0,1000,750)
color white
rect (0,110,1000,100)
color red
rect(0,200,1000,750)
pause 2
color white
rect (0,0,10000,10000)
color red
rect 135,0,25,1000
color red
rect 0,135,2500,25
Pause 2
color black
rect (0,0,1000,750)
color red
rect (0,110,1000,100)
color yellow
rect(0,200,1000,750)
Pause 2
color green
rect 0,0,100,1000
color white
rect 100,0,100,1000
color orange
rect 200,0,100,1000
Pause 2
color darkgreen
rect 0,0,100,300
color red
rect 100,0,200,300
color yellow
circle 100,150,50
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
Saturday, June 30, 2012
10 000 primes
clg
graphsize 500,500
color yellow
rect 0,0,500,500
color black
f=0
for h = 3 to 10000
if f=0 then
Prime = h-1
y = int(Prime/100)
x = Prime - y*100 -1
Rect 5*x,5*y,5,5
print Prime
end if
f=0
for i = 2 to int(h/2)+1 step 1
if int(h/i)=h/i then f=1
if int(h/i)=h/i then i=h/2
next i
next h
Friday, June 29, 2012
Collatz conjecture
Rem http://en.wikipedia.org/wiki/Collatz_conjecture#Methods_of_proof
graphsize 1000,400
for x = 1 to 1000
a=x
n=0
do
b=a
if a/2 = int(a/2) then
a = a/2
else
a=a*3+1
end if
n=n+8
line n-8,400-b/30,n,400-a/30
until a = 1
print "Initial number "+x+ " Iterations "+n/8
next x
Thursday, June 21, 2012
Image effects
# Image effects by aplying formula to RGB
# You need to have an image file 300 by 300 pixels
fastgraphics
clg
refresh
Graphsize 600,600
imgload 150,150,"Kennedy.png"
For x = 1 to 300
For y = 1 to 300
z = Pixel (x,y)
r = int(z/65536)
g = int ((z - r*65536)/256)
b = z - r*65536 - g*256 +1
gosub colors
gosub invert
gosub bw
next y
refresh
next x
colors:
r1=int(r/129)*255
g1=int(g/129)*255
b1=int(b/129)*255
color (r1,g1,b1)
plot x+300,y
return
invert:
r2=abs(255-r)
g2=abs(255-g)
b2=abs(255-b)
color (r2,g2,b2)
plot x,y+300
return
bw:
r3=(r+g+b)/3
g3=(r+g+b)/3
b3=(r+g+b)/3
color (r3,g3,b3)
plot x+300,y+300
return
Sunday, June 10, 2012
Tessellations
rem Tessellations program
graphsize 600,600
fastgraphics
l=180 : u=1: gosub tessellation
l=120 : u=1 :gosub tessellation
l=90 : u=2 :gosub tessellation
l=60 : u=2: gosub tessellation
l=60 : u=3: gosub tessellation
l=45 : u=4 : gosub tessellation
l=40 : u=3: gosub tessellation
l=36 : u=5: gosub tessellation
l=30 : u=4 :gosub tessellation
l=30 : u=6 :gosub tessellation
tessellation:
for i = 1 to 50
x1=300: y1=300: angle = 270
for b = 1 to 20
a = l*int(rand*2)-l/2
for k= 1 to u
angle = angle + a: gosub lines
next k
next b
refresh
next i
clg : pause 1: refresh
return
lines:
r = (angle/180)*pi
y2=y1 + (sin (r))*20: x2=x1 - (cos (r))*20
for n = 1 to 30
circle x1,y1,2: line x1,y1,x2,y2
next n
x1=x2: y1=y2
return
Wednesday, June 6, 2012
Cellular Automation
# This program was malfunctioning for a long time because I did not update the code to the New Basic 256 . It is very interesting to see how 2 very simple rules generate two very different patterns . One is a fractal and the other is chaotic
# You can change the rule by activating or deactivating the plotting instruction . See also http://mathworld.wolfram.com/ElementaryCellularAutomaton.html
fastgraphics
graphsize 800,400
For n = 1 to 2
plot (400,1)
For y = 1 to 400
For x = 1 to 800
a=0
if pixel(x-1,y)=black then a=a+1
if pixel(x,y)=black then a=a+10
if pixel(x+1,y)=black then a=a+100
if n=1 then gosub chaotic
if n=2 then gosub fractal
next x
refresh
next y
pause 1
clg
refresh
next n
chaotic:
if a=001 or a=110 or a =010 or a=100 then plot (x,y+1)
return
fractal:
if a=001 or a=010 or a=100 then plot (x,y+1)
return
Tuesday, September 27, 2011
Static Wave
Rem the purple wave is made out of two simple sinusoidal waves. Change the frequencies and amplitudes and see what happens .
fastgraphics
Amplitude1=30
Frequency1=2
Amplitude2=30
Frequency2=8
for t = 1 to 1000 step .1
clg
for n = 1 to 31.4 step 0.1
r=Amplitude1*sin(t )*Sin(n/(10/Frequency1))
b=Amplitude2*sin(t )*Sin(n/(10/Frequency2))
p= r+b
color red
circle 10*n,r+250,3
color blue
circle 10*n,b+200,3
color purple
circle 10*n,p+100,3
next n
refresh
next t
Tuesday, July 12, 2011
Subscribe to:
Posts (Atom)



























