## 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