设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8157|回复: 1

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

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

1 Q! d* X3 f6 [& Y9 X但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
8 T1 }- `- _' }8 V- b- L
- L5 b/ O# K+ k' I8 Eturtles-own [a b c d k f g h
# A, H$ s5 `0 g6 t  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
+ ?# m/ P% i! Q# k) Q]3 `, o/ f$ J" O& ]2 O. A
to new
2 c9 i0 V. A! y7 G. j$ T" u  ca, a- I& f, k: f: j/ p7 F
  crt 5 * num_of_building. l+ m8 M! N* S% n& |
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
0 x5 v: {# i. N. ]0 ?3 _* l) }& o  scatter     ;;keep center-turtle random positions
9 H/ t3 j& n/ I) k  unit_plan   ;;make up the building plan
/ k( L8 F' t' I5 q0 n1 {# J: `end0 p! ~/ R; R3 l
to scatter
  y  u8 K1 a; f. o9 ?ask turtles with [remainder who 5 = 0]+ n* Y2 \) K$ u8 W* s# p* U: m
[1 R' K; N$ Z8 u
set xcor xcor - 6 + random-float 15
$ e+ u) m  B5 C0 a/ ^1 |set ycor ycor - 6 + random-float 15
' k7 u: N* n& B9 [7 k]
) Z  y8 f! l; Aend
3 s: U! A1 d: S9 Bto unit_plan / L& ~. x9 ^5 ~8 J/ ^  G
ask turtles [) T5 m: J/ s/ Z/ D- V2 r2 H& ]
if (remainder who 5 = 1) [set a who 4 R+ H+ f9 H3 \; d
                          set x ( 0 - Wid / 2 ) * g' @1 I  c4 `. U8 K6 b% ~
                          set y  Dep / 2 ]
" Q8 \5 d* J$ o           set b  int (a / 5) * 5: j; r3 ?  p. R7 O  i" `7 B
    setxy ( xcor-of turtle b + x )8 X" k! I6 ^( f* B& W; P8 q
          ( ycor-of turtle b + y )$ m7 _# S( K, ?
if (remainder who 5 = 2) [set c who
, T! @7 D+ t) H1 I( [' J' b3 O                          set x ( 0 - Wid / 2 )
$ x4 S+ j5 j* u* h' V; T4 Y                          set y (0 - Dep / 2 )  ]$ }5 L3 o% c, f2 O
                          set d int (c / 5) * 5, G: N% s$ s- k" d, @' |# P% L
   setxy   ( xcor-of turtle d + x )
- ?$ b6 J/ i: Y* _0 \8 D5 P           (ycor-of turtle d + y ) 8 d) ~. u7 Q. `6 @* n8 R0 y
         
  u) n. m' H" v/ k0 n' R            " ?* e2 g, c4 ?  U* S0 K) \
if (remainder who 5 = 3) [set k who- P# v# {7 E* ^. A& Z
                          set x( Wid / 2)  ) S; V) F5 f9 U9 P$ ~) y
                          set y (0 - Dep / 2 ) ]
- C' _- l1 T* B3 y3 E                          set f int (k / 5) * 5
  T- }+ K; x$ ?" L) r( \  setxy   ( xcor-of turtle f + x )) Q. x. J6 ?+ C4 K
           (ycor-of turtle f + y ) 3 b$ i( Z8 B9 m! m7 o
           + w2 Q8 @! C' p# }! P& x* q
           
+ Q* {0 ~2 H3 o8 u- N0 Y2 R* `if (remainder who 5 = 4) [set g who1 ^6 S% z+ t: r
                          set x Wid / 2 , E4 l( t! I; W  R- F7 j! V
                          set y  Dep / 2 ]
: A) r+ r+ y7 N/ `% L: T7 q: W/ [                          set h  int (g / 5) * 5
$ J7 H! `# c9 t  setxy   ( xcor-of turtle h + x )
: U  w1 Z: y" F. n$ x           (ycor-of turtle h + y ) ) U4 t0 F1 u' c: s  T
                          - {1 d) x, Q. @- J8 R  |0 v* B. C0 a9 n
                          : t4 N! Q, p/ x" x8 Y! S
                          ]4 \5 \* i" S0 w
end
. E# e/ z' E( q5 V
: _5 N6 {3 w! x% ?[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,: {1 U: H8 {: n  m+ u5 |
应该是
% c; g# L2 h0 Q, o8 s2 Lask turtles [
  ?0 f9 n  y+ K# w; m- K5 pif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
) y2 R* U7 w# `- e3 T                          set y  Dep / 2 , L5 ]; Y6 H: U) q/ G8 k- f
           set b  int (who / 5) * 52 C3 r, ]+ D% W: h
    setxy ( xcor-of turtle b + x )6 d2 F' ?& q4 f  \* s1 N: v0 I) H, m0 v
          ( ycor-of turtle b + y )]]
, S, y) ^3 W' W8 o8 Yend
" [- P3 T: g' [9 e/ M# e8 X之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-12 16:27 , Processed in 0.019706 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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