|
|
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
v0 I" c0 b- ]' h1 A2 P, D7 o8 l4 b: S: X* i7 E
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。; ]/ [; [/ M( ^! ^ N: u
" ~; R8 A1 T$ Q: i0 I
turtles-own [a b c d k f g h
4 T8 T5 {7 @* T: |& ` x y ;; these are the leaf-turtle's offsets relative to center-turtle 9 o, V! K" G V+ C1 z, C# c
]
0 ~# Y4 k7 g, X# i2 Oto new: i) g% Z' ~ w7 x) k% k6 \# q
ca% H* Z2 ^& @8 |: [: {
crt 5 * num_of_building
+ a1 q7 x6 S0 x ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
5 o; L" h; u5 S/ Y scatter ;;keep center-turtle random positions
& \+ _' E, {" D- e unit_plan ;;make up the building plan
+ r3 w0 Q* e$ h# T% Wend
6 q1 Z) S, e; ^7 A5 \) b4 b% r1 ~5 @to scatter
+ P. w) C2 }% o! @ask turtles with [remainder who 5 = 0]
8 o: X& u1 W* ^; A+ T[5 e7 w4 |6 F/ d( @
set xcor xcor - 6 + random-float 156 J9 L' a$ c0 L$ W
set ycor ycor - 6 + random-float 15
- l7 x v: J8 y; |# I( m]
' j7 s" [, U$ o2 |: Dend
' P* O2 s* @$ L' x0 K3 ato unit_plan
; W) d. o: P: D$ C. k* Yask turtles [
2 R7 z6 P( W9 ~# Q7 N, Dif (remainder who 5 = 1) [set a who + h* M+ T$ p% `: q
set x ( 0 - Wid / 2 )
: R4 X1 X- m: `) A0 U- d set y Dep / 2 ]
/ K4 P, w% l: D" B8 } X7 P- Y set b int (a / 5) * 56 F: ?, k9 ]$ v% G. X' J& Y( p
setxy ( xcor-of turtle b + x )
% v1 ?/ f7 c y& B8 `1 c' z7 W ( ycor-of turtle b + y )
3 A4 R6 L* f( T2 v1 Aif (remainder who 5 = 2) [set c who& S: x, w& S$ H! Z
set x ( 0 - Wid / 2 )
' G: d- I+ H/ s set y (0 - Dep / 2 ) ]
# J7 S3 n, w/ z set d int (c / 5) * 5/ s. b6 I& I* c6 `& i" R+ Z/ G
setxy ( xcor-of turtle d + x )
2 ]( @ x: a$ B" ^) m- r (ycor-of turtle d + y ) 3 X) G& }3 f7 V |9 f: V: ~3 j
+ s8 t4 g; q3 R9 U+ { : A ], U% G2 Y, [( z! G: s
if (remainder who 5 = 3) [set k who; g% G3 a0 J8 F& ]
set x( Wid / 2)
: }# o( M2 U* ]) I set y (0 - Dep / 2 ) ]
: g1 ^+ q" H8 F set f int (k / 5) * 57 c! n/ G/ _( ~
setxy ( xcor-of turtle f + x ); W& w1 v" A# u- @/ l; G
(ycor-of turtle f + y ) 2 k8 c4 i) Y0 w+ y+ a/ z
* d) W3 O, L. c+ z: M
8 Z; [) }4 Q# |1 m( hif (remainder who 5 = 4) [set g who1 W. _& `! \! A( N6 H
set x Wid / 2 % ^7 g; \7 O2 |+ `
set y Dep / 2 ]. G" H% X6 k+ W
set h int (g / 5) * 5( p; L# F/ C" l- J8 N: q- e. y
setxy ( xcor-of turtle h + x )
" ~3 W, B, |) ?4 S- g (ycor-of turtle h + y ) 6 ^, G2 G3 k N9 E
( n3 j( V! ?2 p
6 ~& V; `+ r* F" I: W X
]% Z c" `- n i7 }3 D: B5 s
end
) }/ E( u1 k7 E t+ Y4 o& K( B& Q' t' B' f( Z; {
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|