Subversion Repositories wimsdev

Rev

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