- Un quadrillage à effet d'optique
Xmin = -1
Xmax = 9.6
Ymin = -1
Ymax = 9.6
couleur = noir
for(i=0;i<20;i++){
trait = i/1.2
couleur = noir
segment([i/2,-10],[i/2,10])
segment([-10,i/2],[10,i/2])
}
- Une spirale
Xmin = -10
Xmax = 10
Ymin = -10
Ymax = 10
pas = 0.01
trait = 2
for(t=0;t<48*%PI;t=t+pas){
A = [0.1*t*cos(t),0.1*t*sin(t)]
B = [0.1*(t+pas)*cos(t+pas),0.1*(t+pas)*sin(t+pas)]
segment(A,B)
}
- Des segments aléatoires
Xmin = 0
Xmax = 1
Ymin = 0
Ymax = 1
trait = 2
peinture = noir
transparence = 1
rectangle([-1,2],5,5)
couleur = blanc
A = [rand(),rand()]
point(A)
for(t=0;t<25;t++){
n = entAlea(0,5)
if (n==0){couleur = bleu}
if (n==1){couleur = rouge}
if (n==2){couleur = rose}
if (n==3){couleur = vert}
if (n==4){couleur = blanc}
if (n==4){couleur = jaune}
B = [rand(),rand()]
segment(A,B)
point(B)
A = B
}
- Quelques cardioïdes
Xmin = -3
Xmax = 20
Ymin = -20
Ymax = 20
for(a = 0.5;a<10;a=a*1.1){
pas = 0.1
for(t=0;t<2*%PI;t=t+pas){
A=[a*cos(t)*(1+cos(t)),a*sin(t)*(1+cos(t))]
B=[a*cos(t+pas)*(1+cos(t+pas)),a*sin(t+pas)*(1+cos(t+pas))]
segment(A,B)
}
}
- Fractale de Mandelbrot
Xmin = -1.5
Xmax = 0.5
Ymin = -1
Ymax = 1
trait = 0.3
couleur = noir
itMax = 50
for(x=-2;x<=2;x=x+2/400){
for(y=-2;y<=2;y=y+1/200){
it = 0
tmp = 0
z_r = 0
z_i = 0
test = z_r*z_r+z_i*z_i
while( test<4 && it
tmp = z_r
z_r = z_r*z_r-z_i*z_i+x
z_i = 2*z_i*tmp + y
it++
test = z_r*z_r+z_i*z_i
}
if( it == itMax ){point([x,y])}
}
}
- Fractale de Mandelbrot avec des couleurs
Xmin = -2.1
Xmax = 0.5
Ymin = -1.3
Ymax = 1.3
trait = 0.3
couleur = noir
itMax = 50
for(x=-2.1;x<=0.5;x=x+2.6/400){
for(y=-1.3;y<=1.3;y=y+2.6/400){
it = 0
tmp = 0
z_r = 0
z_i = 0
test = z_r*z_r+z_i*z_i
while( test<4 && it
tmp = z_r
z_r = z_r*z_r-z_i*z_i+x
z_i = 2*z_i*tmp + y
it++
test = z_r*z_r+z_i*z_i
}
if( it == itMax ){couleur = blanc}
if( it < 45 ){couleur = "#38388c"}
if( it < 40 ){couleur = "#0000ff"}
if( it < 35 ){couleur = "#6969e4"}
if( it < 30 ){couleur = "#7575ce"}
if( it < 25 ){couleur = "#9797e4"}
if( it < 22 ){couleur = "#aaaaee"}
if( it < 20 ){couleur = "#f0f0f0"}
if( it < 19 ){couleur = "#e0e0e0"}
if( it < 18 ){couleur = "#d0d0d0"}
if( it < 17 ){couleur = "#c0c0c0"}
if( it < 16 ){couleur = "#b0b0b0"}
if( it < 15 ){couleur = "#a0a0a0"}
if( it < 14 ){couleur = "#909090"}
if( it < 13 ){couleur = "#808080"}
if( it < 12 ){couleur = "#707070"}
if( it < 11 ){couleur = "#606060"}
if( it < 10 ){couleur = "#505050"}
if( it < 9 ){couleur = "#404040"}
if( it < 8 ){couleur = "#303030"}
if( it < 7 ){couleur = "#202020"}
if( it < 6 ){couleur = "#101010"}
if( it < 5 ){couleur = noir}
point([x,y])
}
}
- Fractale de Julia
Xmin = -1.6
Xmax = 1.6
Ymin = -1.6
Ymax = 1.6
trait = 0.3
couleur = noir
cx = 0.35
cy = 0.08
itMax = 50
for(x= Xmin;x<=Xmax;x=x+(Xmax-Xmin)/400){
for(y=Ymin;y<=Ymax;y=y+(Ymax-Ymin)/400){
it = 0
tmp = x
z_r = x
z_i = y
test = z_r*z_r+z_i*z_i
while( test<4 && it
tmp = z_r
z_r = z_r*z_r-z_i*z_i+cx
z_i = 2*z_i*tmp + cy
it++
test = z_r*z_r+z_i*z_i
}
if( it == itMax ){couleur = blanc}
if( it < 45 ){couleur = "#d2d2ff"}
if( it < 40 ){couleur = "#c6c6ff"}
if( it < 35 ){couleur = "#b8b8ff"}
if( it < 30 ){couleur = "#a7a7ff"}
if( it < 25 ){couleur = "#9b9bff"}
if( it < 22 ){couleur = "#9191ff"}
if( it < 20 ){couleur = "#f0f0f0"}
if( it < 19 ){couleur = "#e0e0e0"}
if( it < 18 ){couleur = "#d0d0d0"}
if( it < 17 ){couleur = "#c0c0c0"}
if( it < 16 ){couleur = "#b0b0b0"}
if( it < 15 ){couleur = "#a0a0a0"}
if( it < 14 ){couleur = "#909090"}
if( it < 13 ){couleur = "#808080"}
if( it < 12 ){couleur = "#707070"}
if( it < 11 ){couleur = "#606060"}
if( it < 10 ){couleur = "#505050"}
if( it < 9 ){couleur = "#404040"}
if( it < 8 ){couleur = "#303030"}
if( it < 7 ){couleur = "#202020"}
if( it < 6 ){couleur = "#101010"}
if( it < 5 ){couleur = noir}
point([x,y])
}
}
- Une autre fractale de Julia
On peut modifier les valeur de cx et cy pour obtenir diverses fractales :
cx=0.35 et cy=0.08 cx=-0.25 et cy=0.65 cx=-0.28 et cy=0.635 cx=-0.745 et cy=0.12
cx=-0.55 et cy=0.54 cx=-0.545 et cy=0.51
Xmin = -1.5
Xmax = 1.5
Ymin = -1.5
Ymax = 1.5
trait = 0.3
couleur = noir
cx = -0.745
cy = 0.12
N = 1
itMax = 200
for(x= Xmin;x<=Xmax;x=x+(Xmax-Xmin)/400){
for(y=Ymin;y<=Ymax;y=y+(Ymax-Ymin)/400){
it = 0
tmp = x
z_r = x
z_i = y
test = z_r*z_r+z_i*z_i
while( test<4 && it
tmp = z_r
z_r = z_r*z_r-z_i*z_i+cx
z_i = 2*z_i*tmp + cy
it++
test = z_r*z_r+z_i*z_i
}
coul = 255*puissance(it/itMax,N)
couleur = "rgb("+coul+","+coul+","+coul+")"
point([x,y])
}
}
- Tri à bulles
Xmin=0
Xmax=50
Ymin=0
Ymax=100
T = [100,53,77,12,5,148,11,34,86,17,98,3,50,53,0,28,94,51,48,25,6,54,61,60,78,99,12,41,33,47,54,8,5,47,26,58,11,31,54,37,82,47,42,25,18,26,12,43,68,71]
i = T.length
j = 0
trace(T)
transparence = 1
bubble(T,i,j)
function bubble(T,i,j){
if(i>0){
if(j < i-1){
inverse(T,j)
setTimeout(function (){bubble(T,i,j+1)},50)
}
else{
j=0
setTimeout(function (){bubble(T,i-1,j)},50)
}
}
trace(T)
}
function inverse(T,j){
if( T[j] > T[j+1] ){
x = T[j]
T[j] = T[j+1]
T[j+1] = x
}
}
function trace(T){
couleur = blanc
peinture = blanc
transparence = 1
rectangle([0,100],50,100)
couleur = noir
for(i=0;i < T.length;i++){
peinture = bleu
transparence = 0.5
rectangle([i,T[i]],1,T[i])
}
}
- Géométrie dans l'espace
point([5,0,0])
point([0,0,0])
point([5,5,0])
point([0,5,0])
point([0,0,5])
point([5,0,5])
point([0,5,5])
point([5,5,5])
segment([5,0,0],[5,0,5])
segment([5,0,0],[5,5,0])
segment([5,0,5],[5,5,5])
segment([5,5,5],[0,5,5])
segment([5,5,5],[5,5,0])
segment([0,5,5],[0,5,0])
segment([5,5,0],[0,5,0])
segment([0,0,5],[5,0,5])
segment([0,0,5],[0,5,5])
segment([0,0,5],[0,0,0],[5,5])
segment([0,0,0],[0,5,0],[5,5])
segment([0,0,0],[5,0,0],[5,5])
triangle([0,0,5],[5,0,0],[0,5,0],[10,10])
texte("A",[0,0.3,0.2])
texte("B",[5,-0.8,-0.2])
droiteParam([0,0,0],[1,1,1])