设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8199|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。0 i) q: K' I1 _5 Y
! D# [( B, M) ]  Z+ f3 N5 |5 w
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。7 I( @: c' _4 g& T3 X

6 t3 P0 O# k. c1 p: zturtles-own [a b c d k f g h5 ]# ~! I8 V2 k/ o* @; k
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle . x! B' W; {% j6 u* c% g
]& ?8 P; ~8 `3 I
to new
0 j+ U0 U2 G9 _# L8 b4 f+ ^3 i  ca
# v( `( }, K3 M) h* ]  crt 5 * num_of_building
8 d1 a( T7 @3 [- E  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
  m2 Z' M, \$ y2 x  scatter     ;;keep center-turtle random positions
( w$ H1 a+ T4 U0 \  unit_plan   ;;make up the building plan+ F$ P) u, ~) f! i  }: z: V, h
end
5 \. S. G# {* ^to scatter
0 S( x2 T) P! D/ B/ u0 t* Rask turtles with [remainder who 5 = 0]
3 d3 x7 `: j/ T- f& r: a& \6 A- E[
. [" t4 K, l" h. L+ N2 v: X7 Y8 iset xcor xcor - 6 + random-float 15& s! |7 m, b0 y9 x
set ycor ycor - 6 + random-float 15
* |4 B* L6 s" o/ Z; y  Z]
  ?( G& X/ i4 y  N2 Z* qend
3 t1 ~5 }9 j, Z7 V( O8 p0 P$ tto unit_plan
, c3 G6 G/ {# u* vask turtles [) ^5 K( f6 P' c" R- A& j6 u
if (remainder who 5 = 1) [set a who ! _' |2 A+ o1 v' S: I
                          set x ( 0 - Wid / 2 ) 9 Q4 \) G! H6 x, O1 d* U: ^
                          set y  Dep / 2 ]7 @8 O1 t  ^- |* C
           set b  int (a / 5) * 5
) e$ d. W* p* d: G7 J4 I    setxy ( xcor-of turtle b + x )& i/ J: k& W/ i0 Z9 ?
          ( ycor-of turtle b + y )
6 r$ O2 c, e1 g5 A% {if (remainder who 5 = 2) [set c who8 @; P+ |, o5 a  h
                          set x ( 0 - Wid / 2 )
( m. U6 d8 s+ D' f                          set y (0 - Dep / 2 )  ], _/ _) I; G- M' i# a
                          set d int (c / 5) * 5
' r$ ~/ X1 @# g5 e; P' I: }. o   setxy   ( xcor-of turtle d + x )
0 O+ S& u# k9 Y8 v           (ycor-of turtle d + y ) : r5 u7 `" J# T
          - e0 N2 x- i( X. j2 N6 ]# G
            
9 c, k' K7 s4 M  qif (remainder who 5 = 3) [set k who
0 W# V: t4 Z' q# N                          set x( Wid / 2)  , H: R+ c; K4 W8 \% U: Z
                          set y (0 - Dep / 2 ) ]
. o0 y) {$ i3 R7 H2 g                          set f int (k / 5) * 5
" A4 D- o# n5 N! J' D/ k  setxy   ( xcor-of turtle f + x )1 o+ |% c) Q- m" p0 c, j
           (ycor-of turtle f + y ) # x: f1 W; w- j8 a
           
$ l6 V) F, i! F* J% c# \4 k: O2 j           % X* u6 r- D1 h# N+ _
if (remainder who 5 = 4) [set g who4 I9 m# I- m) ^0 V, T, J: ?  G* F
                          set x Wid / 2
3 ~& T! [6 l% W/ e3 k$ r# Q                          set y  Dep / 2 ]% {9 n* [- U' g( s
                          set h  int (g / 5) * 5
- A: E! u: Q% |  setxy   ( xcor-of turtle h + x )
# r) w, E5 Y9 l. P( O8 W# N           (ycor-of turtle h + y )
  R/ Z2 A& ]* |0 B8 I                          
; t# z1 E6 w7 `5 M+ r& b1 s4 T" U                          & f1 d1 \: ~1 q7 A! I0 K! x
                          ]3 y3 {( @8 w8 ?) C* M
end% \$ P+ x: ~$ L4 v% }  @

0 M- Y9 Z, }6 D  {+ I) \9 n[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,$ r7 w/ V* }+ P5 K, a4 W3 y
应该是
; H) v$ {2 y8 z4 F% r5 I( @ask turtles [
2 d" T" r3 _# P* Aif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
0 {; K5 f* {$ Y6 ~! t7 A' L, o: }# |$ r                          set y  Dep / 2
  ]: k1 J7 a: D  f           set b  int (who / 5) * 57 Z! K: Z1 |1 e
    setxy ( xcor-of turtle b + x )
" c% d4 s2 S: u          ( ycor-of turtle b + y )]]* I% e3 L, V% }8 q6 b  Q- ~
end' v! z- M5 e) t8 U! p
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-17 18:42 , Processed in 0.016461 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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