设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7147|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。1 _9 m" P6 S9 E/ y
: Z' B7 W6 C! I% }3 O9 p
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
* Q; S- r- D/ f7 r. z+ f2 f
% E# T4 E! [5 z- @5 X3 x- zturtles-own [a b c d k f g h
7 X- z+ K# z, j) n; |5 b" p0 Q/ M  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
# D! q6 I5 G; j/ }" {/ b]' ~3 `' p# B5 w; Z  W
to new
( @0 B8 g! n5 L) @# @  ca4 v+ Q3 `0 p, R3 I" ]
  crt 5 * num_of_building
6 w: `4 o, ]# e; T& ?  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
" k5 X; P  o% ^& F4 U. r4 n" J  scatter     ;;keep center-turtle random positions : W0 \2 g7 |; Q# \7 U8 {
  unit_plan   ;;make up the building plan
' v7 S) T. f9 x2 q+ d. b6 mend: B& w/ t! r. x/ H) T
to scatter
2 {4 a, k7 ?" s5 c" t6 Cask turtles with [remainder who 5 = 0]
( T. Q% ?8 G8 f& B[
$ g* N% P! B& z; V8 c+ qset xcor xcor - 6 + random-float 15" L' y+ e9 x  p+ Z' H7 m0 |9 c" w
set ycor ycor - 6 + random-float 15
9 S& T  c5 k. V# e, l]
2 q$ ]5 z7 Z6 H$ F8 M% [end6 t5 Z/ N4 J. @1 L1 T
to unit_plan 7 U3 Y  a8 S0 ]9 r7 l0 G1 S
ask turtles [  A9 y; c1 M8 E3 U
if (remainder who 5 = 1) [set a who $ e2 |7 I5 [, X7 u( C
                          set x ( 0 - Wid / 2 ) " _$ u1 R+ C( b$ {) K3 A7 x# P
                          set y  Dep / 2 ]4 U/ H8 w8 R& U5 V" u6 S6 `
           set b  int (a / 5) * 57 j* D1 Q% G" r7 Z/ p3 `! ]
    setxy ( xcor-of turtle b + x )) N0 c  `8 D# n9 \5 T- L
          ( ycor-of turtle b + y )
( C: P5 ]6 l" j3 X% L2 ]if (remainder who 5 = 2) [set c who* H3 ]) Z, v) [# P
                          set x ( 0 - Wid / 2 ) & g/ d! y4 {; ~/ Q7 [1 Y
                          set y (0 - Dep / 2 )  ]
9 `9 A6 T; G. Z6 ~6 t                          set d int (c / 5) * 5
: D% v0 N8 h/ U% J5 |   setxy   ( xcor-of turtle d + x )
0 m" x) _" T: h9 ~           (ycor-of turtle d + y ) 2 x) u( w& L0 x# I; {
         
& L. y8 N$ H6 V. ~6 g( Q- a/ {! A+ B            
/ y1 ~3 |! F- S, Qif (remainder who 5 = 3) [set k who
% H: _# T+ m% f1 r' c                          set x( Wid / 2)  
) {9 s4 L' T9 H- k2 E( C$ X                          set y (0 - Dep / 2 ) ]9 l9 ]2 s1 T; y2 T) q1 r& u* ~
                          set f int (k / 5) * 5
% y& H5 [4 i& [& p6 S! n+ i7 ~" c6 u0 n# x  setxy   ( xcor-of turtle f + x )$ F$ Y' p$ ?  Z
           (ycor-of turtle f + y ) 6 E( c2 }0 E8 O: Q9 {
           $ m, R( c' O$ X
           ' C. i  P+ P, `* ^9 B8 h
if (remainder who 5 = 4) [set g who  J. m/ {- R$ V8 M
                          set x Wid / 2 + n4 J  G. y* k. C( ~
                          set y  Dep / 2 ]5 B  p4 g0 h) n5 ]1 b9 i* f
                          set h  int (g / 5) * 5+ p8 ?# h% j+ L
  setxy   ( xcor-of turtle h + x )
# U* E9 _/ g! U7 G. U3 c           (ycor-of turtle h + y ) ! ?( E2 t1 \; E! ]
                          , Q& Q) H7 K9 E+ @+ i1 F' E
                            T- ]( E; F# x& P# {
                          ]
3 m& H. |2 Q. p  bend
/ \" r4 G0 {2 ]4 j1 R% r' E( ^5 M7 j+ e. j" Q. |7 l& }
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,& u, ~, u8 S% U( j" i1 {
应该是6 ?6 G$ A  [: e% v- i( v. z4 o
ask turtles [
/ [1 @% `, l) j5 Zif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 1 _9 ]$ R" D' Q+ v9 E* I# u
                          set y  Dep / 2 * Y4 i: j+ O* E
           set b  int (who / 5) * 5  l* u; d9 |2 w" f
    setxy ( xcor-of turtle b + x )
. N+ G7 |0 R/ K* A* n- i1 R          ( ycor-of turtle b + y )]]* F, R# S9 D5 `, N1 s
end# F) }7 @9 P0 l; I4 p! w
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-5 17:02 , Processed in 0.017801 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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