设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8805|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。, ]3 g( i: V4 S

% W6 }: G+ X  ]但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
8 o' @: \& A# Z; v
; a: B$ V) n- ?% Sturtles-own [a b c d k f g h
9 `9 a7 |& ^; Y! a6 d) ~0 E  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 6 B* a7 ?4 b6 u! m/ O
]" S% S' S% m( i2 A1 d* c
to new
9 c- u7 C1 G7 @" x7 J  ca  q# R# @; H+ P& k* F) ^+ g/ s
  crt 5 * num_of_building
4 O2 Z3 @$ L# k8 Q  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
7 M7 O$ d6 j' j4 J7 I  scatter     ;;keep center-turtle random positions $ c) i! z7 R) b% o* w
  unit_plan   ;;make up the building plan
1 M5 q: Q$ h* w9 @6 {" x8 B6 b" Fend  L8 X2 T/ T! c" k% I. F+ R
to scatter
2 z. g$ y+ M$ a5 c' D- Mask turtles with [remainder who 5 = 0]! z1 k; @( A2 k9 I8 l) F% B2 n
[
+ ]) E' @, F; O% Gset xcor xcor - 6 + random-float 15' g1 a6 W, o7 _* t2 k
set ycor ycor - 6 + random-float 15# Z/ H, {0 ?* I2 X% T$ @
]
- ^2 o5 h, a; e6 c) l0 f7 z& |5 rend
1 S8 {4 i+ _- X/ {6 `to unit_plan
8 |& k/ }; ^: M1 dask turtles [
9 v( Q( I* _1 d! Y# wif (remainder who 5 = 1) [set a who
# r0 _. |% Y9 f+ P$ y% K0 k4 j* ?) Y                          set x ( 0 - Wid / 2 )
/ V, {) d% @( O1 R) q                          set y  Dep / 2 ]
8 p. }  W" `% l1 Z           set b  int (a / 5) * 55 I. D$ e+ {2 H- A
    setxy ( xcor-of turtle b + x )
. ~* O7 c( W1 [  {+ z; F          ( ycor-of turtle b + y )
( S% j% P: i. s: V9 R! Pif (remainder who 5 = 2) [set c who9 S+ G% q* [; |/ X- x0 c
                          set x ( 0 - Wid / 2 )
5 Q5 g# \, T  b2 w+ v# \                          set y (0 - Dep / 2 )  ]/ V  t8 K2 |( N. f- U6 v
                          set d int (c / 5) * 5
1 M+ y3 Q) R# d. F& s3 b   setxy   ( xcor-of turtle d + x )6 w3 C7 s) ^: ~4 U' V  G
           (ycor-of turtle d + y )
; p$ P8 E9 e6 W, h1 \          5 m# }8 Q- @: U% i
            
4 E; y. t1 t/ b+ r  Eif (remainder who 5 = 3) [set k who  q5 T( W: ^3 Z& h( q
                          set x( Wid / 2)  
; e, }8 k) V. ~! v/ H% ^' Z                          set y (0 - Dep / 2 ) ]% q) w" k- c* ?3 j
                          set f int (k / 5) * 5
+ w4 X9 M# k( Q5 u% X3 v  _% O" ]  setxy   ( xcor-of turtle f + x )3 X/ c* p# b- z6 x% u  O
           (ycor-of turtle f + y ) : D6 ]6 M. T2 a$ A
           ' Z. J4 N0 W- I. M
           5 q2 r" h# R6 I" B: ~8 c' g
if (remainder who 5 = 4) [set g who" }( w/ J' P1 d5 |$ M# ]) h
                          set x Wid / 2
) t7 v7 U* \9 w3 z. y! c                          set y  Dep / 2 ]6 T: e% `. X7 D& ~; L
                          set h  int (g / 5) * 5
: h6 X/ z) e- B" W* s% ?; X  setxy   ( xcor-of turtle h + x )8 ?  v8 r. p2 P5 g7 q4 X: p
           (ycor-of turtle h + y ) 7 m3 Z4 {& W# s3 K! d
                          
, z* B5 Z- G6 b4 S; |7 [                          
6 p5 W4 N. s3 A- k  e                          ]$ V1 ~* y- v4 u5 a' T& _, q
end! f+ k: A6 t* l  t9 K, _. s, {! g
+ ?8 E3 [  [$ L/ h/ B* z
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,* s3 z1 X2 O8 I* ?9 C4 S
应该是0 p$ c! N# Y% H% B. Z
ask turtles [
& C( w3 {# Q; d' t2 T3 Eif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 0 A# U. r0 V5 y9 `# Z8 Y3 b* l' H
                          set y  Dep / 2 + V, x8 c" `$ h
           set b  int (who / 5) * 5
2 X- ]' v/ |1 i. A# f+ S+ @    setxy ( xcor-of turtle b + x )! x. F2 f5 ^  p0 X6 W
          ( ycor-of turtle b + y )]]- j8 |) L" ]* I' J& C( D
end
0 s2 Z- W& i- H( E5 r之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-6 06:51 , Processed in 0.018906 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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