设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8038|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。+ ^8 P& T1 Y' K

  w. u# L) ?3 |& t9 E但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
4 ^# {) A# f! y) j. V2 K$ N  |1 W9 X' q, U, x& M: s& U
turtles-own [a b c d k f g h
3 k/ y. E# U9 u! m. E  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ; c1 u% W) E7 ~9 v# Z/ r: _
]
7 P  p8 }4 v1 ^* a$ W+ bto new
  r6 e8 w: U0 u6 y( {  Q  ca
+ h/ S; t4 B& Z- Y0 V  crt 5 * num_of_building# a7 k5 {, m6 n7 [8 Z* B
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]& v6 f2 w$ M# J
  scatter     ;;keep center-turtle random positions
: x/ s4 r- X4 U7 Q' |! q. Y* I  unit_plan   ;;make up the building plan
  M/ w. Q/ x& T& ~' g1 `% Qend
3 n: Q5 B8 c9 z( X* ]to scatter
1 F2 a. m; b4 k2 Q5 W9 G+ y6 I; bask turtles with [remainder who 5 = 0]5 w/ v2 X( w# h; p0 K
[
, @2 H2 b6 A6 H2 Cset xcor xcor - 6 + random-float 15
4 S6 Z7 U7 n, b# b+ G- {6 y1 _set ycor ycor - 6 + random-float 15/ l' S! |1 `7 ]9 l4 I  E' D
]
5 h0 p; A  B$ R! eend& `6 l/ e* W% \& Q, {" q( ]
to unit_plan
" S5 W' d7 w" G; _4 |ask turtles [
7 `4 b7 B  C" X/ ]/ ^( F' Dif (remainder who 5 = 1) [set a who * P# Y5 f9 C! T% p2 _" u. Z
                          set x ( 0 - Wid / 2 )
$ X* @8 l1 L( L% R8 t. ^1 P                          set y  Dep / 2 ]: x, e9 f1 d: H% K
           set b  int (a / 5) * 52 p' t0 F9 r( r- \
    setxy ( xcor-of turtle b + x )
! U9 N% I6 ^0 a" A3 y3 m9 _          ( ycor-of turtle b + y )
/ z9 M' {  V8 U( Rif (remainder who 5 = 2) [set c who3 I1 M" J1 t$ c, J9 _' ^! ]6 [  z
                          set x ( 0 - Wid / 2 )
0 ^) Z! H2 T! Z2 A  b                          set y (0 - Dep / 2 )  ]
1 _; t* o2 ~* a* n. b* v                          set d int (c / 5) * 5
% H9 |$ @, \" @+ X" Y) C4 C   setxy   ( xcor-of turtle d + x )5 q5 s/ W+ G! s/ W% |
           (ycor-of turtle d + y ) . c8 u* m5 Z9 A8 O  ^1 _5 \
          : K2 i1 \5 k' C9 r. ~
            ; ]3 ^; `% p6 ?) {
if (remainder who 5 = 3) [set k who$ O' x: W# z* m# f. @2 j% e
                          set x( Wid / 2)  
( Z% i/ @0 v, c7 W; T                          set y (0 - Dep / 2 ) ]+ c8 ?7 m8 c: I. T. S( B3 o* Y
                          set f int (k / 5) * 5
& k1 U( D, |! [8 l' a( |  setxy   ( xcor-of turtle f + x )
/ ~( P, y8 Q( ~           (ycor-of turtle f + y ) $ U0 O( b( F2 e5 c
           
& v7 n* o3 {' o# v           
7 _* X0 s4 `, j6 |if (remainder who 5 = 4) [set g who8 k: R" b- W* {; f' [8 U
                          set x Wid / 2
1 Z% |7 j0 K" A: i- O3 M                          set y  Dep / 2 ]
" o8 U, ]0 Q( e                          set h  int (g / 5) * 56 j' @7 F1 b7 p1 B6 q3 m* d% N
  setxy   ( xcor-of turtle h + x )* x& R. L7 Z( d4 X* y+ I
           (ycor-of turtle h + y ) 8 Z5 p2 V# D  Z9 X
                          " Q7 A( t- p, [+ S% ~$ f- |
                          
4 R$ }; l, O* y" Q                          ]
& s$ a% K" L" F/ l! f+ dend/ j* y* s8 s9 K1 W/ a2 w, t

- t) o3 E! f# F% y& @0 W[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
4 G8 B' b1 m; d9 k应该是
& |( @- ]. \2 U9 K. Gask turtles [
' K" }3 M. U2 P9 w$ X+ sif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
/ H9 l( M1 N9 @. ^6 o, q* o! h" Q                          set y  Dep / 2 ; S: S% Y" z, w% M+ @$ K% x
           set b  int (who / 5) * 5
" e. A! R0 R2 l    setxy ( xcor-of turtle b + x )/ w5 k5 \' c. }- u4 {
          ( ycor-of turtle b + y )]]
% b7 a0 o! K5 z1 iend& c- a1 R' ]3 I: e9 R1 T- \( ~7 {
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-30 23:42 , Processed in 0.015154 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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