设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6747|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
( v2 t# c$ V8 q6 I( f
7 U0 w2 ?4 {, ?7 b! m. ^2 L1 o: e/ b但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
5 `$ K1 c; s) m- h
' q* i0 m, ^6 T( ~, L7 \( qturtles-own [a b c d k f g h
: s3 w9 p' f- W2 N+ w  x y     ;; these are the leaf-turtle's offsets relative to center-turtle * M  h0 W7 B0 ^, j. z1 m
]
2 ]7 ]( H1 _5 T1 d: D* zto new
/ U% j/ l6 M* a; m) P  ca
& p' o2 t- M9 \) L) _  crt 5 * num_of_building/ R& T- A! T0 e2 [3 u0 Z
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]8 ]. P" e3 K0 u5 E- x
  scatter     ;;keep center-turtle random positions
" F3 {+ i3 D; Y  unit_plan   ;;make up the building plan
) p2 k2 ]' F  Z0 \* t: R% {end/ T7 G; U9 I6 T
to scatter
% R) U& {4 K+ r( g# q8 oask turtles with [remainder who 5 = 0]  ^* X. A4 }- g3 }# @0 _% s" J/ F
[% X# N0 W( L5 p+ X- l
set xcor xcor - 6 + random-float 15  [6 D. W* H2 P  x" w5 d$ H
set ycor ycor - 6 + random-float 15
6 r/ ^0 R3 P, b% ?5 E]
  S# \1 C( l* @6 w; a) Aend5 D/ t4 f$ [# B" u) y
to unit_plan
$ v" |  m4 c: G6 S# v$ f+ Z- D+ Nask turtles [$ P& A4 {$ r% e# W  B& ?
if (remainder who 5 = 1) [set a who
( u' ^. R$ ?  t2 |, [                          set x ( 0 - Wid / 2 ) 6 X4 Y6 F. p% g7 [
                          set y  Dep / 2 ]; R' }! j; G+ x# _( j! o; w7 m
           set b  int (a / 5) * 51 P) l& v' L% P/ F
    setxy ( xcor-of turtle b + x )+ E8 u! Q# e% D
          ( ycor-of turtle b + y )
; ~3 x! }+ n9 z3 s$ }if (remainder who 5 = 2) [set c who( Z- h- y( \9 X" I- q% Q( Q
                          set x ( 0 - Wid / 2 ) 9 X' k& x  ^* ~* g8 C
                          set y (0 - Dep / 2 )  ]
2 ?- H/ h, ~8 U  e                          set d int (c / 5) * 5( k2 F( g0 Q! S! V1 V& V
   setxy   ( xcor-of turtle d + x )" N" |- G2 U9 W' x2 i- U6 G
           (ycor-of turtle d + y )
5 s5 v8 V2 l. U0 B! M* Z9 y$ n          * }( l& w  d/ w' c: `
            ' Z# p2 R( W) g7 |0 L4 |1 M  `
if (remainder who 5 = 3) [set k who
! Z! G5 _; c+ e) e3 i                          set x( Wid / 2)  
8 n, |4 ?- c7 q                          set y (0 - Dep / 2 ) ]
& U2 {* k2 X, s                          set f int (k / 5) * 59 a4 Y3 _) O5 z
  setxy   ( xcor-of turtle f + x )5 f6 o) A5 z; D/ v
           (ycor-of turtle f + y )
, S( c0 p: f4 i- I- |           % m+ r3 _: d3 o% n
           
" T' ^+ ^6 e6 E* ?7 o( rif (remainder who 5 = 4) [set g who1 W' H7 P4 ^- t% e( F! q
                          set x Wid / 2
4 Z- |- b. J8 \  P, [                          set y  Dep / 2 ]( q4 n" ^; K+ ~' ?
                          set h  int (g / 5) * 57 y- N; d5 b; i: h  e  X
  setxy   ( xcor-of turtle h + x )4 A: e7 C' F0 @, c. Z1 J. ~) I
           (ycor-of turtle h + y )
  A, W/ J/ P( x, x2 n/ L1 K; u                          6 n" w; M9 p8 J9 G+ t* s/ q4 B4 q
                          3 z$ u# e# z- e4 S, Y$ S/ q+ J4 D
                          ]
; [( ]2 a' ^8 b$ Dend' Q$ K1 w# f: p# d( B( b

: v* I) Z/ n. @. A# F% M[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
9 g4 p1 t: n, I" w应该是
: k  w/ H4 U* N# {( e9 U" Hask turtles [
# U/ ]5 Z' s! j* oif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) * R& Y5 M2 C( P# E4 U  b
                          set y  Dep / 2 0 G: E6 F* j: ?1 w- s3 C
           set b  int (who / 5) * 5* D. h7 Z* S( j9 L
    setxy ( xcor-of turtle b + x )! h) V, O" Q4 K5 ^2 a& o" }. }8 \
          ( ycor-of turtle b + y )]]
+ v3 v, Q3 r* t$ U& U! Wend
2 j3 |+ ?/ t& T( D/ a+ y& G8 [之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-20 06:36 , Processed in 0.018065 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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