设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7658|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。+ [! W8 h6 m# L
/ x7 |% C* B+ z+ ?, z
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
6 T% ]* s7 U  A4 a( p# X0 j4 R. C9 h1 F) w8 j+ s( T
turtles-own [a b c d k f g h6 {7 X* o# Q9 q5 v. U" w$ Z- E. R
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
& s& b. n; J) B1 x1 K, ?# z8 T]
  Y7 n, w! H& f" Q6 Vto new
; R; Q$ }$ L, R9 T) b  ca8 }. @( x9 [, e, S9 ^6 l0 T1 ]/ p0 v
  crt 5 * num_of_building
- o# w" e& R) t& p) ~; B0 f1 _  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]' _6 R4 `9 ?5 w$ Q3 t) p
  scatter     ;;keep center-turtle random positions
7 e4 F) I2 @& P- r. _9 B  unit_plan   ;;make up the building plan
1 C# ^- a+ q5 N8 Y* m9 Bend
" ~, H# l+ e8 S3 ^6 a) K/ G' zto scatter
9 y/ y3 N. T: G9 V5 J: S) Bask turtles with [remainder who 5 = 0]( U2 N0 {; Q0 Z  W/ R
[
, `1 M, v; v7 q; A8 tset xcor xcor - 6 + random-float 15) a; e' p0 I/ N5 `8 [8 X( y
set ycor ycor - 6 + random-float 15: O: V' w) W0 B
]
) \0 B/ c' F' y$ p* f6 G7 Zend
! E1 p# `  D4 y* F, B9 z* Kto unit_plan
) ]! s5 r) X7 w% r; g% cask turtles [
) w2 F  D* Z6 R) Lif (remainder who 5 = 1) [set a who
! Y1 z6 s- A3 u                          set x ( 0 - Wid / 2 ) , v# @9 p3 r) @; |
                          set y  Dep / 2 ]& [1 p6 j2 c/ Z& L0 A
           set b  int (a / 5) * 5- s9 c* j9 `" U
    setxy ( xcor-of turtle b + x )" C. Q  ^6 ^2 p
          ( ycor-of turtle b + y )9 p5 x( k8 Q9 \. R
if (remainder who 5 = 2) [set c who
) O0 |! ?. g# f2 B: I                          set x ( 0 - Wid / 2 )
+ l4 f4 {4 i5 |1 B" ~) x& v                          set y (0 - Dep / 2 )  ]
# i# o$ k- R% y4 v; v% o                          set d int (c / 5) * 5
7 o# G$ A$ t) n0 T+ z: q   setxy   ( xcor-of turtle d + x )* {# T' A2 g2 M& V$ \0 P& i! P* w
           (ycor-of turtle d + y )
4 V5 Q5 [3 v' S; F& g! B          - ~7 ]3 }, L1 R! a- z) U) `  P7 w
            8 p4 A: J7 g7 p: _; ]! A
if (remainder who 5 = 3) [set k who3 \) ]' k$ C9 f6 q# _* o: t3 F
                          set x( Wid / 2)  
2 t/ L  J, u8 H                          set y (0 - Dep / 2 ) ]
# c' ?: h( b: w) Y2 }2 E                          set f int (k / 5) * 5
- i7 S& o8 \) x. \8 l  setxy   ( xcor-of turtle f + x )* o. C7 M; N9 E9 a% Y
           (ycor-of turtle f + y )
, _8 Y+ F9 F# _4 U4 ?6 |9 R           
, `, s) `( [. e& e           
; n$ M1 A& R; j4 Y8 qif (remainder who 5 = 4) [set g who8 e0 ^1 t5 `) I  r) L; k; q
                          set x Wid / 2
9 y' Z0 h) e1 p6 G) V+ r7 N                          set y  Dep / 2 ]5 L4 I8 n3 O* f6 E
                          set h  int (g / 5) * 5
6 A& q% u) g( ?9 @9 `% _9 M  setxy   ( xcor-of turtle h + x )6 |& E* w& E5 c7 Q. \1 t; V
           (ycor-of turtle h + y )
* |, Z7 p& d2 _( L: Q3 s/ P, i                          / B/ H+ h. h+ n9 d' {7 R: Y5 Q
                          3 {7 D; [0 h5 q8 U+ E
                          ]* Q0 B! B! L  s
end& N5 K# L# ]! `! G/ j$ J

1 F7 a$ K2 u1 o9 B' o/ t1 v[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,7 d: }; M4 U4 L* V4 h
应该是% L; H1 E% c) L4 }" x; ~& Q' B
ask turtles [' |! w9 L" }" X$ C" P& m9 M2 o+ y
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ' d6 F, b2 H' A1 ~  a; [# m
                          set y  Dep / 2 / F- [/ e) W3 w
           set b  int (who / 5) * 5' h% J; L% Z4 G' N& Z$ l
    setxy ( xcor-of turtle b + x )
5 P, w; u3 P+ H8 v4 }7 C2 ^          ( ycor-of turtle b + y )]]
) D* T  c1 P0 K8 K- e4 y# m7 vend
- l) u6 Q) j/ ?  {" p# D之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-12 13:30 , Processed in 0.013273 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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