|
|
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。. _ o. A7 b4 w
: w/ I- n) e8 e$ L) l' h1 v但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
) S [! n+ T2 s. N0 M5 r ~/ ?, u t( }3 a: N& L( t, G
turtles-own [a b c d k f g h# m1 |/ @. I, e8 t$ _$ s+ o
x y ;; these are the leaf-turtle's offsets relative to center-turtle ^/ f4 N( U! [3 t% E& n0 w; o
]1 k \; @* e: K
to new
$ D2 g* H, ]% T7 O4 f! N ca
9 {1 g$ E/ I# o9 L crt 5 * num_of_building
- A5 j4 o8 z5 D. N ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]9 p5 X( k, @6 K4 _$ Q/ }1 \2 @
scatter ;;keep center-turtle random positions + b9 D, m- U1 K& B& p3 V
unit_plan ;;make up the building plan
. z+ F( N) a& w" g B {! j! Cend
& Z1 ]- O/ r; cto scatter
2 H, G5 T3 E) b6 P+ r. | y- Xask turtles with [remainder who 5 = 0]
4 v! L% @0 [. N/ ~4 p[
: ]% A0 U6 ]4 w G/ b V; {, X3 m- yset xcor xcor - 6 + random-float 15
' D1 Q( Z. S/ y4 v! }set ycor ycor - 6 + random-float 15+ Y' K) X3 S0 @. U! ?) @6 f
]
9 \5 u& W0 w, Y) ]0 y/ Z$ vend8 Q7 G ]- r( N) |' h
to unit_plan
! o* b0 t- R/ ] D7 o: Hask turtles [% H# t( b* R9 g# a m
if (remainder who 5 = 1) [set a who
* M6 I) e, r6 u2 V; a6 U* c! S1 @: D set x ( 0 - Wid / 2 )
3 d* {" L1 U9 D) ]) \7 a% U, D set y Dep / 2 ]
2 s- [% Y+ g2 C set b int (a / 5) * 5" P. I5 L# s* x, B; U7 {
setxy ( xcor-of turtle b + x )
: o1 ?5 }: l" T2 d! a7 v ( ycor-of turtle b + y )
6 f8 q: ^6 I" w' I3 d6 Eif (remainder who 5 = 2) [set c who
* U/ k$ y# u: w; B9 J% V set x ( 0 - Wid / 2 ) 1 j7 O6 n$ j% N% y3 }
set y (0 - Dep / 2 ) ]
5 r8 b: K- k) P# U set d int (c / 5) * 5
" y1 n9 t- \7 `, m1 O setxy ( xcor-of turtle d + x )- h6 M# ~. W( o4 ?5 d: J( _
(ycor-of turtle d + y ) 4 b% e9 o7 g' O7 a# x6 D
4 i- u( x, ?; H
, B/ u# Q, c& z( d* v7 J/ Oif (remainder who 5 = 3) [set k who1 ^' q6 Z1 K M. N
set x( Wid / 2) $ t' m4 t E! u; a
set y (0 - Dep / 2 ) ]1 ^; i. O+ J1 G6 {
set f int (k / 5) * 5: q, ?$ |! S0 w# E' G4 v4 a4 j
setxy ( xcor-of turtle f + x ), c1 T+ o, f' y- P* ?
(ycor-of turtle f + y )
$ e0 @- \# B6 h
4 u$ G! @4 e' K& B" M$ \ * y A9 o0 i$ x/ B2 b/ |
if (remainder who 5 = 4) [set g who4 k& g/ T! t! H
set x Wid / 2
9 K2 \8 c, b9 [, g7 u set y Dep / 2 ]3 u! E1 t* r: w0 C: P% L
set h int (g / 5) * 5' V3 y& L* Y q% A! j- }
setxy ( xcor-of turtle h + x )+ x+ T+ v5 s4 p- f$ M' z
(ycor-of turtle h + y ) 3 l: a0 r( G0 B. @3 Z3 ]
1 z L$ S8 f/ E; S5 ]$ k
7 d( `' c N7 N
], _+ L2 J& w* X( P5 V' c
end
2 w- J h t# `6 f$ y- _
/ Z2 i/ X6 F7 Z, F" E" j[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|