设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7364|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
* C9 T/ |* T% g5 J4 D' ?# N% V) u
9 h1 }# a" I" h2 y, E$ ^4 c但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。: Y  h( u; E/ n  L9 w

# f6 o4 V' v0 _6 ^$ R4 ]turtles-own [a b c d k f g h( E+ O( S# t. O* y
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
- h% ~$ y6 a, ]! n$ G. v+ i]2 ^" E- R! g& @! i6 b
to new" ~; P6 T7 _) S! ~/ q. @& W
  ca6 S$ M6 V* ~5 q8 s6 U4 V
  crt 5 * num_of_building6 b1 w: Q/ A: j; ]% D$ S' X
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
1 y9 U+ |* o* x  scatter     ;;keep center-turtle random positions
' p5 c: V9 f( o! X" J. i  unit_plan   ;;make up the building plan
* b6 O4 I) e! X' uend3 m) z$ u5 b  I
to scatter$ P0 R: o" }. I" \
ask turtles with [remainder who 5 = 0]
( d; `3 |; h4 I& R- I* a[0 ?+ }( x% J7 m- a9 c- A
set xcor xcor - 6 + random-float 15
+ F" y, n/ y. _+ D& \6 b( ^& zset ycor ycor - 6 + random-float 15
7 u% m1 P: x' B& k2 v- C]
  y5 z& a! q# [) H  r, Yend- k% o- q: \4 B9 J) K4 _
to unit_plan
9 j) t% _# |# |/ y/ r. x8 xask turtles [2 I  O* D1 _1 K0 c1 i: d
if (remainder who 5 = 1) [set a who
  ^7 g1 u* P+ v) t9 V2 U                          set x ( 0 - Wid / 2 )
7 `- _6 X0 E5 g                          set y  Dep / 2 ]( H5 ~6 ?9 a4 ?* G  d1 k+ i
           set b  int (a / 5) * 5
/ b" k1 V; _0 [3 c+ l    setxy ( xcor-of turtle b + x )
6 s6 E# a0 _& n          ( ycor-of turtle b + y )+ B% g  }) i, D$ V$ W" f, P  a" k, }
if (remainder who 5 = 2) [set c who
+ y$ N! ?5 I( |9 N6 u# Y' N3 {                          set x ( 0 - Wid / 2 )
7 h3 T' r8 @8 ~, y; I: f- a                          set y (0 - Dep / 2 )  ]
% i6 ]# H4 r, o3 N( I- d0 c& l                          set d int (c / 5) * 5
0 J4 Y: m* U1 h/ ], |  K   setxy   ( xcor-of turtle d + x )
  W4 M: l' @" d9 K           (ycor-of turtle d + y )
6 Z" @: ^2 }) \         
+ E7 {4 ^* t) g3 B& r            + P* p' f: U' q7 N, F
if (remainder who 5 = 3) [set k who1 A  Q. L# b( n8 O8 E7 Z
                          set x( Wid / 2)  ! d% [! U- Q& E& g8 p7 Q! T
                          set y (0 - Dep / 2 ) ]
& X; `5 v& l3 A+ g                          set f int (k / 5) * 5+ ?; @' a( y% I$ w
  setxy   ( xcor-of turtle f + x )* b. z2 T# C" P( |5 q- G- r  ~
           (ycor-of turtle f + y )
$ G% A! |$ f1 M2 y9 P( E           
! Y  K/ H( J) q' N           
. ^( `$ ~, i/ M: Zif (remainder who 5 = 4) [set g who7 Q% A( m2 q( |, Y. s" Z7 ]8 Y; O
                          set x Wid / 2
8 X$ l& z5 j- I/ [                          set y  Dep / 2 ]* B' p' @4 m2 v% k, D1 T7 A
                          set h  int (g / 5) * 5
- T4 A" K2 O, d: U  setxy   ( xcor-of turtle h + x )4 a% h" W8 \4 t7 l
           (ycor-of turtle h + y )
& j+ L, Z5 R5 X( g                          8 ?( N7 Q) }* R- ^& d. e$ W
                          
' O# h2 u8 W5 x( p8 K4 Y2 {                          ]
; B  w3 g6 J4 t5 g$ Eend
0 F6 j- H0 V8 O: Z8 o  o- p5 k2 d. N# _( ~0 {4 M* K
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
/ U8 C( T# U( I- ~4 s: A7 A应该是6 v$ s5 e$ Y2 K4 U% @# l" ]
ask turtles [% X! r# }, w/ G' k: Q4 L
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
) M! o5 Z) u$ ~9 I7 N: o9 G) q                          set y  Dep / 2
, j. R2 u" E& [' Y1 H) A/ O           set b  int (who / 5) * 5) X6 N% T9 c% t
    setxy ( xcor-of turtle b + x )
# s2 u3 T1 C7 U% S$ t! U          ( ycor-of turtle b + y )]]
. p- I- J  B4 p4 R! F& |8 j5 jend
$ ~3 Y) f$ F: P/ ]' J- f) s+ S4 m" E之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-3 23:29 , Processed in 0.017261 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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