设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9136|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。5 i; I: P1 T$ W  Q  ?

/ D0 }; b- R( K" I2 i  {但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。3 B" M2 g, _) Q+ D

, V. E. d3 y! xturtles-own [a b c d k f g h7 c; ]: s# v) e$ s/ c: n# H
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle * U- _* ^3 a) A: B- {" |3 H  f" ~
]1 A; b4 U1 Y3 L4 Q* D& ^6 W, y
to new
/ K! Y- ]$ i& {* E' R5 H- _  ca7 P9 h* e5 b+ {3 E) B" F, W1 |
  crt 5 * num_of_building
: ?0 B& T; s6 W: N" \  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
/ r: B, z5 `) W# z- y. V, f  scatter     ;;keep center-turtle random positions + X1 C: o$ }3 D' p- z, F
  unit_plan   ;;make up the building plan% [$ C3 e; ^  n  b5 H
end
4 e) m  G! r& t, Tto scatter
$ t4 Z3 n2 Q  a" S/ Hask turtles with [remainder who 5 = 0]
& X1 Z4 y( P& O[# D& K6 ?4 l5 Y* f6 P% A
set xcor xcor - 6 + random-float 15
! _/ ^1 S  }3 t( h* u7 n$ Vset ycor ycor - 6 + random-float 154 y- M* W. O  I" W, A& |) T+ G4 r
]: U* \1 d* ~1 `% S3 E
end
+ }( V% Q# A  h9 @4 K3 Cto unit_plan
/ Y8 r! s4 D+ Y' y0 I  v4 K& N9 Sask turtles [
$ E6 _" Q1 c, _" oif (remainder who 5 = 1) [set a who ) u; t& P( l4 Q; P
                          set x ( 0 - Wid / 2 ) # w  o6 N6 g1 V4 M
                          set y  Dep / 2 ]
9 i( P0 ]8 b/ [3 k, _& I% ^           set b  int (a / 5) * 5$ M1 \4 I' Q, q1 w7 ?/ ?$ s/ J
    setxy ( xcor-of turtle b + x ): g0 ]2 k: X# `0 L6 }
          ( ycor-of turtle b + y )
" S7 T2 p* k' Y- k  J5 p) qif (remainder who 5 = 2) [set c who
" V& }* G& O$ u( l. D                          set x ( 0 - Wid / 2 )
9 z8 T# J# }0 t                          set y (0 - Dep / 2 )  ]- `; Z. e2 [; I- T7 a
                          set d int (c / 5) * 59 v4 i& Y; E6 A
   setxy   ( xcor-of turtle d + x )
, q% I5 G3 _- k+ B) s           (ycor-of turtle d + y ) ( {; u$ Q+ T3 S) L
         
' \0 A5 n9 Z8 \/ k1 f            
( U7 q) g) C! q0 x4 F$ pif (remainder who 5 = 3) [set k who
- J" _+ p: c- j) ]                          set x( Wid / 2)  
$ l' f6 ~3 ~  c9 |; w" W9 f                          set y (0 - Dep / 2 ) ]' e! J1 `& b8 \" P
                          set f int (k / 5) * 55 o" C; N/ [, I+ |& ?
  setxy   ( xcor-of turtle f + x )) V  {% {& c0 [# l0 v+ }
           (ycor-of turtle f + y ) ) B4 h5 W. u- Q- \
           
3 I9 B1 K1 z- l2 _6 }! S           
* l9 Y4 d* w* h1 u% \! l  N- W! eif (remainder who 5 = 4) [set g who
1 J/ s6 \+ n9 o1 q  }                          set x Wid / 2
/ r6 {6 q1 ?( L: X! ^% f  |5 H                          set y  Dep / 2 ]2 s, x  L1 @2 o5 @
                          set h  int (g / 5) * 5
, m) O* \7 @8 B0 ~& v# Z* J# g  setxy   ( xcor-of turtle h + x )
1 ~  ]/ T# S6 ]0 P; H$ ?8 O* ?: d           (ycor-of turtle h + y )
$ N8 m( S% E  e- i7 G* @; K                          
* I* {3 T% _7 W; V. U                          ; S& i& w- i0 y4 B! V; [% [
                          ]7 |" ~% N% {7 {
end
1 S6 b0 i. p( V
% D! v3 ^1 `) x  |$ H: Y[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
2 {8 z+ K( J1 Z: C8 d/ p应该是; r$ @! b6 ~- w
ask turtles [
2 `/ h0 T3 O) Pif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ) P( k* K5 \1 ]
                          set y  Dep / 2 / t& R# U, u) R+ R' ?+ b' R* E
           set b  int (who / 5) * 52 I0 @3 `1 X- C7 |8 M) T+ i- v
    setxy ( xcor-of turtle b + x ), q% a2 O( o. j$ K6 I
          ( ycor-of turtle b + y )]]% @% v7 x' @2 O: _8 g  ]5 \
end
% V' K; E( x, e之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-21 14:47 , Processed in 0.015111 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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