|
|
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
) C* s( }, Z) j9 N1 d9 A1 d3 v; | r# r2 x( N) o; X
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
: a0 }6 L o4 f q2 P" {' N- e0 T" M" H" z @( |* ]
turtles-own [a b c d k f g h
, x2 ?2 t h2 \; n1 }- { x y ;; these are the leaf-turtle's offsets relative to center-turtle 0 Q* x- q# m! C! d
]3 V5 }+ V) G. w5 I4 I( D! h
to new, ?2 }) B. t* h
ca
0 U6 \5 }& f* p4 T; h crt 5 * num_of_building) M/ x4 A4 N' e
ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
$ C. R* a: T" H0 k. [# G scatter ;;keep center-turtle random positions 0 Z8 r7 D2 H0 w
unit_plan ;;make up the building plan
B4 S# o; n5 r' G0 mend9 S' z0 ?' g _( r( _! |
to scatter
9 }) L) x& {2 g+ [4 u/ \- m+ k" H; kask turtles with [remainder who 5 = 0]- |2 T. ^ T9 T$ Q
[
: ~% ~. j+ B' F# k6 T* o5 nset xcor xcor - 6 + random-float 15
6 |( R* W1 V$ i$ ~! Vset ycor ycor - 6 + random-float 15
( |+ G! j5 ]4 w* s& C: R5 F* v' t]
U8 p) T* `4 W( @5 |end0 `, S6 l& A+ m( W3 P
to unit_plan 0 R: f9 v7 Z# Z
ask turtles [# c$ L" Q% Q; p3 a+ v8 b+ L( \
if (remainder who 5 = 1) [set a who
) r7 E6 l7 a% ^& q q set x ( 0 - Wid / 2 ) $ l9 N2 }: T+ D5 \. h' @5 ?7 L
set y Dep / 2 ]2 ?8 Y3 h! I: j, y4 w' O9 F y
set b int (a / 5) * 51 O8 r+ H* t) D- N4 S
setxy ( xcor-of turtle b + x ): Y1 M+ v4 t# N
( ycor-of turtle b + y )
: _0 L8 X9 w; r6 ]if (remainder who 5 = 2) [set c who
/ S" Y) Z$ J$ D5 z3 P: h2 J set x ( 0 - Wid / 2 )
$ o& y" Q" }% P9 @1 H: f set y (0 - Dep / 2 ) ]/ _1 c: f0 @) A3 D; @. |7 ~
set d int (c / 5) * 5
2 Q( R0 b. [4 D5 H+ j setxy ( xcor-of turtle d + x ). ]2 @$ E9 ^8 Q. D1 H
(ycor-of turtle d + y ) $ I. \# @1 P* X) G. i M$ J5 g
+ }# M; o1 M; j
2 q1 X. I/ x B( @4 f9 I$ S
if (remainder who 5 = 3) [set k who
0 ~; y/ R% ^' @/ W! [' H1 L set x( Wid / 2) ' }5 @1 Z! G0 w: r8 O* [ T& [
set y (0 - Dep / 2 ) ]9 ~; h9 m/ J: y4 b3 I( [2 k: S! I
set f int (k / 5) * 5
' v8 @% G! z- j5 F( u1 W6 B N8 j setxy ( xcor-of turtle f + x )
9 z4 f" v& s. R+ H7 l' M% u (ycor-of turtle f + y ) - j# D. D9 f( q, U
4 w2 l0 F; h# m; }" B8 Y
, a; ^2 V) o' a. Rif (remainder who 5 = 4) [set g who
3 C* k) t4 F1 X set x Wid / 2 # n1 e# x8 ~4 H7 Y/ g7 C# r4 b) t
set y Dep / 2 ]
" M" O m2 k" k: O' j/ r set h int (g / 5) * 5! \* }& {, _5 Z/ D5 h0 d8 K& h
setxy ( xcor-of turtle h + x )
5 C6 |6 v S& t. b+ v' {9 D9 ? (ycor-of turtle h + y ) 9 i5 N7 ^/ P% c8 |
+ }8 Y! {( r5 }
+ v4 u1 t! f' Q, E; d ]2 G; M( c- \$ B# y7 _$ s% g; m
end
6 O7 G1 {+ B5 K4 c/ S
% _6 B' m% O- v- ^) O' O[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|