设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8044|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
$ N8 m+ M7 x# m* y& S  C
5 O/ s& R( p0 _. M# L但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
& @7 y6 d4 |3 u: I4 G  k' @+ R
/ Q" P7 W' ~5 uturtles-own [a b c d k f g h
, I( T1 q- j" ^1 t3 N2 t! {  x y     ;; these are the leaf-turtle's offsets relative to center-turtle % K! U5 Y: `+ H- P  r) A6 ?
]% ~* T0 ^/ U( `6 x& a, G, p
to new
9 N7 m5 Y# h9 y  J- ^8 _  ca7 \7 Z4 d9 n" h, \' \8 M3 z5 C- |) M2 |
  crt 5 * num_of_building
/ k8 `8 z+ N6 x9 p  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]0 g2 H5 k. |& v
  scatter     ;;keep center-turtle random positions " k2 R. I' u( x
  unit_plan   ;;make up the building plan: K% v6 X0 x- l0 e( [% _( [0 x
end& s3 p0 W  Q9 _; m4 C8 P
to scatter
3 G% g. ?  o% E  h/ Vask turtles with [remainder who 5 = 0]
7 _: m3 e- Y1 [3 q/ u1 K* Y4 V[9 c' @# f6 s$ @/ i$ f! P
set xcor xcor - 6 + random-float 15
: o) i0 L* V$ [$ a. |" s4 r* K. Qset ycor ycor - 6 + random-float 157 `! n7 {& l0 w* g5 T* U! K) `$ K
]& Z9 j$ U" m4 x
end; Y& ~9 V. ?( w0 f4 i$ O
to unit_plan
/ z% H% t' }" Z) p. Kask turtles [2 c! C) ]* `) u) v0 J
if (remainder who 5 = 1) [set a who
% x8 l" J; [! F3 c! ?3 z  y                          set x ( 0 - Wid / 2 )
. s4 h2 R# ^8 V. w; r                          set y  Dep / 2 ]* S" h. W3 O1 K& [0 i0 G
           set b  int (a / 5) * 5
) @% x9 ?# ^! T1 u+ E% B& h    setxy ( xcor-of turtle b + x )
7 _9 `$ d2 E  V+ y: t          ( ycor-of turtle b + y )
, S- K3 x% ~, Zif (remainder who 5 = 2) [set c who$ z$ `6 k4 D5 h0 t' s8 C
                          set x ( 0 - Wid / 2 )
' W9 O) y- q% k* y: p                          set y (0 - Dep / 2 )  ]- J7 _6 j" J: N
                          set d int (c / 5) * 52 S4 t# h+ t$ h
   setxy   ( xcor-of turtle d + x )* O! @! Y$ B2 e( y
           (ycor-of turtle d + y ) 8 ]- A& g; Q3 F. g9 l0 _. _+ e
          9 J# ^4 G& w' D( C2 H* ^) h
            5 D* B6 p# |% ]
if (remainder who 5 = 3) [set k who
0 `# W) @8 {1 V                          set x( Wid / 2)  . d1 b/ ?/ ?* D5 G6 d8 E* f3 Y7 v
                          set y (0 - Dep / 2 ) ]  c! _6 }7 D& E
                          set f int (k / 5) * 5* k7 T7 D! E$ b' o' O% j2 K* e. U
  setxy   ( xcor-of turtle f + x )
& @$ z- j+ Y7 t           (ycor-of turtle f + y )
. f1 H7 N' H/ w! ~- t: K           ) f$ @6 @+ C2 t. O' P* X& |
           
1 ~0 c: Q; m: x4 l  h9 Vif (remainder who 5 = 4) [set g who
2 a3 x' L' U/ n. V$ F9 s0 K' V                          set x Wid / 2
  K1 z1 @/ G* R8 C                          set y  Dep / 2 ]: T( \( u& b1 x! A$ u1 J2 N
                          set h  int (g / 5) * 5( [, v& G# k1 c* l$ z$ y% y
  setxy   ( xcor-of turtle h + x )
3 b# `  Z/ ?3 D% x" f) }0 |           (ycor-of turtle h + y )
9 W% I4 ^$ e9 ?. }% E1 N                          
* ^$ {- i* y* t- T" W* }: ^                          
/ z9 F3 a* H+ P/ Y" E                          ]
5 X/ z5 |( B8 i8 oend0 _) V5 U0 E: s; m+ v, H4 d7 f
. ^* T4 P+ l( m7 d
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,+ Y% S# m7 ^8 b0 J$ p$ |: L
应该是5 Z. c% ]7 U7 a6 u# Q. }
ask turtles [0 i6 t% B+ q! H. Y" x, i# n
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
. T; _0 O6 t2 B+ C7 ]+ s                          set y  Dep / 2 6 f+ k5 m0 a0 |! u
           set b  int (who / 5) * 5$ \  W9 ?7 ]# c$ z" K3 p) J$ @
    setxy ( xcor-of turtle b + x )
: ^% Z, m  @' T* x          ( ycor-of turtle b + y )]]
7 T+ ~# M) j5 q7 Z8 zend! t3 W3 z6 M  [9 ~
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-1 08:35 , Processed in 0.016525 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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