|
|
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
4 Y' ?: ?5 p" \; \! Y8 ]5 u/ F6 L% q, A; {% H3 q
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
3 ~. F% {& l# m& R, c3 L
+ ]3 ?( U4 Z# T! g4 { }turtles-own [a b c d k f g h
, v( t) v9 B2 z3 T x y ;; these are the leaf-turtle's offsets relative to center-turtle
2 q+ @2 e9 F0 Z* Y5 b( z* []* l/ b0 ^& N) r0 |+ F" q
to new
$ Y5 z2 _3 n/ ^ ca* i$ Y( m" `! E9 ?! I
crt 5 * num_of_building9 ], n: U% g9 L5 m# x& [6 \
ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
j2 e" w& i8 G scatter ;;keep center-turtle random positions 3 ^6 a+ g2 ~6 _5 i4 E' h: y7 m# a
unit_plan ;;make up the building plan$ g$ Z7 _- o& h8 A6 l
end8 e/ u- L& ^& X. r: v
to scatter0 t+ V- y; f* E/ i
ask turtles with [remainder who 5 = 0]
( S/ F6 \1 H8 L/ d `0 X[
% t1 s7 y; C* w# t3 L# D Gset xcor xcor - 6 + random-float 15& g3 W" d! H! `) ]1 l
set ycor ycor - 6 + random-float 15
9 i7 ^- X7 W2 w1 G- `( P q]
U# a1 U- }3 n, ?end: G' ?- i& L# r: H9 @+ h
to unit_plan # a/ N0 {8 Y) w$ X
ask turtles [
, k7 U$ G2 u# c( l8 `" k# Gif (remainder who 5 = 1) [set a who . |, }# y% E$ b, R4 o
set x ( 0 - Wid / 2 )
l- C' r* y* b' \/ j set y Dep / 2 ]: m' J* q Y* c4 d- a O& r
set b int (a / 5) * 5+ x8 Z$ W4 P8 g
setxy ( xcor-of turtle b + x )
1 e* c) ~- ~& I5 q2 @# v ( ycor-of turtle b + y )
& W0 {/ B$ | ~. B& [/ kif (remainder who 5 = 2) [set c who) ]5 O! [9 p9 I) `$ ?' }
set x ( 0 - Wid / 2 )
Y& i% c- t: R7 z4 | set y (0 - Dep / 2 ) ]8 Y* O3 n& m6 B* v2 I" m1 u- j
set d int (c / 5) * 58 F2 W) U; D' S J, D- O% b0 U
setxy ( xcor-of turtle d + x ) H n$ D6 M% {: t
(ycor-of turtle d + y ) ( R3 v$ k% _3 @/ l/ g! a
2 C; ] f( Y% F) f 3 m( ?1 Z0 t: u+ @
if (remainder who 5 = 3) [set k who
- ?# B: x. ]0 p7 J3 O8 k7 h set x( Wid / 2) & X& i: R1 G; s! j+ z" I( K4 z0 L
set y (0 - Dep / 2 ) ]; ~& G6 U+ ?+ C8 c+ \
set f int (k / 5) * 5
# I2 j2 \+ G1 S setxy ( xcor-of turtle f + x )+ |+ o" S3 L5 m+ L# h: C
(ycor-of turtle f + y )
* j' {( q- X C P' k 2 P$ q' i& C" ?2 N8 F& V( ~
" [* V" m7 ^5 v5 p$ nif (remainder who 5 = 4) [set g who, N0 j7 g9 _' a3 z
set x Wid / 2
1 t7 |, A% k& Z set y Dep / 2 ]
9 @: Q+ R8 H( F8 I! r0 ~, y7 v set h int (g / 5) * 5 _) l( @4 A$ z/ t5 Y$ n
setxy ( xcor-of turtle h + x )! _! _6 _9 R ]( t O. n0 ~9 C5 }
(ycor-of turtle h + y ) ' p7 h* v# T0 Y: T
. B( h. |. x+ s: N
$ l8 N o- |; H8 ~ m
]5 ~) G; y' C: U. t: B2 d
end
- r i3 }& z: j/ B7 b4 V8 ?( ^3 S/ f+ ]% u
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|