设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9149|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。6 n  B& Y! t* V6 O* M$ J" v

! Z2 J5 G5 g* _, R但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
) i1 v, l% o& a, ?' `; l. W; K7 V2 N8 P. M5 l
turtles-own [a b c d k f g h. e9 ?* R5 V( f+ o
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle / f1 U! h- ?" {! o" o( _) C- ]
]  L* M" @  q+ t/ b, y; @
to new8 B4 m1 ~% }' Q+ v8 ~
  ca
" |  j7 j& l& |  V& L  crt 5 * num_of_building
6 E5 ~  L2 w- y" D9 v; c  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
4 i* L/ [9 [; v* ?) R' Q6 `. U  scatter     ;;keep center-turtle random positions $ d$ V9 S$ S* ]- u, P# r
  unit_plan   ;;make up the building plan, c/ O0 N7 @7 D9 q2 U% l
end7 G3 k( k6 L# ?9 a) S  _: }
to scatter
9 \/ S, I, H& w$ `ask turtles with [remainder who 5 = 0]+ L3 n1 f$ Q& i
[. E& D- `4 i! S8 ]2 j+ l2 t- [+ O
set xcor xcor - 6 + random-float 15
3 t& o; `3 w' T! P0 h% l1 |0 oset ycor ycor - 6 + random-float 153 O# ^0 Y# ?5 W& `( j
]
' a" M. M) n0 b4 Q& o1 e* h# Dend
5 ?3 U7 G. F" o! w1 _) i& U- Wto unit_plan
' ^& s7 G6 n' K/ q* ]7 jask turtles [
5 G- L1 u* e4 M+ o0 M; B8 O& sif (remainder who 5 = 1) [set a who 4 ?/ N5 o  Y4 U7 \5 t( K# m7 m& e
                          set x ( 0 - Wid / 2 )
) Q/ @+ I" ?' H- a! w1 M                          set y  Dep / 2 ]
7 f" L, v! g+ g6 S4 ~# H9 a           set b  int (a / 5) * 5
$ C" f# W7 o/ _6 `    setxy ( xcor-of turtle b + x )
3 u0 X( A8 s. ~: m5 E8 B8 ]          ( ycor-of turtle b + y ); @+ a/ Q/ E* g( U$ h3 o. r
if (remainder who 5 = 2) [set c who) E: D$ f( `, u
                          set x ( 0 - Wid / 2 ) , Z9 Z/ `/ t9 b3 ^# X- J2 L* S5 c
                          set y (0 - Dep / 2 )  ]1 n- U( F# Y& V4 M4 ^% Z# h
                          set d int (c / 5) * 5% e- }1 Z: G4 u# U7 n+ d8 D% v8 }
   setxy   ( xcor-of turtle d + x )/ x, H# F7 y% ?" N. B: ?
           (ycor-of turtle d + y ) 7 E  F( @  }. ^. J1 a
         
& S1 C6 |$ N$ s            
5 E2 b6 t7 y6 W" m4 g( I8 S" \if (remainder who 5 = 3) [set k who
( \) o, `8 {; p                          set x( Wid / 2)  
+ v( w/ s6 ?+ X) s, Y" A                          set y (0 - Dep / 2 ) ]% X- L$ i1 I; ~2 Z5 f9 d0 k
                          set f int (k / 5) * 5
- L. _/ E4 C! }# p" _# g  setxy   ( xcor-of turtle f + x )5 U- Z* ?2 Q3 Y, x" C+ D
           (ycor-of turtle f + y )
5 X' d/ b6 T0 W! f4 s0 Q4 R  ?           " t8 v1 A& i- Q7 z3 m# Z
           * ?( e/ g. [1 T5 C  `1 c
if (remainder who 5 = 4) [set g who4 f5 b7 i8 j* A2 D
                          set x Wid / 2
4 ]4 u" r% O% e* J( C: m                          set y  Dep / 2 ]
0 K" j5 Z$ B- _6 \2 W& E                          set h  int (g / 5) * 5
' z0 {" o4 G: o! W" i8 [1 N( z  setxy   ( xcor-of turtle h + x )
1 F" _5 e7 d, U. f/ z" z1 o           (ycor-of turtle h + y ) / \4 ]: Y; |3 @6 Z
                          
* u6 p+ x0 f+ A$ T0 w* _                          
$ R  g, E) q  b% i                          ]
. g6 Z- z# f4 E+ t& pend
) U5 z. L* l) t7 E. L/ U* O. G- m# e) z0 `. }
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
. a+ r  I. _* |! P应该是
% S8 h4 V7 q/ E; ~4 \" ^ask turtles [) N. \2 h3 v5 X7 X& ~
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
4 b0 p1 i' R( C0 z) Z                          set y  Dep / 2 - F. [( }, e2 h  t) d
           set b  int (who / 5) * 5" M4 I( ?5 k9 _2 e; P9 [) \: B
    setxy ( xcor-of turtle b + x ). a" E- }! G/ n1 F
          ( ycor-of turtle b + y )]]
) V1 @( x* H$ _# kend: y$ u) C( w& @3 I4 B
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-22 17:00 , Processed in 0.015234 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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