设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7307|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。) u! o& Z' ~4 p: z1 V5 c, [- Z
. m) e# T, w6 P
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
) k! L  I, q* V' d; @! w3 {: b! R
turtles-own [a b c d k f g h$ E/ X* A8 t5 }% ]
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
7 i9 r9 g, E9 ^: V3 C  |- |]8 T  E& Q) f4 M& M3 @
to new
4 x2 a9 H1 Y5 L  e# J' i. }/ V  ca
( R8 O8 e, K! P; C& |  D  crt 5 * num_of_building
: t8 r$ U+ E8 ]/ v  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
/ Z1 r, b2 G$ j; j  scatter     ;;keep center-turtle random positions - \' o; i5 l. ^
  unit_plan   ;;make up the building plan6 V/ w9 j6 H% e
end
3 K& x' y& d) ito scatter3 y$ A, B' ]3 q$ F; i1 B! F  S
ask turtles with [remainder who 5 = 0]
! b6 N  x7 m$ @% e/ _[
7 C8 o+ Z2 ]5 R: M; hset xcor xcor - 6 + random-float 15
( y3 o+ e2 }- t+ H0 \set ycor ycor - 6 + random-float 15
* F8 w# J$ A3 Q$ c* o9 S]
2 K" W/ a6 K9 P* v' M- a* Bend
7 W& H$ q9 B; m* ]to unit_plan
- d* g7 \* N$ f$ T  mask turtles [
+ a/ C6 i) I2 u, T; m0 }7 j2 Wif (remainder who 5 = 1) [set a who   V3 r' N' Y4 B# y
                          set x ( 0 - Wid / 2 ) 6 e& K7 S/ o* H6 B3 ]$ f4 L
                          set y  Dep / 2 ]( D7 p% y0 N9 f* f4 x8 O; I
           set b  int (a / 5) * 5
8 |% i( y' J/ e0 C2 k9 X* F1 f    setxy ( xcor-of turtle b + x )/ ?  ]( I/ S  ?% r9 \* n
          ( ycor-of turtle b + y )$ M- q. M9 w: s& p: J5 f8 q
if (remainder who 5 = 2) [set c who
$ T3 n7 T+ j, h                          set x ( 0 - Wid / 2 )
( K3 I3 Q) J# D% o4 L                          set y (0 - Dep / 2 )  ]
7 m- F! W5 R1 @% b                          set d int (c / 5) * 5/ Z! y  {  f0 u( ~$ t
   setxy   ( xcor-of turtle d + x )
# \  v; J# W. |& Y  S           (ycor-of turtle d + y ) : n$ J9 f2 U- C
          " U5 B: d* ~1 d3 C
            ; `- i+ S1 f" N& g& J( B
if (remainder who 5 = 3) [set k who
  t9 F( \( [9 _* [" y0 |                          set x( Wid / 2)  ' x! b6 J* M6 q" \* Q
                          set y (0 - Dep / 2 ) ]
1 g: b4 }1 J2 Q9 x                          set f int (k / 5) * 56 L, d4 m. O+ V3 u
  setxy   ( xcor-of turtle f + x )0 B  W3 {3 ^& c9 k( ~8 ^
           (ycor-of turtle f + y )
( P2 V3 Z5 ]) s8 J5 E           
6 _$ e% d  b" s7 z           
/ G( H: \# C( ^: bif (remainder who 5 = 4) [set g who
& W2 }. q5 o, T9 o% \/ B* k( V                          set x Wid / 2 ; l* ~# u1 V+ F. P% C% @" t
                          set y  Dep / 2 ]* X) R* \' g0 v, {2 r6 k0 b
                          set h  int (g / 5) * 56 W* x# E4 P2 F2 r: {
  setxy   ( xcor-of turtle h + x )9 @  s8 }5 i8 v, g, P9 x! A
           (ycor-of turtle h + y )
  w' r& @" k! u0 z) I& B+ @                          
0 R0 v$ n7 t1 I) }9 _                          7 _1 _  w% f: f8 V
                          ]
5 b$ T" t9 |. O6 s. u9 h- Iend
( s& _0 _& q; Z7 W# w% C* e; ^
, d' m: c7 t, m1 X[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,* u. M5 _+ [! d" n+ ^3 p' u2 @) @
应该是7 j+ N2 B. _7 h2 d
ask turtles [
7 n$ F1 e! T  e% l6 D0 L+ Dif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
( z/ Z6 ]! @5 h' `/ C                          set y  Dep / 2
+ o* R- I& J6 p8 B3 x( f           set b  int (who / 5) * 50 F4 ~7 H) h6 m0 L; A& Y
    setxy ( xcor-of turtle b + x )
' a% s5 m' {+ B" w          ( ycor-of turtle b + y )]]' m/ f+ J9 {4 Y. y7 P# `
end! Q' y+ \0 v, r* x7 j9 b) t/ h- ~; D6 J* p
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-27 21:15 , Processed in 0.015774 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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