Subversion Repositories wimsdev

Rev

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