《netlogo实现相向行驶的小汽车(共3页).docx》由会员分享,可在线阅读,更多相关《netlogo实现相向行驶的小汽车(共3页).docx(3页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上在街道上行驶的汽车要求:1. 汽车按照上下行车道行驶2. 汽车的加速度和减速度,通过滑动空间来调节。行驶过程中不发生碰撞事件。3. 能够时时检测汽车在行驶过程中的最大速度和最小速度。4. 绘制某一选定汽车在整个运行期间的速度曲线globals sample-car turtles-own speed speed-limit speed-min to setup clear-all ask patches setup-road setup-cars reset-ticksendto setup-road if (pycor 0) set pcolor white end
2、to setup-cars set-default-shape turtles car crt number-of-cars set color blue set size 1 set shape car setxy random-xcor random-ycor set heading 90 ; set initial speed to be in range 0.1 to 1.0 set speed 0.1 + random-float .9 set ycor 2 set ycor random 2 + 6 set speed 0.1 + random-float .9 set speed
3、-limit 1 set speed-min 0 separate-cars crt number-of-car2s set color orange set size 1 set shape car top setxy random-xcor random-ycor set heading 270 ; set initial speed to be in range 0.1 to 1.0 set ycor random 2 set ycor random 2 + 17 set speed 0.1 + random-float .9 set speed-limit 1 set speed-mi
4、n 0 separate-cars set sample-car one-of turtles ask sample-car set color red ask patches withpycor = 10 and pxcor = 0 and pxcor = 50 set pcolor 122 endto separate-cars if any? other turtles-here fd 1 separate-cars endto go ask turtles let car-ahead one-of turtles-on patch-ahead 1 ifelse car-ahead != nobody slow-down-car car-ahead speed-up-car if speed speed-limit set speed speed-limit fd speed tickendto slow-down-car car-ahead set speed speed of car-ahead - decelerationendto speed-up-car set speed speed + accelerationend专心-专注-专业