设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8285|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。2 ^, M, R7 y; H* [* s1 N

' Y- u# S3 x8 _! t. c" e但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。7 `! i% T1 S4 Z3 {7 B% l/ d

2 Z$ i  T3 J; s8 h: b0 H  X0 L! Oturtles-own [a b c d k f g h
2 N  h  q$ @8 Q; Q  x y     ;; these are the leaf-turtle's offsets relative to center-turtle - f$ x( I- a) X( {! Z8 Q2 ^
]
0 r: H2 a! ]# I4 g: w4 d6 Fto new
" l. q% ~% ]/ ~8 e  ca3 g" h6 J; T% Q" J1 D& o$ p
  crt 5 * num_of_building
  H3 F& K$ S/ {6 S- K  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]) t$ Z& s* g2 c; E
  scatter     ;;keep center-turtle random positions , V& X5 s# l, \/ ~& r
  unit_plan   ;;make up the building plan
! o8 Z  ^0 x* S* w8 Cend$ o4 I' n5 G6 y/ Q/ m  q! x  Y
to scatter
1 j# ^) `/ r1 H2 Q. m2 i) Yask turtles with [remainder who 5 = 0]
% q6 a* X, o2 b; R8 `' Z- ^( L! C[
& n' A0 z- s) P. T3 ~; f+ p( hset xcor xcor - 6 + random-float 15
5 Q& n. w' z4 N$ U; Vset ycor ycor - 6 + random-float 15* a6 ?* c9 o4 D, f% \! e; V0 O
]! r* Q" a, R" T! b. ]
end
# d! k9 I1 h: pto unit_plan 5 t. R. k5 J% d3 H3 m& D
ask turtles [3 d! A0 A; S* K/ _
if (remainder who 5 = 1) [set a who . z4 e, z0 w4 p! _9 a& ~2 [" Q
                          set x ( 0 - Wid / 2 ) ! U/ f" E% W; ?
                          set y  Dep / 2 ]
7 x5 B; A5 e; a4 ^! i           set b  int (a / 5) * 55 p" r% j2 L+ W" L3 [  \5 v7 t8 k
    setxy ( xcor-of turtle b + x )
" V1 \9 U- k* O' I: f9 u  a9 y          ( ycor-of turtle b + y )+ e8 v8 t# w4 H) `4 D* j. F( D& I
if (remainder who 5 = 2) [set c who. p( O& b! U" }# h( Q& p
                          set x ( 0 - Wid / 2 )
% f: s" x8 N* H% ~7 @$ F( G! e                          set y (0 - Dep / 2 )  ]
7 W2 t/ Q7 o7 f; I% \/ s3 _                          set d int (c / 5) * 55 s% g0 u: P) I
   setxy   ( xcor-of turtle d + x )5 C' Z& f+ r+ R6 ~) w" y+ ?! r
           (ycor-of turtle d + y )
+ @5 K' r: c0 Z% l         
- H4 H3 L4 r$ M' O" ~- ?            
, L1 u( Z5 W! E2 e6 K* Uif (remainder who 5 = 3) [set k who9 q" c* X( f8 {6 B& S- J3 B& D
                          set x( Wid / 2)  * M4 B" h; ]1 v2 w
                          set y (0 - Dep / 2 ) ]
; ^' T* o( K- R4 C: {$ \                          set f int (k / 5) * 5' b. B' ?' r/ T7 ]( A
  setxy   ( xcor-of turtle f + x )
) p1 q( a( H* c. g3 f0 ?: N% [/ e           (ycor-of turtle f + y )
/ r% y5 e3 D1 I: m( F7 A           
: J9 L7 S% C  y7 F           
4 c( a3 @" E5 M! N4 Vif (remainder who 5 = 4) [set g who% Z1 V/ Z" v0 [7 m; P2 K% C
                          set x Wid / 2
- x' j7 u( x2 \9 ]1 ?                          set y  Dep / 2 ]0 w  x( a1 `4 F, F! t1 s
                          set h  int (g / 5) * 51 }/ U8 _& [3 p( M' r8 r. h1 ]
  setxy   ( xcor-of turtle h + x ): T# R, V- b& t) p& K* a
           (ycor-of turtle h + y )
4 a: A! d% @" U% V+ t8 n5 `                          
5 V) e: L  b! n, L                          
$ u$ m# J. f# s. u( E. L                          ]
6 G, x: K+ V3 Z* @# lend! c. g4 }: |* |# f$ p$ P

+ v% ?8 {! h: ^[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
( [* u# W) d& {4 C$ u应该是
" T$ z, G3 \9 b0 M3 i4 V; Hask turtles [2 m5 d* `# T; Z# x0 P
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 7 e! Q8 q3 m$ j6 [; c; d7 j
                          set y  Dep / 2 # E' j# X6 M* g
           set b  int (who / 5) * 5. k. s  e$ B* i% ^% J  I* ?
    setxy ( xcor-of turtle b + x )
: ~0 B( r, M7 j          ( ycor-of turtle b + y )]]
- m, a: {5 N- B: y$ pend
! c$ D, l/ j( }5 _$ j4 l之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-31 03:44 , Processed in 0.017551 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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