设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8627|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。% V; B* Z: z1 \4 L1 o6 m, l

% @% c' u. \8 x/ ]) Z但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
4 y4 w1 Z6 l' K3 B- z, R' }& k# e. Y' d7 M* C5 \, b8 w
turtles-own [a b c d k f g h8 r: ~) x/ @) f: U$ s# ?
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
  K- k& J( T- W]" q6 z( r2 v! [& r& _" R
to new
) A( j, K, r) C- p9 a4 A7 d& P  ca
: u8 G( r- D: u9 {% W% F  crt 5 * num_of_building
9 e- s' s1 d. z  B  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]  A! H6 G0 `4 j0 {0 o# u* M
  scatter     ;;keep center-turtle random positions 2 G9 F  G, B9 c" f$ q
  unit_plan   ;;make up the building plan$ [7 n1 c: A5 D3 s) }0 c* N
end5 p/ B' @! b* r7 g6 d
to scatter
; H: i5 v6 h9 ^( bask turtles with [remainder who 5 = 0]
* G9 s5 w6 J- ^[
+ X6 z; t) z' k" W. r" [set xcor xcor - 6 + random-float 15/ U3 z5 N0 C2 V9 Z; I6 f" P
set ycor ycor - 6 + random-float 15& K8 v; G; ^. \3 N  a
]8 k& T2 O2 G/ ^( a! `
end- s* X0 l& m7 h$ I
to unit_plan
1 \4 ~. c0 i; [, }: i$ G  z2 o  t) Y( rask turtles [
. I$ _1 s9 z% Z) s7 h9 a& [if (remainder who 5 = 1) [set a who
& h1 @  N% u7 ^7 X( U3 J6 I                          set x ( 0 - Wid / 2 ) 2 A' q& J) H) C, t0 ?, q5 @
                          set y  Dep / 2 ]
0 d/ P4 B7 W- [* s  I4 h           set b  int (a / 5) * 5
+ j. j0 O, i4 S+ A6 F+ I, A    setxy ( xcor-of turtle b + x ), W) @" N# O  {2 _2 b, O
          ( ycor-of turtle b + y )
8 h" s# K, L$ d* Z4 jif (remainder who 5 = 2) [set c who. n) x/ o( n- l# ?( X- h, A3 v
                          set x ( 0 - Wid / 2 )
* N4 V6 a! x$ z3 R+ @                          set y (0 - Dep / 2 )  ]. X/ _: }, v' L1 y
                          set d int (c / 5) * 5
0 E, O1 ]3 [: j2 d   setxy   ( xcor-of turtle d + x )& i7 R3 E4 J2 L# _
           (ycor-of turtle d + y )
7 M" x( M9 f( z; k          : x" R6 p9 B! `; Z5 |6 c
            
  G: C* H; W$ R: Z; [# ^7 Rif (remainder who 5 = 3) [set k who
; E) C% T% s4 q% S( i8 H* q: E                          set x( Wid / 2)  
' n: l" y( v7 I                          set y (0 - Dep / 2 ) ]+ G% T) R$ M" }9 C& T+ V( q) `6 l
                          set f int (k / 5) * 57 H/ I6 Y4 r# t0 g
  setxy   ( xcor-of turtle f + x )8 M" H; s" j% V( x7 O5 T
           (ycor-of turtle f + y )
8 L3 Q( P3 y$ p             U) {5 w( v) ]; m! P" G
           
- O/ b# j9 [) T$ Y3 E8 Eif (remainder who 5 = 4) [set g who* I7 \+ e+ L6 s) y" k4 |/ K
                          set x Wid / 2 ' K' t, D/ }( G+ M& x: w5 x  }
                          set y  Dep / 2 ]% G3 w7 x& S& K! L
                          set h  int (g / 5) * 5
: a$ x# e# B* f: f( V+ ]' i; U  setxy   ( xcor-of turtle h + x )
9 b+ R3 u8 a* m+ w           (ycor-of turtle h + y ) + `) G+ G7 N; q8 D
                          
- ~4 B2 _4 x, D                          ) b4 U, F1 ^# }& @! `! X( c! i
                          ]
  M- @- f) J1 k' W% j9 kend# s9 v% C. b! d6 X' d* ^' N: l
6 \- l5 d6 H: R) f7 G4 `6 v. V- Z
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
% L* g! O! \% W- n9 @应该是
7 R  a% [: C# c- _) g7 ?, Z( a$ t, Fask turtles [- A, j$ j2 m& D' D  m& |4 k
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ; N, X4 M2 M. @$ T6 q
                          set y  Dep / 2 $ m+ _) x1 M8 ^/ E, c+ a
           set b  int (who / 5) * 5, z. \9 C% Y+ U  ^. g
    setxy ( xcor-of turtle b + x )
: M! E. i' _- H          ( ycor-of turtle b + y )]]
6 E2 P3 z7 D: A8 ]end) M% v5 _7 l( B$ N. j) S; n" F5 W
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-18 05:40 , Processed in 0.020286 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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