设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8207|回复: 1

[交流] 看看这段代码的问题

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
  v0 I" c0 b- ]' h1 A2 P, D7 o8 l4 b: S: X* i7 E
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。; ]/ [; [/ M( ^! ^  N: u
" ~; R8 A1 T$ Q: i0 I
turtles-own [a b c d k f g h
4 T8 T5 {7 @* T: |& `  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 9 o, V! K" G  V+ C1 z, C# c
]
0 ~# Y4 k7 g, X# i2 Oto new: i) g% Z' ~  w7 x) k% k6 \# q
  ca% H* Z2 ^& @8 |: [: {
  crt 5 * num_of_building
+ a1 q7 x6 S0 x  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
5 o; L" h; u5 S/ Y  scatter     ;;keep center-turtle random positions
& \+ _' E, {" D- e  unit_plan   ;;make up the building plan
+ r3 w0 Q* e$ h# T% Wend
6 q1 Z) S, e; ^7 A5 \) b4 b% r1 ~5 @to scatter
+ P. w) C2 }% o! @ask turtles with [remainder who 5 = 0]
8 o: X& u1 W* ^; A+ T[5 e7 w4 |6 F/ d( @
set xcor xcor - 6 + random-float 156 J9 L' a$ c0 L$ W
set ycor ycor - 6 + random-float 15
- l7 x  v: J8 y; |# I( m]
' j7 s" [, U$ o2 |: Dend
' P* O2 s* @$ L' x0 K3 ato unit_plan
; W) d. o: P: D$ C. k* Yask turtles [
2 R7 z6 P( W9 ~# Q7 N, Dif (remainder who 5 = 1) [set a who + h* M+ T$ p% `: q
                          set x ( 0 - Wid / 2 )
: R4 X1 X- m: `) A0 U- d                          set y  Dep / 2 ]
/ K4 P, w% l: D" B8 }  X7 P- Y           set b  int (a / 5) * 56 F: ?, k9 ]$ v% G. X' J& Y( p
    setxy ( xcor-of turtle b + x )
% v1 ?/ f7 c  y& B8 `1 c' z7 W          ( ycor-of turtle b + y )
3 A4 R6 L* f( T2 v1 Aif (remainder who 5 = 2) [set c who& S: x, w& S$ H! Z
                          set x ( 0 - Wid / 2 )
' G: d- I+ H/ s                          set y (0 - Dep / 2 )  ]
# J7 S3 n, w/ z                          set d int (c / 5) * 5/ s. b6 I& I* c6 `& i" R+ Z/ G
   setxy   ( xcor-of turtle d + x )
2 ]( @  x: a$ B" ^) m- r           (ycor-of turtle d + y ) 3 X) G& }3 f7 V  |9 f: V: ~3 j
         
+ s8 t4 g; q3 R9 U+ {            : A  ], U% G2 Y, [( z! G: s
if (remainder who 5 = 3) [set k who; g% G3 a0 J8 F& ]
                          set x( Wid / 2)  
: }# o( M2 U* ]) I                          set y (0 - Dep / 2 ) ]
: g1 ^+ q" H8 F                          set f int (k / 5) * 57 c! n/ G/ _( ~
  setxy   ( xcor-of turtle f + x ); W& w1 v" A# u- @/ l; G
           (ycor-of turtle f + y ) 2 k8 c4 i) Y0 w+ y+ a/ z
           * d) W3 O, L. c+ z: M
           
8 Z; [) }4 Q# |1 m( hif (remainder who 5 = 4) [set g who1 W. _& `! \! A( N6 H
                          set x Wid / 2 % ^7 g; \7 O2 |+ `
                          set y  Dep / 2 ]. G" H% X6 k+ W
                          set h  int (g / 5) * 5( p; L# F/ C" l- J8 N: q- e. y
  setxy   ( xcor-of turtle h + x )
" ~3 W, B, |) ?4 S- g           (ycor-of turtle h + y ) 6 ^, G2 G3 k  N9 E
                          ( n3 j( V! ?2 p
                          6 ~& V; `+ r* F" I: W  X
                          ]% Z  c" `- n  i7 }3 D: B5 s
end
) }/ E( u1 k7 E  t+ Y4 o& K( B& Q' t' B' f( Z; {
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,( E  [, m+ ~: O9 M" P+ W/ t% w! z
应该是: o) B2 G' Y3 _; h
ask turtles [
; M$ M* o' u; Oif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
3 u0 j! R$ q8 Y$ {5 I* S0 q6 h                          set y  Dep / 2 4 S- [0 B9 Z) H. o: y
           set b  int (who / 5) * 5+ b2 I; i: D7 ^) X; A9 j
    setxy ( xcor-of turtle b + x )3 |& {# W$ U1 R! M% \
          ( ycor-of turtle b + y )]]
9 A) k/ U9 @. \- o# z/ V. cend8 D- U7 t7 z6 f) P4 ]* Z
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2026-5-19 02:40 , Processed in 0.024719 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表