Subversion Repositories wimsdev

Rev

Rev 7692 | Rev 8560 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
20 reyssat 1
!if $wims_read_parm!=slib_header
2
 !goto proc
3
!endif
4351 bpr 4
slib_author=Bernadette, Perrin-Riou
4158 bpr 5
 
4194 bpr 6
slib_example= 5,3,3,,perfect middle\
7
12,2,4,[A,B,C,D],point html
7692 bpr 8
 
20 reyssat 9
!exit
10
 
11
:proc
12
 
13
!distribute item $wims_read_parm into slib_N,slib_s,slib_h,slib_text
14
slib_option = !item 5 to -1 of $wims_read_parm
15
!default slib_s=5
16
!default slib_h =8
17
!default slib_color1=blue
18
!default slib_color2=green
19
!default slib_color3 = yellow
20
slib_text=!declosing $slib_text
21
slib_G = 1
22
slib_cnt = 1
23
slib_n = $[2*$slib_N]
24
slib_A1 =0
25
slib_height1 =1
26
slib_sizey =1
27
slib_cnt1 = 0
28
slib_width1 =15
29
slib_Sizey = $[$slib_h+1]
30
slib_choix1=!values 1 for x = 1 to $[$slib_s+3]
31
slib_choix0=!values 0 for x = 1 to $[$slib_s-3]
32
slib_noeud= !random 0,1 repeat $n
33
#permet d'assurer que l'arbre ne part pas avec une seule branche (inutile dans le cas parfait)
34
slib_noeud = 1,$slib_noeud
35
slib_choix=$slib_choix1, $slib_choix0
36
slib_position =$empty
37
slib_milieu =0,-1
38
!for slib_k = 1 to $slib_n
8321 bpr 39
    slib_L = !line $slib_k of $slib_G
40
    !if $slib_L<>$empty
41
        slib_i=!item 1 of $slib_L
42
        slib_position_prov=$(slib_A$slib_i),$[-$(slib_height$slib_i)]
43
        slib_position = !append line  $slib_position_prov to $slib_position
44
        !if $slib_cnt > $[$slib_N] or $slib_sizey > $slib_Sizey
45
        !else
7692 bpr 46
#choix des fils (position et nombre : la position est-elle intéressante pour un arbre non binaire ? )
8321 bpr 47
            slib_c=!item $slib_k  of $slib_noeud
48
            !if perfect iswordof of $slib_option or $slib_c = 1
49
                slib_a =!item 1 to $slib_s of $slib_choix1
50
            !else
51
                slib_a =!shuffle $slib_choix
52
                slib_a=!item 1 to $slib_s of $slib_a
53
            !endif
54
            slib_Li =
55
            !for slib_j = 1 to $slib_s
56
                slib_b=!item $slib_j of $slib_a
57
                !if $slib_b <> 0
20 reyssat 58
#creation d'un fils
8321 bpr 59
                    slib_jj =$[$slib_cnt+1]
20 reyssat 60
#sa hauteur
8321 bpr 61
                    slib_height$slib_jj= $[$(slib_height$slib_i)+1]
20 reyssat 62
#la hauteur de l'arbre
8321 bpr 63
                    slib_sizey=$[max($slib_sizey, $(slib_height$slib_jj))]
7692 bpr 64
# Ne sert à rien ?
8321 bpr 65
                    slib_cnt$(slib_height$slib_jj)=$[$(slib_cnt$(slib_height$slib_jj))+1]
20 reyssat 66
#on rajoute une ligne pour le fils
8321 bpr 67
                    slib_G =!append line $slib_jj to $slib_G
20 reyssat 68
#nombre de sommets
8321 bpr 69
                    slib_cnt = $[$slib_cnt +1]
70
                !else
71
                    slib_jj=sentinelle
72
                !endif
20 reyssat 73
#on rajoute le fils sur la ligne du père, rien s'il n'y a rien à cette position
8321 bpr 74
                slib_Li =!append item $slib_jj to $slib_Li
