设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6249|回复: 1

[交流] 看看这段代码的问题

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。! i' D* P/ Z3 q3 e! C; b2 @

* C# W  Y. }+ n9 p3 O" w; E但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
8 T, B& A& E6 \! c* }" T' `9 j' a$ v/ @7 ]+ H
turtles-own [a b c d k f g h
! S8 i. q- P2 D8 g; G  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ! g9 v4 v4 m" z0 w4 @
]7 a" k* S% m& x; X9 U' n
to new
: @. |  e# W( C: C/ x7 n  ca6 k8 W5 q3 J+ }2 }
  crt 5 * num_of_building
& _' I& P' Y- z2 d1 }  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]/ k4 ?$ b6 w. m5 z& X: H
  scatter     ;;keep center-turtle random positions $ F  |6 K$ p* a- K3 s, l; x
  unit_plan   ;;make up the building plan
$ I3 J$ c$ ?7 J5 }& f! G! Vend+ c$ h0 ^2 {7 @/ t5 V0 n$ A  E
to scatter
$ N& j& c+ |0 |' M; [4 Hask turtles with [remainder who 5 = 0]+ V( I! p- E- F) z1 Y) \7 N/ A1 h
[, @$ M+ H& `) L3 }6 q5 C  o" P( T: r
set xcor xcor - 6 + random-float 15: d3 r$ M# C8 g
set ycor ycor - 6 + random-float 15
- y8 X, g" Y1 @% S8 G3 T]2 ]1 w3 E- W5 W; d. o
end. L$ h/ R' h7 P. j; a6 f
to unit_plan
2 r- j9 R: w' M1 A) M& i0 g- h) Wask turtles [% c$ U0 n3 @7 C/ e6 _0 ?+ I7 A
if (remainder who 5 = 1) [set a who
2 }1 i! y! c: U$ l, u# h( S7 q                          set x ( 0 - Wid / 2 )
. a" l) J  b! `$ L& i9 a                          set y  Dep / 2 ]# m% X' F- R) e5 @' A% `
           set b  int (a / 5) * 5
0 K, I4 N: R8 s+ a    setxy ( xcor-of turtle b + x ), v4 y6 N- A% V
          ( ycor-of turtle b + y )
% z: h  [1 M2 j0 t' Mif (remainder who 5 = 2) [set c who7 _* u" }2 a5 x2 u
                          set x ( 0 - Wid / 2 ) " P0 g8 [) N* e. A$ m% I
                          set y (0 - Dep / 2 )  ]
" C! A) Q- r( _3 g: ^( g$ s3 f; w/ `                          set d int (c / 5) * 5
( i2 {8 g' d' E6 P   setxy   ( xcor-of turtle d + x )
( C% {% k4 W4 b2 }& i" F           (ycor-of turtle d + y )
, k$ W7 ~3 \% X          2 Z# q" T& e! U, b
              L$ ~0 C$ z+ T* {0 ~5 C
if (remainder who 5 = 3) [set k who
1 M! S. j# Z# Y* r0 |                          set x( Wid / 2)  " t  ]% D4 v  ~' M8 }# O
                          set y (0 - Dep / 2 ) ]
7 ~* w6 K6 A+ K* J$ Y; s3 H2 @) O                          set f int (k / 5) * 5
  T; @8 B: {' h9 R5 R- m- s  setxy   ( xcor-of turtle f + x )9 j' p3 m* F+ b) e0 u) g
           (ycor-of turtle f + y )
2 T$ ^) B! h0 z1 B  ~           
" R9 Q, X# [& d( c6 C( c, S1 U           
+ \7 J% @9 P; i$ r" d5 Pif (remainder who 5 = 4) [set g who
0 B! u* I" r) [( Q7 I; A                          set x Wid / 2
/ u/ W6 Y8 K% J6 q, t                          set y  Dep / 2 ]
4 k' j0 j* ~, Z( C, N( N6 l% n/ C' N                          set h  int (g / 5) * 5
. j/ v" A0 E0 b4 n  setxy   ( xcor-of turtle h + x )
/ Y1 K! y" n( l2 a           (ycor-of turtle h + y )
) W9 X/ g3 o0 V8 j                          
. o% _: M, o0 \. J+ ?  {. s                          % L# h# {# s* m2 K/ f
                          ]
4 }8 b$ U8 g) _' d* X) r& t8 Y9 [end
, {& y5 d' f  X4 M+ @+ U
1 t/ w5 J0 u" P* P6 b[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
" s9 t$ q7 S9 y) \! x: x  L应该是
6 {" A: c" H9 X7 [/ V5 Bask turtles [9 d. h: i* m( m3 g( X  T: o- [
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ( m* ^+ C2 Y$ [
                          set y  Dep / 2 ) [3 x1 h& x% c
           set b  int (who / 5) * 5& u: ?6 }9 s0 x7 ~. `2 [, S) D  _
    setxy ( xcor-of turtle b + x )5 v: q/ b& F- p, @# i
          ( ycor-of turtle b + y )]]" X; q/ x2 X" D+ T0 l+ a
end
. p: K/ z: J. Z之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2025-9-5 12:32 , Processed in 0.015967 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表