设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7811|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
) T% s) L$ R) a/ K. J: C' y! D* A) h8 |  o
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
* Q; k+ e. R+ W) S+ G, A( z
& ]$ V# g! @! pturtles-own [a b c d k f g h; X. a4 K. O- U1 b
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ) v2 O- F% x' i4 _& _0 T9 w/ h
]/ B# U# Y- H' i; P/ n' O
to new; @" l0 c- @) E8 ]7 q' _" R4 w
  ca
" r/ p+ V2 t" s4 k  crt 5 * num_of_building6 M1 [' E3 ^) Z7 S
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
1 H) m0 ]7 h) n5 y2 b; D) a( B  scatter     ;;keep center-turtle random positions & [+ g# D6 H6 G' j5 s& Q9 l
  unit_plan   ;;make up the building plan
# [' ~1 H' j( {2 }8 k& g* N- z6 l1 \end7 ?6 D( O* m3 O: |
to scatter* v' ^7 M( j( o9 M3 O
ask turtles with [remainder who 5 = 0]. f0 S6 n5 G; X0 z0 K
[: Y1 v5 E) @3 f" ~  U6 p5 G
set xcor xcor - 6 + random-float 15* p/ h4 G$ \, k5 P9 X# \
set ycor ycor - 6 + random-float 153 f! U5 K. \8 j$ R
]
! f8 A  o* `. hend5 E, \5 |! {6 ^
to unit_plan
3 k* q2 b2 d5 z/ g* l3 eask turtles [
/ G; l; o& t2 B4 B- a& i7 dif (remainder who 5 = 1) [set a who & h" j6 @. l7 e: u# W( e. j( `
                          set x ( 0 - Wid / 2 ) : a2 |( f  K+ a/ n& z* d* n& j
                          set y  Dep / 2 ]
5 G- ^  W$ s" y6 I           set b  int (a / 5) * 5+ B7 D5 p) r# _! K8 n( m8 l4 q
    setxy ( xcor-of turtle b + x )
( m3 G9 I% S9 ?6 H( u          ( ycor-of turtle b + y )  ]* A$ ~2 W# m9 E
if (remainder who 5 = 2) [set c who5 c$ i2 q7 q8 [4 \3 ?# j9 N
                          set x ( 0 - Wid / 2 )
2 l; C( V1 r# ~, q) R! C! U; c                          set y (0 - Dep / 2 )  ]' y; s1 o5 `3 z5 @3 D( b# P
                          set d int (c / 5) * 5% l1 r, s" P2 Q
   setxy   ( xcor-of turtle d + x )
4 q+ D4 R/ x" @3 m, _+ ~           (ycor-of turtle d + y ) 4 j* J! T; g: v1 B; h8 L* w
         
: G+ ]- Z3 o1 n. K% H7 [            
( Z8 ?4 h7 g) `9 }4 Sif (remainder who 5 = 3) [set k who
  f2 f! A% b# n, o* L                          set x( Wid / 2)  
; y) S) q: u- Z* ^0 ?/ f                          set y (0 - Dep / 2 ) ]
; D$ W  k! g3 V$ {4 u                          set f int (k / 5) * 5
, g: ]/ v( E' d2 r& c5 N! v  setxy   ( xcor-of turtle f + x )0 r" `/ Q4 H3 M
           (ycor-of turtle f + y ) $ s9 x+ @& i( @3 L
           0 Q6 x/ {, D7 n& {: S! Q3 n
           
$ U( [/ W- Q4 |3 p) e' F8 Zif (remainder who 5 = 4) [set g who
8 N  l; W' l! u& c9 k% {( N2 q                          set x Wid / 2 # ?+ W3 w, y! s# A) I/ }
                          set y  Dep / 2 ]3 w/ V3 `7 Z3 b: r( B( J1 H+ o
                          set h  int (g / 5) * 5
9 z+ W: k2 w, X4 S7 }+ T( X, X  setxy   ( xcor-of turtle h + x )1 n- m9 P& b0 s/ i8 z# h
           (ycor-of turtle h + y ) 0 h' @- ]. j# Y
                          9 o2 `, w. q/ o% X% h
                            A: Z7 _+ ]2 e, Z# q- P
                          ]
2 J- r! U6 T. i2 _9 Send
  \. I. y# d& Q8 V; y" g$ e1 f6 s$ T2 J0 k. D  u: v. K! E
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
5 c/ h# s! w0 u5 Q* e应该是
- c0 w4 r" @0 Y  \# Zask turtles [# S8 r1 d# j: D
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
# A, o! c' j+ C- x8 o6 ?/ S! B                          set y  Dep / 2 " e( T. N/ v/ Z  j5 l. L, N7 ~3 m
           set b  int (who / 5) * 5! E2 l, S  R$ x6 v3 n' q
    setxy ( xcor-of turtle b + x )3 n8 {9 `3 S0 E
          ( ycor-of turtle b + y )]]
+ _+ s2 \; o; y: t8 s1 u; o! dend( {7 G, a0 m. ~, P
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-4 14:10 , Processed in 0.018912 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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