|
|
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
6 V' K" v) r! z! C: u; _5 t6 Q5 L: }
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
! |, V. m7 ^: M2 _$ U, h* Z5 ?* E' u4 j0 l! Z0 J1 G
turtles-own [a b c d k f g h, e7 k5 X6 Z& [- {+ o `5 r3 {0 I
x y ;; these are the leaf-turtle's offsets relative to center-turtle
5 \2 I4 K8 z$ T2 s# Y9 \]' \* m; u3 p0 J3 D4 ^1 ^
to new
3 M$ \' d1 J. x4 J+ W ca9 c/ G! n6 L# x; N
crt 5 * num_of_building
/ o3 _/ E( e% {6 x3 O$ } ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
0 ]8 p4 B4 R+ y# v4 [* S; Q scatter ;;keep center-turtle random positions
/ j/ }9 ?7 T' Z& r unit_plan ;;make up the building plan
; Z8 b% { m7 k% P+ S) Q" Jend
+ Y, F; K* D* A7 r Y) U3 hto scatter
, h. K) u3 q6 D/ \ask turtles with [remainder who 5 = 0]
5 K8 l9 e7 ~3 W% s, ?[" f4 g# W, }9 i5 f
set xcor xcor - 6 + random-float 15; z' X! {2 {8 ~. ^6 |1 p" m7 T
set ycor ycor - 6 + random-float 15: {# E, g8 `9 Y; T% H" g' g! S, p4 D
]
: N! z8 u5 ~, ^. }! _, M. Vend6 C. V% k" V; a' j" D) J
to unit_plan - ?0 a! R& i4 V' s) i
ask turtles [
( |$ N* E' h& c5 {if (remainder who 5 = 1) [set a who 7 C7 ]9 @# p7 o& }
set x ( 0 - Wid / 2 ) " H" u5 v8 c' j1 J4 O+ k5 m
set y Dep / 2 ]; f v, c0 d5 {
set b int (a / 5) * 5( z" n7 Q- f4 J) E/ j/ H
setxy ( xcor-of turtle b + x )4 v+ T' |5 \( J7 K1 k* r0 ^; t9 g
( ycor-of turtle b + y )
m) v6 j8 T" V" C, S% Jif (remainder who 5 = 2) [set c who- m' W7 Y9 ^, ?! \
set x ( 0 - Wid / 2 ) 3 v3 ^- d# l. W2 \: p
set y (0 - Dep / 2 ) ]
/ w f( Y& T- u set d int (c / 5) * 5, ^3 j# }9 O( a8 t$ y' L
setxy ( xcor-of turtle d + x )
; {' h! i1 n! ]3 o+ _5 ^. K (ycor-of turtle d + y )
' M! O3 y- ]1 Y! R G , }7 J1 Q# n4 I6 A4 m8 s
" Q1 f0 Y; a m Z S6 gif (remainder who 5 = 3) [set k who. v8 |; s7 V4 r" m
set x( Wid / 2) 3 v3 S, s6 B( I! Z m) C# S! \
set y (0 - Dep / 2 ) ]. l! X! I" T: F4 c1 Z4 O# U
set f int (k / 5) * 5! n9 F% N2 U9 O! D4 a% T$ R3 O
setxy ( xcor-of turtle f + x )
! x9 j1 Y Z0 X& r# }1 Q (ycor-of turtle f + y )
1 K8 K# M9 ]! `" b, D4 Z2 |! `
9 _; r* A" W% m, t x$ I( Z# q ) L/ L/ J; U( |
if (remainder who 5 = 4) [set g who7 `. a4 b+ v+ I' V
set x Wid / 2 1 _3 v; t( e9 `( U. D
set y Dep / 2 ]( j0 z# P9 q- ^+ P1 `& h
set h int (g / 5) * 5, O" R: {' y, h% [" d' L# w, q8 D2 U+ }
setxy ( xcor-of turtle h + x )# `# o: f4 d8 `$ v
(ycor-of turtle h + y ) ; i. Q7 D* l( D, R e5 q" Y
. L3 _- }" f1 r
* f u$ C. ]! C. q, O ]) s! R7 R, m* S5 V U
end
, f6 |5 ^. Y8 S; e: M; L8 ]& s. a
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|