设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7587|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
. Y- g- x1 m5 N1 Q0 @6 M
: t3 f' x: Z! l但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。3 ?( p# d9 b  T/ p! n
. e/ f1 F0 ~2 I* n; C
turtles-own [a b c d k f g h
5 R  Z: }$ G% S* z2 y& G  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
1 k: J1 N, n/ u" l3 S" [' }( z]
8 N. |/ \$ ^# \: q/ B4 T  T" bto new) c# C' L: o/ p4 u! Q/ p- R7 v
  ca/ v# Z2 n& U$ I* `2 K2 |
  crt 5 * num_of_building( _5 N, _5 Z6 \8 \+ \: X
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
" w; ]- ]* n4 c+ h. I  scatter     ;;keep center-turtle random positions
, N2 P: Y4 v0 [  unit_plan   ;;make up the building plan" I* W- J0 z( W9 y- @1 \- ?
end
# f. s+ }, \6 M, L3 Z. Y/ \to scatter
4 P$ w  |; R" x& u$ B6 `& Qask turtles with [remainder who 5 = 0]* T  l/ o8 _4 s; C( T% F: j
[8 |" D3 C3 w/ q& R) e
set xcor xcor - 6 + random-float 15. M9 [6 V6 J- t$ ]  t% Z" ?
set ycor ycor - 6 + random-float 15
; s8 i7 u% F' @2 a0 Q]0 u; c2 }+ P" `# e
end* B0 @; a% d6 c- w7 d
to unit_plan - d+ e( j7 S7 u
ask turtles [
& H9 N% t/ w3 g! e1 Aif (remainder who 5 = 1) [set a who 5 l) D. \( C2 G8 W: K9 `
                          set x ( 0 - Wid / 2 )
& n3 j8 A! W0 \. L+ b! z                          set y  Dep / 2 ]
# K% z9 |* C. G5 Q           set b  int (a / 5) * 5
) L* j& n) h0 o7 P6 R6 z' e    setxy ( xcor-of turtle b + x )5 d0 e" i: L. I+ l: n
          ( ycor-of turtle b + y ); b9 d$ j! u# }. X8 L4 V
if (remainder who 5 = 2) [set c who
. @% b7 _, B0 Y$ M$ J1 h) P                          set x ( 0 - Wid / 2 ) ) T3 W7 O& B* @+ l. ^; G/ \) U
                          set y (0 - Dep / 2 )  ]4 ~' R& a7 M' D! f2 R3 ]
                          set d int (c / 5) * 5
# G9 b/ V3 Y' A2 H6 M   setxy   ( xcor-of turtle d + x )
' a) |5 v  O) t           (ycor-of turtle d + y ) ' u9 W3 ~) ]0 L6 b7 A7 E/ [
         
! J) a/ n% j( i            
$ Y. Q9 w6 g! d* y7 ?5 [) oif (remainder who 5 = 3) [set k who9 G  B- w2 W/ w- Y
                          set x( Wid / 2)  - x; ?, Z" X! m8 c
                          set y (0 - Dep / 2 ) ]
" A; u1 ^( G; u2 Z) k                          set f int (k / 5) * 5
" F  a7 M& J- t9 `$ F  setxy   ( xcor-of turtle f + x )
; r2 h& v9 m1 x           (ycor-of turtle f + y )
( @* k2 X5 ?( T. ~4 r' l           5 h" y0 u# O9 }: x8 h
           
0 H/ o" [# e7 S9 N8 t! Lif (remainder who 5 = 4) [set g who
, g% ~8 ^, ^+ Z3 j  d! [  `                          set x Wid / 2
0 o" _' [4 p; M6 x! v                          set y  Dep / 2 ]
5 @! d( g% H; \1 a" [8 T0 k' s4 D                          set h  int (g / 5) * 5, c# g3 d( B% p: \4 w7 n
  setxy   ( xcor-of turtle h + x )
- N6 j3 {: o! V4 k: g2 u- I           (ycor-of turtle h + y ) * L4 ]& ~& T9 o* M! B
                          
& `, }: j. D! _% j. ]( E0 u                          5 z, ~) \+ g1 {6 P. e' Z3 C
                          ]
! N( k- d* |/ @- t! X6 Yend
! z* F# F1 h+ m8 K( y. ^' i; @5 X2 P1 y
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,2 b( U3 d) k1 v- y, o3 U& a2 ?9 k  K
应该是
. V* N- n  H: ~$ y( D) Task turtles [
# w$ O" c) t: m# Eif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 9 n, [. J. B4 w* e' L- V6 u+ Y
                          set y  Dep / 2
+ \+ X7 \4 h: q) [* y- d           set b  int (who / 5) * 5
9 s# t0 @* b' d! ^* @    setxy ( xcor-of turtle b + x )
: G4 @2 W* z( @3 M          ( ycor-of turtle b + y )]]
- R# r6 @" O) M$ p) Bend
- \5 B0 F1 G4 R- O之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-2 10:20 , Processed in 0.021139 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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