7692 bpr 75
#le calcul suivant sert pour le dessin. Faut-il le mettre ici ?
8321 bpr 76
                !if $slib_b <> 0
20 reyssat 77
#position
8321 bpr 78
                    slib_A$slib_jj=$[$(slib_A$slib_i)+($slib_j-($slib_s+1)/2)*$(slib_width$slib_i)]
20 reyssat 79
#calcul de la largeur donnée au sommet $slib_jj pour ses fils éventuels
8321 bpr 80
                    slib_width$slib_jj=$[$(slib_width$slib_i)/min($slib_s,$slib_s+1)]
81
                    slib_milieu_prov=$[($(slib_A$slib_i)+2*$(slib_A$slib_jj))/3],$[-($(slib_height$slib_i) +2*$(slib_height$slib_jj))/3]
82
                     slib_milieu = !append line $slib_milieu_prov to $slib_milieu
83
                !endif
84
            !next slib_j
20 reyssat 85
#on met la ligne $slib_k définitive
8321 bpr 86
          slib_G = !replace line number $slib_k by $slib_L,$slib_Li in $slib_G
87
        !endif
20 reyssat 88
  !endif
89
!next slib_k
90
 
91
#Trace du dessin
92
slib_dessin =xrange $[-$slib_s*$slib_width1/2],$[$slib_s*$slib_width1/2]\
93
yrange $[-$slib_Sizey-0.5],-0.5\
94
linewidth 2
95
slib_cnt =!linecnt $slib_G
96
 
7692 bpr 97
!for slib_k= 1 to $slib_cnt
8321 bpr 98
    slib_u =!line $slib_k of $slib_G
99
    slib_i=!item 1 of $slib_u
100
    slib_position_prov=!line $slib_k of $slib_position
101
    !for slib_j in $slib_u
102
        !if $slib_j  notsametext sentinelle
20 reyssat 103
#trace de la droite
8321 bpr 104
            slib_position_prov1=!line $slib_j of $slib_position
105
            slib_dessin = !append line line  $slib_position_prov,$slib_position_prov1, $slib_color1\
106
             to $slib_dessin
7692 bpr 107
#on coupe les segments au milieu pour mettre un cercle et éventuellement du texte
8321 bpr 108
            !if middle iswordof $slib_option
109
                slib_milieu_prov=!line $slib_j of $slib_milieu
110
                slib_dessin = !append line disk $slib_milieu_prov,30,white\
7692 bpr 111
circle $slib_milieu_prov, 30,$slib_color3 to $slib_dessin
8321 bpr 112
            !endif
113
        !endif
114
    !next slib_j
115
    !if point iswordof $slib_option
116
        slib_dessin =!append line disk $slib_position_prov,30,white\
117
      circle $slib_position_prov,30,$slib_color2 to $slib_dessin
118
    !endif
119
    !if $slib_text <> $empty
120
        slib_textk=!item $slib_k of $slib_text
121
        slib_dessin =!append line text black,$slib_position_prov, medium,$slib_textk to $slib_dessin
122
    !endif
7692 bpr 123
!next slib_k
4194 bpr 124
 
125
slib_out=$slib_dessin
126
 
127
!if url iswordof $slib_option or html iswordof $slib_option
128
  insdraw_size=300,300
129
  !insdraw $slib_out
130
  slib_out=$ins_url
131
  !if html iswordof $slib_option
5736 bpr 132
   slib_out=<img src="$ins_url" alt=""/>
4908 bpr 133
  !else
134
   slib_out=$slib_out,[$slib_G],[$slib_position],[$slib_milieu],$insdraw_size
4194 bpr 135
  !endif
4908 bpr 136
!else
4194 bpr 137
   slib_out=[$slib_dessin],[$slib_G],[$slib_position],[$slib_milieu]
138
!endif