设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7841|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
8 I: g& C# E3 T9 S+ N: |
3 W4 j: d' S: N$ N但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
& P3 M& b0 j. V" S" K2 I6 m" L. I; `
turtles-own [a b c d k f g h
* W( G4 O: m$ J- O& c6 G  x y     ;; these are the leaf-turtle's offsets relative to center-turtle - X' a6 F! x/ E5 G- X. v$ W, ?
]
) k- B6 J4 n3 V6 T; J# p) ]" fto new9 x% H2 T4 n5 d% ^& z& r( R
  ca
0 ]% T3 \* b, [3 c( K  crt 5 * num_of_building
: c  |% w4 W* I# Z3 U5 K- {" t  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
( i# }, S7 B6 Q4 Y  scatter     ;;keep center-turtle random positions / z4 z8 ]2 A/ R: |
  unit_plan   ;;make up the building plan
$ G* E7 j8 A% }- iend
: \' m- ?  z5 M) [* T. @9 Ato scatter. k1 {8 k8 e; b/ r4 b& g1 d& w
ask turtles with [remainder who 5 = 0]
1 h& |) g2 Y. S! {3 \! J[
% |* B/ L, i8 T2 n4 v# c# Vset xcor xcor - 6 + random-float 15
* x, Z# W" v" N2 B6 I3 r2 wset ycor ycor - 6 + random-float 151 A" N" O/ v. e# [: `  M
]
4 R  \- X' k5 I) S" Eend
( U7 k2 a7 t# b& a# N2 dto unit_plan : e2 n! F/ N9 Q* O6 r
ask turtles [. y* p- ]2 X' T8 h- r
if (remainder who 5 = 1) [set a who
6 u0 Y9 Y$ {. e' q  i                          set x ( 0 - Wid / 2 ) - N$ L. u2 @, k" y
                          set y  Dep / 2 ]) \  S9 S3 V/ y$ d
           set b  int (a / 5) * 5
: x7 Y: A6 r* e4 T4 ~8 V    setxy ( xcor-of turtle b + x )0 G) b: i  G! T( M/ H8 U
          ( ycor-of turtle b + y )
' b! E/ e% b; t1 y& m5 W" \0 wif (remainder who 5 = 2) [set c who0 ?5 n/ m+ ~5 n/ l
                          set x ( 0 - Wid / 2 )
0 m0 a( H( F& r! a. V                          set y (0 - Dep / 2 )  ]
. u$ @) ^2 U# N/ R9 A                          set d int (c / 5) * 5# P' H) m; H" }1 a) Z" n
   setxy   ( xcor-of turtle d + x )( g+ k  E' L4 k& ^1 n; T
           (ycor-of turtle d + y )
, S+ @( y  L8 c1 W# s         
& K, v% ]: D+ h            0 M& P: b! R) G& f
if (remainder who 5 = 3) [set k who9 w% C, E* I8 T. M
                          set x( Wid / 2)  
  s9 }6 ?  f0 |6 D# f0 c( l                          set y (0 - Dep / 2 ) ]
6 \+ [! O$ I4 Z8 V                          set f int (k / 5) * 5  q  e' H. g" E& K  _
  setxy   ( xcor-of turtle f + x )
# w" z. w9 L2 _4 Q2 q& Z3 Y           (ycor-of turtle f + y ) / R* ]- r2 P7 M- W! i
             q$ @- J$ {6 ?$ W+ ~
           8 k* [/ a. D6 X* ?- H
if (remainder who 5 = 4) [set g who
, N2 Y+ ^8 `  m( C" T                          set x Wid / 2
& `6 A' {$ P2 `                          set y  Dep / 2 ]/ c( A  l" E$ [- P7 j4 }: {
                          set h  int (g / 5) * 5% x2 a9 L9 e) Q6 B5 S
  setxy   ( xcor-of turtle h + x )
! `5 d6 x; q5 J/ e; {7 g2 Z           (ycor-of turtle h + y )
4 B; h, o( f: D6 n! D* @                          
* t1 ^# Q8 k9 @, s" E: K1 }                          / T3 F1 e8 J! M6 y" X
                          ]. F9 k& O& A% v. r/ s& T
end6 O- b: \3 }$ _  a/ u  q+ l- K9 Z

1 u5 F, Z& B4 R[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,0 G) U$ L% N2 B) K. U  V% g
应该是. a: _& u+ K1 x. y5 ^
ask turtles [
4 ^( H5 `5 R0 P# n3 `' i3 Jif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
4 l# H% p3 Z* D% q# z                          set y  Dep / 2
, x2 h: k/ w2 @- O, D. M% l( ~" T& E           set b  int (who / 5) * 5& g# O' _- O, h! L* {( F9 e0 t
    setxy ( xcor-of turtle b + x )
. ]. y6 T7 f1 t9 C1 \6 q          ( ycor-of turtle b + y )]]
: C6 e/ o6 P+ u$ S% ]1 J* h; f+ j& vend
/ w2 ^" \2 B7 E# L之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-8 04:57 , Processed in 0.024383 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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