设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7479|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。8 a3 d2 v0 j+ |3 U; s, y3 G1 ]/ ]6 j
; Q7 S0 t. u2 t& P$ F
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。5 e- o- [& t# D  e1 B  j7 h
7 b& b& ~3 t  @+ q, b. r' O
turtles-own [a b c d k f g h( ^. O8 _4 w$ e# T. m1 }
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ) I. D( q3 G9 s& u% X& u
]
0 g' K  P" z6 o4 g3 Cto new
' f- v7 A, q+ a  ca% b+ b2 F( i3 r. T! Z
  crt 5 * num_of_building
. |) p7 u  G! ?$ g% ^* Y' r  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]* T( ?2 U6 |7 ^. j1 v9 W! R
  scatter     ;;keep center-turtle random positions ) s" e5 s2 u) N" }2 @& v' P
  unit_plan   ;;make up the building plan3 F" j) @6 g1 W0 @5 V+ {+ _
end, {% P9 m  O) A% Z4 S- r
to scatter
1 B: s1 W1 n8 `- Zask turtles with [remainder who 5 = 0]
* g6 f+ \* D0 n7 D0 p6 o% F[+ Q* W, ]) \3 s/ p0 U4 t
set xcor xcor - 6 + random-float 156 `7 D9 u+ i% m4 r, |5 ?
set ycor ycor - 6 + random-float 15
  w$ V, H0 B2 S2 n. k]- o) B% k' }" V& C7 H
end4 D$ Z) j: Q4 E1 v- e
to unit_plan
& r; S$ v% U8 S' `9 E& O* }ask turtles [* w+ k! p( H3 c% b& r& L/ P
if (remainder who 5 = 1) [set a who " L  L& f/ f: J9 K! S& M: V
                          set x ( 0 - Wid / 2 )
6 R* E# ?% D5 \7 K" q( z) X                          set y  Dep / 2 ]2 \3 p# V1 r; @( T/ Z
           set b  int (a / 5) * 5
' S$ w* M( o1 I$ C+ u8 g    setxy ( xcor-of turtle b + x )
7 E3 U  u& M! S1 G" H5 v7 M          ( ycor-of turtle b + y )
# A+ K0 B' g$ E. s* u' vif (remainder who 5 = 2) [set c who
7 q- p0 f5 e; G+ J5 L' t                          set x ( 0 - Wid / 2 ) 7 g/ H- H8 ~, K# f0 y
                          set y (0 - Dep / 2 )  ]
, J+ B, S3 \3 D. d4 D                          set d int (c / 5) * 5) W! g; W4 X1 _" \7 S3 K  u
   setxy   ( xcor-of turtle d + x )% X8 z' K, x) J& U4 m; r; K* x
           (ycor-of turtle d + y ) 1 I+ n+ J7 _( R* G
          0 t3 x2 G0 f7 E( [, ^2 g
            0 N/ R2 {( L/ Y( c
if (remainder who 5 = 3) [set k who4 }" k$ ]& _/ P& W6 [2 B# A0 n0 O
                          set x( Wid / 2)  
: U- o" p) [1 `& S, i: @+ b- I                          set y (0 - Dep / 2 ) ]$ L, g% h6 f. t8 _
                          set f int (k / 5) * 5
7 V# W1 l; s! c  setxy   ( xcor-of turtle f + x )! H' {4 b& P. w& |* C2 |- S
           (ycor-of turtle f + y )
) U( F8 Z0 p2 p1 R* V& y           $ \# `3 l$ D+ m" Z
           / Z% x7 z6 T& ?0 F
if (remainder who 5 = 4) [set g who/ ]% i) z8 N  O4 {0 V. n
                          set x Wid / 2 - F6 H) p' h# {
                          set y  Dep / 2 ]4 Z8 g$ N; ^  ]( ~, ?4 |
                          set h  int (g / 5) * 50 p. M0 T" J. G: f8 L) J6 V$ Q  O
  setxy   ( xcor-of turtle h + x )
4 Z/ y; e/ j2 D& B           (ycor-of turtle h + y )
$ z1 B. ]7 \+ w( ]2 U8 M% I% I6 l                          & R1 x. |0 k/ C9 R7 p
                          
- Z; `8 B7 s/ z* e) Y2 H                          ]
3 n, X- h* ~* X) lend
& m+ @$ R8 v/ L+ c7 {
! C4 c$ P9 R4 Y. Y  [' r$ X& Z[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
. t  j; `" ?& A% H应该是
5 H, m* v7 A* c+ e1 Zask turtles [  v  T- d* j2 _
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 4 V8 H  K( G1 {& }* d
                          set y  Dep / 2 1 k1 P% B9 v9 p! A
           set b  int (who / 5) * 5/ G5 [3 g' f% t
    setxy ( xcor-of turtle b + x )" V% ~" y$ l1 y7 M( j/ s  d
          ( ycor-of turtle b + y )]]
3 a0 y; u  v' ?4 uend
* c5 u  \( z# l2 `: {8 Y之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-16 01:00 , Processed in 2.402182 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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