|
|
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
& C" M2 }: s; M+ \" ?+ Z* `) ]& } S. J+ H! p
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。% K f" u q$ u2 ], m3 ~: |! N
k/ O6 u& B3 t M
turtles-own [a b c d k f g h$ c( D) g" r' U
x y ;; these are the leaf-turtle's offsets relative to center-turtle 7 t+ p" A* x; O8 y2 }
]+ H7 u9 t+ f& X+ S, ~! p4 |
to new
. S% C( R# e. U% G6 @7 P ca
- W6 |/ L; y' Z7 c9 h crt 5 * num_of_building
! W R$ e. K" ]/ D ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
5 }1 x- O, g5 w% t$ n scatter ;;keep center-turtle random positions 3 Z7 x5 d# ?; ?$ u& N
unit_plan ;;make up the building plan* [3 d4 L" D) _% B5 _, l% h
end
% c; b. j! x7 L4 H* {7 k. fto scatter
5 N" h4 _, L2 y# p& R0 _% |8 Wask turtles with [remainder who 5 = 0]
. J, R$ [7 C( w7 ?4 P( M" R6 g[
. _; R& c8 X) W+ F E* \set xcor xcor - 6 + random-float 15
: r7 X2 D" U) x6 Vset ycor ycor - 6 + random-float 15
0 a9 H6 G& ^( A7 G4 L0 u]$ O! x c; [6 V8 |' U& Q
end
$ O2 B9 P; g3 ]. n8 f0 F4 T0 {to unit_plan 7 T e! P" S1 N" P& [( c: ?+ B
ask turtles [
& M! O v9 m q7 S3 @# y2 m( ^4 qif (remainder who 5 = 1) [set a who
8 C' _+ t0 \* {' I set x ( 0 - Wid / 2 ) ( _6 \' G+ }9 a- }% L
set y Dep / 2 ]/ }& f2 ^" b. o' ~* ~3 d: e
set b int (a / 5) * 5
) H, K. K5 s1 J6 d. ~ setxy ( xcor-of turtle b + x )$ Z$ ~/ V0 [& W% o( X" m+ K' ~
( ycor-of turtle b + y )
y& |' S" ?1 c" I- q1 ]3 F2 fif (remainder who 5 = 2) [set c who
4 E+ T1 X8 R: C% g& j set x ( 0 - Wid / 2 ) ( G% H. D7 v) k9 y/ U; `) e
set y (0 - Dep / 2 ) ]
% J0 D/ @0 N# j% l: [' ^ set d int (c / 5) * 5, Y1 f' z7 U4 M( i. o- F; K
setxy ( xcor-of turtle d + x )
, L, y+ m" ]+ }, ?# [7 K (ycor-of turtle d + y )
) N U, J! X) } 9 P" A7 @* ?+ L/ ~ I5 M& H, ]' a9 X
+ \4 s, I8 w' r& n
if (remainder who 5 = 3) [set k who
/ o* r3 {7 s/ W# ~ set x( Wid / 2)
1 U4 j- X9 W' X& D4 R, c set y (0 - Dep / 2 ) ]$ z+ U5 y! G9 R: n& M
set f int (k / 5) * 5* ^1 B/ g' h- n4 u! i
setxy ( xcor-of turtle f + x )7 R: y. R- y9 h$ h; g$ \' z
(ycor-of turtle f + y ) / b+ L& W* O) G( S! a8 F3 q
# U* a. R1 q& J; y6 m. C
1 n- J. `0 o, \! A; Jif (remainder who 5 = 4) [set g who5 f3 z$ w5 w+ `7 f# |
set x Wid / 2 , g1 F4 t. l& H) w2 z/ t; `
set y Dep / 2 ]
7 T1 d2 ?5 r& O) a0 t3 U set h int (g / 5) * 5% z) A. d+ G# ?' q- {
setxy ( xcor-of turtle h + x )5 @( |/ b+ A. o' ]
(ycor-of turtle h + y )
/ I* A4 P( h( G4 d 3 a7 v* D3 ^' L2 t
. q$ p I* \% H ]& s/ R- y! S0 |/ ?% ^* w
end4 @9 e3 ~# c" s& B) `" X
5 C5 w' a; r# r: E[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|