设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8052|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。6 q, o% y# E- I
; c' A& v3 Q# A6 y
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
# k/ z* ]/ T2 f- F6 l! p
. y- ?8 G9 g- ^: A4 `turtles-own [a b c d k f g h
4 U  c8 E' i; s! w  Z  x y     ;; these are the leaf-turtle's offsets relative to center-turtle , P. K7 U* D! o& Z" [3 b& [' o! q5 k( Q
]
* b5 b# L8 J$ \- r! dto new
6 q7 s" g6 X3 f3 u, X  ca. o6 V; P: S+ O+ L8 V
  crt 5 * num_of_building, c$ W$ j) c2 ~3 D5 b$ ]
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]: ~7 V4 F( K5 ^( s
  scatter     ;;keep center-turtle random positions 4 I" u) {) F* D9 A( J  \1 x$ n
  unit_plan   ;;make up the building plan- m8 |3 h1 [1 M
end- P% J$ M8 P# l) o+ J7 l' b8 [
to scatter
$ C5 `5 f+ f- I9 Z: Dask turtles with [remainder who 5 = 0]
* e6 G1 p/ G. d' V: w8 C[
5 Z2 o$ s# Q) ]. Rset xcor xcor - 6 + random-float 15
$ e1 ^! u# |8 |0 w- h) fset ycor ycor - 6 + random-float 151 D7 G  P9 ^* X3 d
]  r8 S1 e% t5 U/ B* \
end
, V9 P9 Q& a, v  T0 o! vto unit_plan
# D+ r6 q; C# {4 Y, Uask turtles [6 n1 Z4 ]" c4 K4 a
if (remainder who 5 = 1) [set a who
0 r3 F# p; }4 R5 V4 k, p' }8 F                          set x ( 0 - Wid / 2 ) 2 R3 P" u4 l& |) v3 w' q! k
                          set y  Dep / 2 ]2 {* O$ Y" d2 I& p: j
           set b  int (a / 5) * 5
- L# u+ `: o) W% z3 y    setxy ( xcor-of turtle b + x )
& Z2 ]# T* q& \          ( ycor-of turtle b + y )
8 j8 Q0 }% d- Y8 j9 }if (remainder who 5 = 2) [set c who" O+ Z; |: H; _4 H# T6 O8 s) N
                          set x ( 0 - Wid / 2 )
) Y) i- e( R. T' e: r                          set y (0 - Dep / 2 )  ]; a! }5 I+ k4 B" N# O( l. A0 d0 t
                          set d int (c / 5) * 55 q5 L: y( D& f2 r8 T0 }
   setxy   ( xcor-of turtle d + x )2 Z$ v/ T( S# j
           (ycor-of turtle d + y ) . l2 i  a, y; ?6 I# I
         
3 M5 O  X9 S$ D* s: g+ w: ^+ L" B            9 P# A. I) j1 i  \& `5 \3 \; }
if (remainder who 5 = 3) [set k who& V+ J- F: u" h3 q4 p1 H# T0 W
                          set x( Wid / 2)  
/ J: l( H. t; _5 u5 Z                          set y (0 - Dep / 2 ) ]' g# c3 y7 R7 q- \& _
                          set f int (k / 5) * 55 K; P+ d5 D* Q0 i: M$ S
  setxy   ( xcor-of turtle f + x )
+ b1 ]* ~. m, `* o) b. G2 L1 U           (ycor-of turtle f + y ) 7 T% d. r! `1 m8 Z1 x- [+ c, i4 o( |
           
9 z; ~5 A7 I) A. t6 ~$ ]: ?           ! [9 p4 d) Z4 u2 z
if (remainder who 5 = 4) [set g who2 M! [) v  s, y$ @8 K
                          set x Wid / 2 ; _) d; f; ]0 O
                          set y  Dep / 2 ]" n  J% k6 l& |$ U5 E% P
                          set h  int (g / 5) * 54 F  E* `% Y* z* z' j
  setxy   ( xcor-of turtle h + x )
( w6 p* C/ g1 X" D           (ycor-of turtle h + y ) 6 c. U+ e2 G& r, u
                          2 ]) N( p6 z  k4 a
                          2 i2 ]. i/ p2 P
                          ]3 ?3 L0 ]- C# \+ @. _
end
# l6 P) U, Q# u! q+ f5 u: U' ^; P& P3 f: o8 _% u4 j! P/ P: L* y% {
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
: x, A3 d9 {, I0 m9 v应该是
8 W$ O+ |" q% m. R% K% vask turtles [
/ S  z. r/ I( ~* y: K2 e, fif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
+ `5 B% N5 J) U( J5 B% W8 N                          set y  Dep / 2 6 H# K' B  B5 N
           set b  int (who / 5) * 5
, e; P$ x& c) I3 n) d- C$ F    setxy ( xcor-of turtle b + x )# f- Y+ V4 L% j  A% D
          ( ycor-of turtle b + y )]]
& y' h- z% s0 e/ ]end
! u$ t+ f8 B' U0 c% e$ u5 z之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-1 23:43 , Processed in 0.015293 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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