设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7616|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
5 Q- h- X8 x& a: ]# M3 f3 q
+ h9 B+ V, N, a但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。" l* m1 n7 G0 N  f

' i3 G0 \2 Q+ w+ n, Bturtles-own [a b c d k f g h* Q$ s2 g; r  T: b
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 4 {  U2 o% Z9 J
]
4 t8 Q2 @+ W' h( l, ^to new
1 Y7 N, L8 e/ {  k# y& A" S  ca
# ]! @, o# K9 \  Q  U/ N4 ~  crt 5 * num_of_building: Z4 B4 q9 `5 a! j: _. y: [8 Z+ G$ P
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]  V4 ~$ E' O9 a/ c" O" @3 ^0 n- Z
  scatter     ;;keep center-turtle random positions
6 T2 G/ [0 n& P6 s  unit_plan   ;;make up the building plan* J" @8 Z# F% {& R0 z
end# e$ t1 y% g$ \- l, }! Q
to scatter
2 V2 d) K, c3 o- b, ]ask turtles with [remainder who 5 = 0]
$ y* Y, N: Z# N; X0 D, D[8 Q2 i5 w- b; F- d) c
set xcor xcor - 6 + random-float 159 d9 [9 Z, M! J: T0 R( n7 u
set ycor ycor - 6 + random-float 15
9 d5 n, h! e8 f/ [$ G]
: N: M$ Y, {( e  B- pend
! B6 g9 G+ j1 m* h) x3 k* uto unit_plan
$ x  E) I# B2 r! Aask turtles [
5 p6 s- M/ T3 [5 Uif (remainder who 5 = 1) [set a who
) F; y4 B# r1 E# R                          set x ( 0 - Wid / 2 ) : @2 U- g. Q: S+ ?9 R% R+ z9 n; m
                          set y  Dep / 2 ]
/ }: y5 p6 }  d- M5 K1 E/ {           set b  int (a / 5) * 5
! [( e% b! }5 h    setxy ( xcor-of turtle b + x )6 O, I+ c/ p- h7 B; g7 _
          ( ycor-of turtle b + y )1 k) G; u2 U& `- @
if (remainder who 5 = 2) [set c who1 N6 K# h) K* v0 I5 Y( j
                          set x ( 0 - Wid / 2 ) + B9 A: z$ W9 e( @1 c
                          set y (0 - Dep / 2 )  ]+ E; D! k& i, s% L  v" c1 d4 J$ Q
                          set d int (c / 5) * 51 H/ j$ ]5 O& v) H8 \6 j, M
   setxy   ( xcor-of turtle d + x )6 b) U: L& L1 d
           (ycor-of turtle d + y )
! M0 b* a2 l2 [( d1 I9 w         
% Q5 h+ Y( k; S1 i6 M            
8 r1 G8 L9 v% A- F) {" T/ W* `if (remainder who 5 = 3) [set k who
8 }3 q0 H0 {0 i0 i/ L3 m                          set x( Wid / 2)  
; C- W" V8 g2 ^                          set y (0 - Dep / 2 ) ]
, {3 N# H2 {. X% ], q# P                          set f int (k / 5) * 59 `" w! z; w- @( S
  setxy   ( xcor-of turtle f + x )
) o2 P( E- ~) @* H+ R1 [           (ycor-of turtle f + y ) " _2 b' _  N2 f# W
           ! e. h+ Z5 y. A! A+ }
           
: B7 h  H9 V( p# S1 _if (remainder who 5 = 4) [set g who
; p3 z- P  x8 T3 a* }4 {) _0 E                          set x Wid / 2
1 O* s3 J( Q" [                          set y  Dep / 2 ]
- r& n" v. K, W- c% L. k, v5 S                          set h  int (g / 5) * 5
1 x# [8 a3 y4 Y) V0 \' d& ?8 \. f  setxy   ( xcor-of turtle h + x )) E; I0 @  |3 |7 }' v5 F+ k
           (ycor-of turtle h + y ) 2 O2 q0 M4 O& x' ?5 N
                          ! k- M" m7 s) e, {* T4 \; W
                          
* _& y" j* b. J1 e                          ]
  b: j* R/ d' cend
/ _4 H  h- m3 W# G$ Y8 y# Y
1 X: b+ A/ ~8 f6 H& R* W[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,0 A# P( Y% F' y/ e9 c  u) S
应该是$ U8 y4 B9 x9 s
ask turtles [
' g# i" q- O, }5 }, Rif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
9 v1 q5 Z) Y5 z6 j! b* H; h1 p! C                          set y  Dep / 2 ; F/ y- W4 i4 @
           set b  int (who / 5) * 5
- p7 ~9 J" g! u0 V7 ]2 N" k9 w    setxy ( xcor-of turtle b + x )
4 ?% a" x+ C& F' J: I; ~          ( ycor-of turtle b + y )]]
7 }4 J, d# L* y0 nend5 A, m' V) e$ O% Q. B  b$ k
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-6 00:34 , Processed in 0.014907 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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