|
|
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
2 O$ j1 r" p. m0 G9 h$ X% F. q9 W0 t7 u5 G
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
8 h0 U+ q4 T6 m% [1 k! @$ W% h' S/ G3 P$ Y; u
turtles-own [a b c d k f g h
; l. R$ V/ A. |4 R x y ;; these are the leaf-turtle's offsets relative to center-turtle
7 Y- D$ N( C; K; q) `]$ i- a! N" n. T! S$ i) v+ N
to new3 S$ s `9 w8 R- B
ca
3 W1 X1 S$ c1 | crt 5 * num_of_building/ r5 R4 j J9 m: X7 H
ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
4 M/ p/ t _" U% K- w' G9 E. ? scatter ;;keep center-turtle random positions , w1 w0 s& Q% V
unit_plan ;;make up the building plan5 U* M! U( F( h2 `4 e
end3 `" ]# D6 {2 R
to scatter0 j6 _( P7 y( Y7 Q; |+ E' F6 ~
ask turtles with [remainder who 5 = 0]. c9 H7 K7 [5 T8 e1 R
[
9 J* f4 G* Q8 P/ `) tset xcor xcor - 6 + random-float 155 {( `) j! I* u9 Q! E( r5 Z/ ~
set ycor ycor - 6 + random-float 150 |" n f4 o; I4 w9 w' h+ t
]
1 h6 {" Q# B) v$ Hend; X/ p6 M- i) V5 @: s, U8 A# b
to unit_plan
' Y. @4 q9 v# X# P5 R. Q7 P6 n {ask turtles [; E; Q3 ~1 }) l
if (remainder who 5 = 1) [set a who ' m4 _6 ^3 J# u. k$ G
set x ( 0 - Wid / 2 )
, X8 Z% h& N/ b9 G' m set y Dep / 2 ]
4 S4 N" C Q9 p( r set b int (a / 5) * 5
8 t5 u4 s9 y# E, h setxy ( xcor-of turtle b + x )! ~4 u: J/ @% |5 u8 ^# M
( ycor-of turtle b + y )* ~. f$ w, F1 X; V5 Q, P
if (remainder who 5 = 2) [set c who
% X8 u" E; o# D8 `7 T8 D* b' H" ^ set x ( 0 - Wid / 2 )
, Q. @, ^4 E4 d) p4 I set y (0 - Dep / 2 ) ]* y5 v5 }) ]& U) o
set d int (c / 5) * 5
6 E' o1 x* Y& B! } setxy ( xcor-of turtle d + x )
' U: z6 {/ R# T" L+ \7 i i (ycor-of turtle d + y ) * Y" x4 I+ `# `" }6 k6 _
$ k3 ]$ S) ?, ^! z
' n4 w+ _) h$ ]. uif (remainder who 5 = 3) [set k who+ s6 O8 `# h V! u* H
set x( Wid / 2)
3 f& V( {1 G0 a( B) | set y (0 - Dep / 2 ) ]
% ^+ `# D. Y) S( k& Q3 s set f int (k / 5) * 5% ^, |, S$ L# [9 }3 e) U4 t
setxy ( xcor-of turtle f + x )
% @0 ~6 d. v3 I% P (ycor-of turtle f + y )
: ~9 I1 M) y$ v- n1 F1 \
3 h& m. B3 R/ Q2 e S
7 `; E: p4 e# x/ Q2 A( I& {if (remainder who 5 = 4) [set g who5 `! [0 a2 @8 B8 [1 L
set x Wid / 2
3 n; ^; e# \. n5 b0 F set y Dep / 2 ]
* a' |0 O1 }8 P' q! [* z2 T set h int (g / 5) * 5. e$ K# x" h/ ?1 F7 O5 t' Q
setxy ( xcor-of turtle h + x )% }& ~3 O" Y% z$ j
(ycor-of turtle h + y ) * T/ N$ }; l9 N
5 A$ t6 R- P; Y - B" Y0 g4 d1 \" O% V. [
]
3 M6 S4 S3 U( s, aend
; N1 A- }4 ^ y) V; w o) K" ?' A0 _, w+ v6 o
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|