Subversion Repositories wimsdev

Rev

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