设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7490|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。6 D* O( I+ V: E7 h8 s

( ?! z+ j; {+ M# r但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。" d' j& @* B. ]& O9 n. O
" g+ ~' V6 B/ ~* s0 Q4 |& i
turtles-own [a b c d k f g h
- M! Y1 [# l7 J  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 3 q0 h! X; K7 z, l* \
]3 |" @: A; d4 P: A
to new) H& [1 E; ?0 w6 W0 T) X# t
  ca
9 t4 Y4 o+ x! G: A: [9 x  crt 5 * num_of_building
2 n2 J1 m$ u" P) W; y  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
( G* ^5 q3 g$ v8 ~' V/ q5 z  scatter     ;;keep center-turtle random positions . G( x" o4 j7 E( \. O
  unit_plan   ;;make up the building plan2 l7 I. X4 y7 S# h& Z$ u4 S/ u
end
8 @" ^7 J5 ^* }, vto scatter
, N4 `/ ]) `5 G5 x3 a8 M# qask turtles with [remainder who 5 = 0]" Y9 B4 F$ m) p2 L
[
# d. P/ L! O: N3 i8 rset xcor xcor - 6 + random-float 15% K% S# c$ e5 [- J' b1 K4 a
set ycor ycor - 6 + random-float 154 x5 h7 [0 ?; e! C
]
7 R" c* x1 U4 V* S: L- bend. w% T6 B7 j/ i" Y
to unit_plan
6 B' {  N7 ~- p0 H( }* _ask turtles [
' V2 A( q, L4 U) gif (remainder who 5 = 1) [set a who
8 h. y: o) x2 n  I                          set x ( 0 - Wid / 2 ) : z7 i' D  l# g+ Q% r/ D
                          set y  Dep / 2 ]7 ?  r0 ?: h8 }3 Z4 a1 s0 b
           set b  int (a / 5) * 52 n  {) |% d$ Y, K5 `) n# z, c
    setxy ( xcor-of turtle b + x )
. {1 G' H: `" ?5 Z; z          ( ycor-of turtle b + y )  N% s& |' c) m, r7 T+ @% u
if (remainder who 5 = 2) [set c who
' X4 i2 C! K! ~. o- [2 _0 v; K                          set x ( 0 - Wid / 2 )
4 A! o$ k% I2 f* k! w! S2 O# f$ ~                          set y (0 - Dep / 2 )  ]
! L/ {: M+ e( {- i                          set d int (c / 5) * 5! ?; q5 b- A4 \% e- K- I- F( ?3 x. x
   setxy   ( xcor-of turtle d + x )0 ?" P" ~% l& k! S5 ?  n4 t
           (ycor-of turtle d + y ) ' z) n! }' }. @7 Y
         
4 J% U/ r* W7 O% C* L/ r# a            
( J/ \& ^/ d2 j$ mif (remainder who 5 = 3) [set k who4 o! G- w$ t8 y& o) v: A4 l# j' E" ~( _
                          set x( Wid / 2)  
( c+ S# c& B" T5 A; J9 t                          set y (0 - Dep / 2 ) ]
+ y5 @5 f3 @0 Y5 p1 Y+ ]                          set f int (k / 5) * 5% J) w3 P! X3 \# g8 P+ I+ k" m
  setxy   ( xcor-of turtle f + x )
) @6 g: B" D! D6 b           (ycor-of turtle f + y ) # U: Y8 J; L+ O. C& i' p! v
           
- k9 [' K# s6 f+ x: G           " T5 W- P7 k1 y  s1 W9 Z
if (remainder who 5 = 4) [set g who. F) i! e1 c3 E( O/ `, Z+ B
                          set x Wid / 2
  t' x/ b& w$ l                          set y  Dep / 2 ]0 t9 @& d  u: \2 C9 @0 R- N% T0 _
                          set h  int (g / 5) * 5
5 L' i+ y+ [# r' f! M, y: X& S  setxy   ( xcor-of turtle h + x )5 E; y1 T& V6 I+ Q) V
           (ycor-of turtle h + y )
7 w, N6 _/ f' X" _* |! ?                          
" O  a4 R$ P. ^3 {4 H( w7 a                          
& [0 i: Q9 _  V                          ]
( }3 t, R" W% j  D2 Q% o0 F# dend
8 M# Y* C$ K( p6 _0 a0 r! S4 L
3 r" B8 Q0 }% s0 y/ x0 \2 e, D+ X[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,3 |) O+ A5 E$ a9 F4 |; ^/ ^/ p3 f
应该是
/ O2 L, @; b$ Pask turtles [
, s2 Q) y3 R( Gif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) $ s* y$ }" d; L
                          set y  Dep / 2 , @& J, I4 t1 o
           set b  int (who / 5) * 5
% _& ]. E; n" A# L" \6 E    setxy ( xcor-of turtle b + x )( w, l! w+ X# A% l4 J0 n% M+ O; }
          ( ycor-of turtle b + y )]]
$ W6 _! O4 A- `; s6 vend( z; S0 M+ W; p% l# t
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-17 16:34 , Processed in 0.024210 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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