设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9008|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
8 B4 x" M+ `; _7 k; I% B* [0 ?7 m. |5 @6 _% e$ ?( v" p
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。2 X+ `* X1 F1 W7 X

( ]  ]4 l  I6 {/ t" _/ pturtles-own [a b c d k f g h5 ], x5 H6 v4 l8 o. n: l
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
/ K! B2 ?8 c0 X8 _  j]
; {& M. O4 `& q9 j6 t1 Sto new
5 X. \' d6 Y1 m8 B2 w1 C  ca
# _* [8 l# c6 r" R7 H6 Y! Y7 y5 [1 ]  crt 5 * num_of_building& x6 d% C9 i. Y1 m: T1 I
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]& s9 \" V* \6 }5 y) Y7 E
  scatter     ;;keep center-turtle random positions
) H4 U) C! |/ ~- C; j' M  unit_plan   ;;make up the building plan
. F0 a! i9 p) a# Jend8 E3 D/ Y; Q" p
to scatter
* k5 z( B% `  t! h$ pask turtles with [remainder who 5 = 0]' k1 w' o& o. Q* a3 A. J
[
0 I2 G, b' x: N# x8 \0 }& o- mset xcor xcor - 6 + random-float 15: ]: l) m% {- L. J9 o- y
set ycor ycor - 6 + random-float 157 E$ P) _1 V; z
]& O8 z# P: f$ y+ J. x3 D' e
end/ Q' F4 H- K9 ^9 }* z/ \5 G
to unit_plan 3 W( V- Q0 K: k8 E, D, u. ^; L
ask turtles [5 P$ K/ E9 W/ r
if (remainder who 5 = 1) [set a who ( v2 G$ _  b- D9 t! D2 e3 o+ D
                          set x ( 0 - Wid / 2 )
: B" g$ `$ Z& ]& C) Q0 ]9 y* c8 w                          set y  Dep / 2 ]
% x: C, L3 `5 c& `  e           set b  int (a / 5) * 5- j6 E3 v: D2 n( N% J
    setxy ( xcor-of turtle b + x )! f; `. i+ p$ T4 t. F
          ( ycor-of turtle b + y )
2 {0 O& v6 h  D; Fif (remainder who 5 = 2) [set c who! S. l: P% m! e- S8 D
                          set x ( 0 - Wid / 2 ) " K+ U+ S& t) C
                          set y (0 - Dep / 2 )  ]* L  u8 m0 B" B! _
                          set d int (c / 5) * 5, G( @* N- t+ C4 I: V
   setxy   ( xcor-of turtle d + x )
# T" A. q; R5 `9 X6 c, Y2 m           (ycor-of turtle d + y ) . J% N! d4 J) i
         
* B  R$ X4 V* t4 `% q' o            ! X4 N+ A8 R2 l- ]# f) T) m
if (remainder who 5 = 3) [set k who
6 n# S' U; P2 G$ z  E                          set x( Wid / 2)  
) ^; q* V8 P' L+ n4 I+ Q/ O% o+ S                          set y (0 - Dep / 2 ) ]) j. z6 S" L. Q% N% F
                          set f int (k / 5) * 5( `) L, M. Z7 F1 f) @' Q" W  b
  setxy   ( xcor-of turtle f + x )/ \3 N2 V: P) G/ u' y% I
           (ycor-of turtle f + y ) - ]2 T+ r1 Y- i
             Q! o; z3 ]0 {; P+ O8 s: o
           ( a  S; y* I" ^2 a
if (remainder who 5 = 4) [set g who
  Q, W/ _: x3 m' x6 z( b) {9 k                          set x Wid / 2
0 i9 [% P( a0 \- d                          set y  Dep / 2 ]6 _  l. z- Z+ w3 f, m2 x: V
                          set h  int (g / 5) * 5' t& W& P7 ~. N7 g8 s
  setxy   ( xcor-of turtle h + x )0 d. F9 z$ F& Q. N6 @, I. w9 K  q
           (ycor-of turtle h + y )
; v0 f0 T# n5 k9 s( P                          
. f  Z  }7 s4 b3 E3 U: h                          7 P  I/ K/ K( C( f
                          ]7 ]8 A" b' a1 J2 _: m6 L) a" w, d% [% }
end5 Q4 T- T8 c0 p7 s1 P* H

0 L: P) [0 t  S[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
% M$ V7 `2 Y5 `5 l1 u" C( s应该是
) o4 J) ]5 G. xask turtles [( f3 {/ R7 d# N  a% Q- v
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ) b4 O9 U. s& ]5 a+ b2 C
                          set y  Dep / 2 ; a7 K( S2 ?# w  I( W
           set b  int (who / 5) * 5
. W) |) f! Z% Y( _$ K3 ^* R2 ]1 @    setxy ( xcor-of turtle b + x )1 k  k5 b+ H- A+ G
          ( ycor-of turtle b + y )]]
2 d! `7 z8 p6 d" P' jend
% u9 h7 s9 S- t% b# z之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-6 03:28 , Processed in 0.015956 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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