设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8449|回复: 1

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

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

7 I4 X+ B1 Y' ?' l但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。' n- o/ p, D: p% k6 z1 G1 m

1 u8 Q/ d3 s3 O& F; `turtles-own [a b c d k f g h. Q4 j+ S: H8 c5 ?( S; @9 I$ v
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
% S0 ~1 r9 x( G! N- G# L]
5 ~) w: `+ g; w, m  \/ ?8 b+ Uto new7 d2 a- z8 e4 Q/ G
  ca
( R) q) A$ u3 e+ ]- A3 R  [# K  crt 5 * num_of_building
" V1 Y) l4 y$ R- ^! q! w  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]3 V" b! S" n  t# a% n8 o/ m
  scatter     ;;keep center-turtle random positions ( j3 S$ `: D* ^) B& Y! @
  unit_plan   ;;make up the building plan
- C' L# y; p0 k. N" U: oend
/ h! R. s7 @$ @' h; P- Qto scatter9 Y$ i) s8 s6 B; ~
ask turtles with [remainder who 5 = 0]
( y# q* A8 _" _: u" F) U5 P[
# }. L9 c8 c1 k" V% H8 Q1 E/ sset xcor xcor - 6 + random-float 15
: q% c- h; a/ e# }; E8 j5 hset ycor ycor - 6 + random-float 15+ n( X8 W9 o, D0 \
]
% s$ z& F: _, @6 Q" Eend
# [) T& P$ W2 c* O, r$ fto unit_plan 5 ^9 g$ \8 R. G% h  a2 C' D" I% E
ask turtles [( O7 k( z- E" W0 Y  w8 ^5 E% l
if (remainder who 5 = 1) [set a who ( \  l0 {  `# R
                          set x ( 0 - Wid / 2 )
8 R' P. ]5 g: w$ f, B( g. _& \                          set y  Dep / 2 ]
& A0 P8 e" P: z           set b  int (a / 5) * 5
+ h( R0 B0 @: h& M9 s    setxy ( xcor-of turtle b + x )9 e+ c. ?7 f! ?2 z2 x' K( g
          ( ycor-of turtle b + y )  I; k% m; t+ N4 a
if (remainder who 5 = 2) [set c who  V$ G1 U) ?* ?
                          set x ( 0 - Wid / 2 ) : {  B& C; k- d9 d( l  c
                          set y (0 - Dep / 2 )  ]
: s- e+ g: M# c                          set d int (c / 5) * 5# _3 ^! j+ B; J; ]  O
   setxy   ( xcor-of turtle d + x )$ N" |5 p) }5 N' x5 g
           (ycor-of turtle d + y )
2 K: C1 q1 Z7 p( m          : ?7 Z% }) S' a. Z
            
) T5 u$ `: u2 C9 E& Z, Bif (remainder who 5 = 3) [set k who
( Q8 @2 p" S( @- x                          set x( Wid / 2)  - |9 z5 ]) V+ K  N- [& w
                          set y (0 - Dep / 2 ) ]# I" y' x: T) x+ Z: ]% A
                          set f int (k / 5) * 55 s/ r1 ]: C6 e3 F$ G; Z
  setxy   ( xcor-of turtle f + x )
: O) Y4 o6 Y% x% Q- J           (ycor-of turtle f + y )
5 f* \: W( ]) A$ b( |           
- j% e+ n* w1 _( s. K6 X1 V7 h           4 X5 [! B2 C; Y/ K
if (remainder who 5 = 4) [set g who
6 V4 a! `+ @7 i9 r                          set x Wid / 2 , a' V; Z1 w+ b" ]; P9 X
                          set y  Dep / 2 ]
. w. {- C" D, P; Y& S                          set h  int (g / 5) * 5
" F6 [# \8 V% Q' X* q  setxy   ( xcor-of turtle h + x )
6 E: p1 C* Q7 i8 C0 |0 K4 b% f9 X: X           (ycor-of turtle h + y )
% h, M7 ^& {4 j) _- I; J/ W3 R                          5 k+ D/ A* L1 D
                          2 u7 Y7 H8 @/ P$ d
                          ]
+ x) a% }5 y3 e, H. G8 d& mend6 u+ q( d. [! s

/ ~2 _$ Y; v* e% ?, u) b! `2 C[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
5 I  g. K- x' N. ~% m; x应该是
1 V9 ^% `- L/ I# @; Iask turtles [5 y' o; j1 v$ W
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) - f7 W3 K2 b: s0 R! y, t* B3 j
                          set y  Dep / 2
, r9 e1 v, X6 o* F% ~/ V7 e" ^           set b  int (who / 5) * 5
8 e/ v1 w8 z, F  i- [    setxy ( xcor-of turtle b + x )  O/ l$ n, G. k2 n# C! s
          ( ycor-of turtle b + y )]]
7 O) K* ]8 a: o" k( @3 ?4 \end7 l: |( H1 l! X2 d; E
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-27 16:40 , Processed in 0.014353 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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