设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7776|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。  Q& I! K2 t8 }" O
5 }/ R; j6 Y. `- ]' a$ ~. l! e
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
# ^  L. ^, }2 Z" ?% y1 d* \. e: M8 P: K5 q* B9 u) |
turtles-own [a b c d k f g h
. ]4 e& n# L5 r3 M8 E! C3 Z& k  x y     ;; these are the leaf-turtle's offsets relative to center-turtle   `1 l/ y4 P" X- \- m
]
* S6 T# W; H0 {; Y! ~! m+ `6 a1 }. Jto new
. s" A- |, B2 t3 a) R  ca
/ Y/ [' W: c* V: S1 O  crt 5 * num_of_building% a. X4 K" j/ S
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
* f! G+ d' O) @  scatter     ;;keep center-turtle random positions
; F- h2 S! q* G' e1 q  unit_plan   ;;make up the building plan: @( s% N* ^9 g7 P5 V- E
end
6 d- [! R, R* o1 Ito scatter
2 d& D1 V- f, Yask turtles with [remainder who 5 = 0]
; ]% w. t2 P" j* V5 c. L  }[
) L  ^! N7 p1 c) N* lset xcor xcor - 6 + random-float 15/ e9 {0 |/ V6 D0 l  ~
set ycor ycor - 6 + random-float 154 W  q% t0 {" P& q5 y. d
]
* v' g0 U& {# O9 I5 q1 E, `' aend
2 h$ ]8 ]- V3 kto unit_plan , S9 g, E8 E. O7 H% N( F
ask turtles [' B2 v5 W  n& ?
if (remainder who 5 = 1) [set a who . y3 R8 a3 V8 `7 ~
                          set x ( 0 - Wid / 2 )
) i' q3 G9 a5 ^7 v0 q9 i                          set y  Dep / 2 ]: s6 a+ n" ?- ?' m0 n. [
           set b  int (a / 5) * 5( L/ N& D9 x/ H/ q
    setxy ( xcor-of turtle b + x )
7 ?# U% e  u  X  ]+ ?          ( ycor-of turtle b + y )% m' e. W3 T, \  A
if (remainder who 5 = 2) [set c who
' m  K5 F) F9 e6 J                          set x ( 0 - Wid / 2 ) ; W7 [9 B. R' y8 J; A7 T/ b: s% Y
                          set y (0 - Dep / 2 )  ]- R, l9 A9 Y5 J9 ?2 Z2 h! K0 Y
                          set d int (c / 5) * 5! ~2 O6 Y6 ?! `" {0 B
   setxy   ( xcor-of turtle d + x )
% R- z# F3 [- ?$ ~  y1 p6 N$ c5 ?           (ycor-of turtle d + y )
: Y  b% L, P, [3 x; A" r: e7 r         
) K. s$ U/ P+ c) d; k            
1 [& K  |' c/ L0 n: x% K  v! aif (remainder who 5 = 3) [set k who: x: d. ?) [. H" _% G4 m0 u9 n
                          set x( Wid / 2)  , Y8 o4 i+ `5 x( U, M2 O* ]. z) X; J, m
                          set y (0 - Dep / 2 ) ]
0 m9 @( t# [& K, P3 D, \& E- T2 [                          set f int (k / 5) * 56 B! p2 N  U! }! q6 P% Z
  setxy   ( xcor-of turtle f + x )2 r  `" m" e- o$ M$ [8 H% Z, {
           (ycor-of turtle f + y )
& X$ ?! V% T. Y# t8 D           # }) ?- M1 B/ ?
           6 b7 G6 e6 Y* G9 r- D( B
if (remainder who 5 = 4) [set g who
3 `' j, n. S# O                          set x Wid / 2
4 @" _/ u9 e; X* W4 x                          set y  Dep / 2 ]
% M" b9 c/ ]2 I3 D9 @  ~                          set h  int (g / 5) * 5" L& J8 i! _8 A
  setxy   ( xcor-of turtle h + x )4 O1 u8 _& R# I: m8 C* h8 B
           (ycor-of turtle h + y ) 7 }' v3 c7 {. |- `6 v( q2 l) N+ W
                            r' c2 u+ U2 h; V$ ^
                          
( m( H# R. U1 H' M                          ]% B8 a/ t9 K) O3 r
end) R' M# l6 D' m* |+ {' B* d

. `- o0 o' J5 \8 J[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
: P- n6 i. X8 @! q: a应该是
# P: z3 l8 d+ W4 g- u# \' Eask turtles [+ \: P% Y) Z9 D; w: t4 S1 W
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 9 }6 F  i8 }" \, s
                          set y  Dep / 2
6 Q& M6 J0 u5 q: ?           set b  int (who / 5) * 5& A% F. h/ X  C! Z0 u) L6 g5 [
    setxy ( xcor-of turtle b + x )
: ^5 C; d2 f! \+ C          ( ycor-of turtle b + y )]]3 N9 k6 z5 R( r  V9 o* a" Q4 i4 k/ V( M+ M
end
4 X  E( |/ v  T之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-29 23:20 , Processed in 0.016392 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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