设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8231|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。8 a3 |1 G, c( W8 ~& @7 Z" S! ^! a

" g+ N* F) Z& m; q; ~5 ]: U, l但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。! U$ b* B1 {) S& R$ h

7 g2 s. c( [: {* uturtles-own [a b c d k f g h: Q# ]7 @4 p, J- y. q
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle + E( ?; z9 S$ ]9 X) x8 p
]! f6 F! o* @9 ?, [) Z& [3 z
to new
) t" C$ M4 L( ]/ R  ca
" q$ n, ?) i0 x  h/ E( M  crt 5 * num_of_building; ~6 C; ~% |4 Y0 n
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]! z) a5 a* F: H' @/ U( X
  scatter     ;;keep center-turtle random positions
+ t( t1 M; S  Y" \  unit_plan   ;;make up the building plan
; a/ a  _  L$ s& f6 D$ M/ }3 v7 tend
% B8 J2 `5 G8 K2 s6 Mto scatter
. C' @5 z# N, c# o' `) V: sask turtles with [remainder who 5 = 0]- t% h" ^  v* l6 _1 T
[
; G9 K, f: N  t, C9 A! zset xcor xcor - 6 + random-float 152 c# Z- M+ I4 _- g
set ycor ycor - 6 + random-float 15% u( ^& W7 A/ m  _8 i% ^, w0 a
]6 L% i; r  \2 L
end2 h! ~. X, W, O) ]0 v5 V0 P( F  I
to unit_plan
3 o8 T$ e% Q, l' N  v) O5 Zask turtles [
5 F/ m( M0 \! ?: @1 Wif (remainder who 5 = 1) [set a who 9 k: L! }0 p' |/ o2 }  m
                          set x ( 0 - Wid / 2 )
+ M( A7 F) ^0 ^4 s% z                          set y  Dep / 2 ]% p/ W# V+ x- V- [. k
           set b  int (a / 5) * 5' ]; q' a; N& L0 ?% u- Y% h5 ?
    setxy ( xcor-of turtle b + x )& T" `' y1 ]  d% V9 f1 W
          ( ycor-of turtle b + y )
) @& K* t  i6 n4 xif (remainder who 5 = 2) [set c who
/ m) W' V- j" Q3 b. G4 t                          set x ( 0 - Wid / 2 ) & K) C) I/ x+ s  n  k1 [
                          set y (0 - Dep / 2 )  ]3 U( }, _5 D9 Z( R; k: }9 o
                          set d int (c / 5) * 5! x( B4 f2 }9 `  L! z
   setxy   ( xcor-of turtle d + x )  _% ^: C  D% P7 X4 ]& o1 c
           (ycor-of turtle d + y )
  j! m! X" T+ _% x         
! m0 N+ s1 [! z; e4 D2 ]. `# G            # z7 \3 Z6 ?3 O( C' H
if (remainder who 5 = 3) [set k who
/ I; j" b7 A7 X  i                          set x( Wid / 2)  $ l0 `4 F6 g& L) {
                          set y (0 - Dep / 2 ) ]: j9 r$ }9 W, x1 ~
                          set f int (k / 5) * 51 R  j4 O4 p( ~
  setxy   ( xcor-of turtle f + x )7 F, D: l6 h6 a: p6 S/ O
           (ycor-of turtle f + y ) - d! c4 }- Z* P: d4 Y
           # C( o& Z  Y% L5 K
           * s# Q" f4 ?/ F0 t" r& j
if (remainder who 5 = 4) [set g who: S% w- \" x5 x/ Z% }# ^
                          set x Wid / 2
8 n4 W& {! j' J, f( S. k0 g& y* I                          set y  Dep / 2 ]+ n6 F- ^. f1 u2 B
                          set h  int (g / 5) * 5
" C8 q& l7 u. I8 {( c: X  setxy   ( xcor-of turtle h + x )
; ?: ^# e' E2 \           (ycor-of turtle h + y ) / f; T0 o  f( O  L8 V
                          
9 S' G' P& w5 r                          7 Q$ \, L% X. @- M2 e1 f' ?& d
                          ]
, f5 ~8 j  y9 K1 v* O8 ~; R# qend, s' t7 t; M$ _4 L, R8 k& _
6 w( H0 a( F5 [6 e3 r5 F- f$ l
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
8 _* K! R8 m5 f+ m应该是
+ T- J/ n, ^0 U/ I: J4 N" `ask turtles [
0 L$ J% G3 L1 T# J* |$ T5 q7 Oif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
3 ]: y- `+ h. j                          set y  Dep / 2
! ~$ y, u& s- l% g# u' |7 S           set b  int (who / 5) * 54 x* n8 o9 a' U7 Y8 T0 F* D
    setxy ( xcor-of turtle b + x )7 G5 j/ ?- f! Y. H5 l# c# A
          ( ycor-of turtle b + y )]]* Z3 x( S# D: J( F* a  H& k
end" L# ~% i! W" k8 W; P' t7 @0 s
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-21 23:37 , Processed in 0.027927 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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