设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8338|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。9 b9 R9 p3 b( ~: {) @7 N

0 Z6 ^2 |% m% J: D  M但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
- K# Q# t3 s% U2 {# f/ D
* I+ r9 b4 |  o# H- L0 _turtles-own [a b c d k f g h
8 j# a) D+ l/ I  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 2 M1 m8 K) L. Q( @( R7 v$ Q
]: o5 M* E# c2 f& a; K7 y( n
to new8 |* V7 ?) g# Q3 K( R
  ca9 f% I! _. @0 _* V2 E3 ]6 N. k
  crt 5 * num_of_building
& s9 u2 c0 u1 z! z8 d1 K  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]% V/ h& M! `; j* p
  scatter     ;;keep center-turtle random positions
. k. P- M2 }5 M5 t  unit_plan   ;;make up the building plan
! \5 N& s9 k" ~7 W4 r  Iend1 {7 N# z  Z* o' \- f+ y1 L
to scatter
8 ^2 s3 z+ ^. n2 o, I* P/ f, Wask turtles with [remainder who 5 = 0], A, \0 U( S, e5 q
[
, i' _( N, ~$ M5 cset xcor xcor - 6 + random-float 154 }0 l; x! A. ]8 y; n
set ycor ycor - 6 + random-float 15
/ h$ l, S+ y9 s]# N$ p1 R" T4 V$ X. E* }% i
end
( j  V' `8 N2 O* [to unit_plan - c" _. [, ]# L& `1 l
ask turtles [% V0 b7 d$ d4 E* C, u
if (remainder who 5 = 1) [set a who
! M9 t5 e; O3 p9 ]5 [" P; d$ u                          set x ( 0 - Wid / 2 )
) l& m/ |2 ]: Q: q( k% X                          set y  Dep / 2 ]
- Y- o1 |% k5 m4 m' ]           set b  int (a / 5) * 5
# ?; o0 q1 T& h    setxy ( xcor-of turtle b + x )
/ Q9 L2 v) [. s4 j          ( ycor-of turtle b + y )" O2 Z, Z1 t* B2 @' G3 G1 B
if (remainder who 5 = 2) [set c who0 r8 x% V! z" \8 c
                          set x ( 0 - Wid / 2 ) 8 V) ]8 O, S4 ]
                          set y (0 - Dep / 2 )  ]# L) e5 B0 g1 b+ }
                          set d int (c / 5) * 5
" U: }, G! @3 P   setxy   ( xcor-of turtle d + x )
1 _5 s* T7 _8 Q' _6 J/ P; m           (ycor-of turtle d + y ) 2 ^+ B1 p% a* K. H( X/ U  K( o. z
         
9 x0 {/ ]# T+ B8 R9 w- e8 }            * Z8 T$ ^0 O; W
if (remainder who 5 = 3) [set k who3 M3 Y: i! g7 z1 F  ~5 P+ G
                          set x( Wid / 2)  2 o4 w$ t; i' b  B. H
                          set y (0 - Dep / 2 ) ]  q+ K) r( G1 z, W/ J# q( L
                          set f int (k / 5) * 5
3 @) i% g) l- U  setxy   ( xcor-of turtle f + x )% r; D: N8 y: b' B
           (ycor-of turtle f + y ) 1 b: \3 r0 s/ F
           
9 B% k" @8 E3 v$ T+ r" O! l  f           8 C  R# q6 }. t/ s2 s
if (remainder who 5 = 4) [set g who* U( |7 {4 x( w  S8 r
                          set x Wid / 2
+ G( G: Y/ V2 W' D. x! J  P                          set y  Dep / 2 ]4 c+ P' R: G9 X
                          set h  int (g / 5) * 5
" g+ q6 [! ~5 ^$ e5 d  setxy   ( xcor-of turtle h + x )" m7 @, g% v* x/ G  d# t% E8 h0 R
           (ycor-of turtle h + y ) $ p" a- F3 y5 k9 u
                          ' K$ g4 }. j! ^' R2 H
                          * Q* S2 |# V$ L, I
                          ]
3 G* ?& V/ S# M3 x9 g6 j( Bend& U7 R' o/ p! I) m
/ t. b( t# C; g( c, h
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
# t, D# Y7 z( T$ ]- B+ w6 t应该是% j! D% G9 O, X$ i/ Y$ d
ask turtles [; l& B6 I% J- w4 B: [; F$ L7 n
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 3 }) I  U. k. a* x# e3 q9 m1 H
                          set y  Dep / 2 # p3 q! ?8 s3 b9 \) G" s* b( I9 [
           set b  int (who / 5) * 5- c+ H8 m$ x/ u/ T* S' H: R, {
    setxy ( xcor-of turtle b + x )
" q0 p3 i/ t1 g& F2 B  d          ( ycor-of turtle b + y )]]3 i7 u) U* F" V$ N
end
0 A2 Q, G; Y6 c5 J3 _- M之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-10 07:53 , Processed in 0.017932 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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