设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7404|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。$ l! l3 S9 c- r! w
+ u. P9 r, W3 Z$ W7 B- x) D9 c: G
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
& S3 T5 z5 M! Y6 g. W) u4 S+ N9 t5 T( d% F6 G
turtles-own [a b c d k f g h
( k- I: c8 w( O8 c7 c  x y     ;; these are the leaf-turtle's offsets relative to center-turtle $ S# q6 p7 u; Q6 ]8 q8 i& n( _: Y
]7 R3 O3 v! j0 O, A8 h$ C) U
to new8 c, G7 f- q, n6 W& J
  ca6 X$ }# T7 w! V; ?/ h' T1 C
  crt 5 * num_of_building
* `) b# t; X7 b( o+ `  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]1 e/ _% b! l) m
  scatter     ;;keep center-turtle random positions ; M0 i/ q! j3 I% f7 S# ~1 D1 T
  unit_plan   ;;make up the building plan- n7 g$ J* h$ r. d- v
end3 Q( W, I  B" A1 f2 A2 b
to scatter
" y* y; g  t+ B# xask turtles with [remainder who 5 = 0]
7 O0 V+ X+ i5 N2 W2 V4 w4 X: v( p[
; ]3 L+ o3 I6 U' C, sset xcor xcor - 6 + random-float 153 G- D) d* E) T8 V( d' M4 W
set ycor ycor - 6 + random-float 15
, |9 i" w) C4 Y! R]
7 c5 h5 l, W6 H- V( q' Hend: }# N" d2 t( _# f6 u- H4 n2 L
to unit_plan 4 e: s5 e( M, u/ j" }; h
ask turtles [& |$ h  _& \; l, E6 m: d
if (remainder who 5 = 1) [set a who
, c/ ?( f6 M% X3 g                          set x ( 0 - Wid / 2 )
3 ]8 b5 V3 y1 t$ d( Y5 D. G  g                          set y  Dep / 2 ]
1 W0 K) f" f! y$ ?* s           set b  int (a / 5) * 59 q8 O  }! P2 d+ K8 f3 O2 ]0 a% q5 `
    setxy ( xcor-of turtle b + x )9 B, j  A# {- s( u: V% Q7 ?
          ( ycor-of turtle b + y )
/ s% }. V2 i- O0 _( Z& @, Iif (remainder who 5 = 2) [set c who! t' _; A# A1 V2 J9 m# D
                          set x ( 0 - Wid / 2 ) 7 ^- n4 q4 h! H
                          set y (0 - Dep / 2 )  ]0 q8 F. T& u0 L9 o
                          set d int (c / 5) * 5
: T/ B) o1 K; N- e4 h( h. K   setxy   ( xcor-of turtle d + x )% n' S3 O; ]; [7 p7 U
           (ycor-of turtle d + y )
0 t6 T/ u% Z4 \2 Z9 f" ~! M% g         
7 r9 B6 j: \6 F- r4 I            
+ S/ q) x5 j! f' Q: sif (remainder who 5 = 3) [set k who
  Y' `) D0 Z- p) {* f9 B/ x                          set x( Wid / 2)  
5 ]0 i2 C) y0 E: a& h8 c7 }                          set y (0 - Dep / 2 ) ]
# o4 G- @8 \5 i# j; \" K' J. ^                          set f int (k / 5) * 5
, |' Y5 ]9 Q7 X5 Q  setxy   ( xcor-of turtle f + x )
; m: O2 |: {4 l           (ycor-of turtle f + y ) / t3 s4 c9 s% {" k1 ?: k& C
           
6 S4 Q2 _$ ?  ^' L9 y, G' p: y           
, W0 y  J: Y$ H8 Aif (remainder who 5 = 4) [set g who* x" f* B9 s' S, e
                          set x Wid / 2
1 z& q2 e* ?7 w6 _. @! [5 T. L8 f                          set y  Dep / 2 ]
2 O, {0 v- _9 \& s* S  b' S+ v                          set h  int (g / 5) * 52 V# u) p8 t2 b7 J1 h2 f" g9 L
  setxy   ( xcor-of turtle h + x )5 x- E2 U* S2 j8 l
           (ycor-of turtle h + y )
1 G' s( ]* {0 h% w' _1 c# ?' \                          
+ T! X. g" d4 J9 W                          
0 W9 R* f- g$ M' B, M/ \                          ]  R. B( ~! H$ |' c4 F# H. b
end
8 }: F9 g& a/ h- V8 {3 ]/ s) l. s$ s3 w
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,0 o' C' j5 \2 L4 o! O0 f
应该是
" L1 a  K' \) Nask turtles [  ^, t0 x5 N* s0 S: t8 }* y0 f; L6 q0 M
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 2 v1 A- z/ E/ z8 u& N# }- h. F7 Z
                          set y  Dep / 2
! o0 B! x0 g; O9 f9 G' Z. l           set b  int (who / 5) * 5
# ~  J3 ]  D! O7 u    setxy ( xcor-of turtle b + x )
& H% t) l, J1 s3 [/ Z: h2 ?          ( ycor-of turtle b + y )]]
' k4 m# j0 l* H! s5 X' bend6 K  F1 _7 S! m' Y; l3 N5 C3 B
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-8 13:49 , Processed in 0.015535 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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