设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7281|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
7 }' L3 G" A9 F9 T8 c( Q5 n% }6 G2 w; ?/ h& n% {( r
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
2 v+ y1 A6 a3 w! |) a$ l
. `' ~) D& A$ x( d0 e2 G# V, oturtles-own [a b c d k f g h
' ~* t# v* T! y# \- ^  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
) L8 u  r( }) a+ v3 J, g  p9 s" P]# n; _7 E/ i$ y1 [3 v
to new
0 G. a7 k+ i) ~! _  ca9 m( D% o" P7 Y  a2 S
  crt 5 * num_of_building
7 w) A' z) P# ~  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
! v. y5 L/ C9 n% D3 Y  scatter     ;;keep center-turtle random positions
4 ?4 L; V  |( Y8 r2 L  unit_plan   ;;make up the building plan3 F2 D) w2 o* B! ~. e, X
end
, F& W3 L  {; c- a/ tto scatter$ v, L! m$ b# I4 c
ask turtles with [remainder who 5 = 0]
5 z, H" E, u$ G3 r[
' w, }1 w! W) B: v" Zset xcor xcor - 6 + random-float 15  o5 [7 S; ?+ l, I/ |) Z$ b, w) P% n
set ycor ycor - 6 + random-float 15! }0 E' ^# G/ D8 J
]
" o& g! U. h, w( ~: |6 ^end' E, A$ j$ U3 w" u5 `0 O
to unit_plan
! L& i  _4 d0 ~/ Zask turtles [
' ]  C- h, Z' u9 C+ K/ wif (remainder who 5 = 1) [set a who
; q5 j/ ]- _( m" _* w. T9 y3 t7 Q                          set x ( 0 - Wid / 2 )
- n- j) I; u- i+ X5 P, e                          set y  Dep / 2 ]- P2 j9 e3 u; B) n$ {. O
           set b  int (a / 5) * 5
4 g  m. Q; B- Z    setxy ( xcor-of turtle b + x ), }# [2 O' }5 S
          ( ycor-of turtle b + y )$ z' Y. J  i3 J
if (remainder who 5 = 2) [set c who2 r# Z2 {1 q" T. o; n( f
                          set x ( 0 - Wid / 2 ) " I/ }0 V/ ]& @6 g' _/ J0 l
                          set y (0 - Dep / 2 )  ]
  g* G! b- r( g  D) u                          set d int (c / 5) * 5
: g. H1 d, e0 k! T7 G2 W- R2 f   setxy   ( xcor-of turtle d + x )
* W& @3 N% j8 l# v! q: v7 T7 x           (ycor-of turtle d + y )
/ Q! Z  t3 e: |- `         
/ ~: K9 b' c+ G7 [% W/ [: O, @            0 ^9 l2 _( B; b" d  p! U. k2 [
if (remainder who 5 = 3) [set k who
1 v8 }$ q( k* N; f, I$ e                          set x( Wid / 2)  * [2 i, Q( U1 ^2 ^) U. S: v0 g$ @
                          set y (0 - Dep / 2 ) ]
7 n$ {+ s7 m* S2 Q* P) M0 d                          set f int (k / 5) * 5- c0 ?4 f; v9 v* {* }
  setxy   ( xcor-of turtle f + x )& J5 g- {' E# h, p
           (ycor-of turtle f + y ) 7 z! m+ @' h+ X" N
           / o0 v- p3 f( B5 _
           5 V5 N9 ^  r+ q, t* ^( Z+ \  p
if (remainder who 5 = 4) [set g who
6 z1 Y- D+ |+ A1 ?5 {) \! r, ~                          set x Wid / 2
5 L* {9 K- {, O" [                          set y  Dep / 2 ]
0 ~- |. ]+ }3 J                          set h  int (g / 5) * 5
" q3 ]9 \: z: f$ g) l3 v& p  setxy   ( xcor-of turtle h + x )5 S; \' a% i5 D3 H, Y
           (ycor-of turtle h + y ) ( b4 ^( G; W+ u) `3 N
                          9 y/ `* L( b: w% `. `1 P
                          
  |* _& m' M" ?                          ]
  h; V* w4 g7 C2 k" s; g% t2 }3 {  Dend
% b4 Q$ H( Q  L/ R
9 e, F5 {3 w: l! p[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,. K! |6 q, r, H1 N1 y1 y
应该是+ f2 ~/ O) ~: T, U3 ^) S, ~- t7 n
ask turtles [
0 E2 Z5 ~+ V0 O+ I( R1 U7 }if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) % V) ^( B/ E" f1 C* J
                          set y  Dep / 2
  z) H9 X/ {+ ~+ n           set b  int (who / 5) * 5+ V+ @; o; m4 U+ E' n
    setxy ( xcor-of turtle b + x )
2 s' y5 w3 b* Q6 H- |4 y( r          ( ycor-of turtle b + y )]]
# c* D6 U. O5 \) Cend
- i* }6 a/ O' {之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-24 22:49 , Processed in 0.019921 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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