trafico

Desafío Física: Editado por litdevMicrosoft Community Contributor, Moderador
http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/7239821c-161c-4328-b29d-7c55e40b11b9

Escriba un programa para controlar un semáforo en un cruce donde los coches llegan de diferentes direcciones a diferentes velocidades. Si quieres un reto aún más luego añadir unas cruces de la red de carreteras y controlar  todas las luces. Las luces se pueden detectar cuando una cola se está acumulando.
Un reto difícil para algunos de ustedes puede que deseen trabajar juntos en esto.

Programa Listing TRK448-1    Editado por NaochanON

  1. ‘  Challenge of the month April 2013  …   Physics Challenge   //  Trafic  ….     by  NaochanON
  2. ‘  TRK448-1
  3. Shapes_Init()
  4. GUI()
  5. shapecars()
  1. While “true”
  2. L_Cars_Moving()
  3. R_Cars_Moving()
  4. Up_Cars_Moving()
  5. Down_Cars_Moving()
  6. RemainTime()
  7. Program.Delay(50)
  8. endwhile
  1. Sub  X_AvoidCollision
  2. For LL=(DN+2) To (DN+cars+1)
  3. If  LL<>L Then
  4. If Math.abs(Shapes.GetLeft(SHP[LL][1]["obj"])-Shapes.GetLeft(SHP[L][1]["obj"]))<160*s Then ‘  next car
  5. Vx[LL]=Vx[L]            ‘  same speed // avoid collision
  6. EndIf
  7. EndIf
  8. EndFor
  9. EndSub
  1. Sub  Y_AvoidCollision
  2. For LL=(2*cars+2+DN) To (3*cars+1+DN)
  3. If  LL<>L Then
  4. If Math.abs( Shapes.Gettop(SHP[LL][1]["obj"]) – Shapes.Gettop(SHP[L][1]["obj"]) )<140*s Then ‘  next car
  5. Vy[LL]=Vy[L]            ‘  same speed // avoid collision
  6. EndIf
  7. EndIf
  8. EndFor
  9. EndSub
  1. Sub RNDXSpeed
  2. Vx[L]= Vx[L-1]+Math.GetRandomNumber(10)/10
  3. Vx[DN+2]=4.5
  4. EndSub
  1. Sub RNDYSpeed
  2. Vy[L]= Vy[L-1]+Math.GetRandomNumber(10)/10
  3. Vy[DN+2*cars+2]=3.5
  4. EndSub
  1. Sub L_Cars_Moving
  2. DN=0
  3. For L=2 To (cars+1)
  4. Xpos[L]=Shapes.GetLeft(SHP[L][1]["obj"])
  5. ‘———————————————   Restart  ———————————————————————————————–
  6. If  LRNotice=”OK” And  -2000<Xpos[L] and Vx[L]<0.35 then        ‘    if   signal becomes “Blue”
  7. RNDXSpeed()                                                   ’   new speed
  8. EndIf
  9. ‘———————————————   Yellow Signal  ——————————————————————————————-
  10. If  LRNotice=”Notice” And RemTime<=24 and  625<Xpos[L]  and Xpos[L]<675  then ‘//  Notice Area
  11. Vx[L]=Vx[L]*0.5                                                  ‘   speed down
  12. elseIf  LRNotice=”Notice” And  550<Xpos[L]  and Xpos[L]<625  then   ’    Signal = “Yellow”
  13. Vx[L]=Vx[L]+0.75                                                 ‘   speed down
  14. EndIf
  15. ‘———————————————   Red Signal  ——————————————————————————————-
  16. If  LRNotice=”NG” And  625<Xpos[L]  and Xpos[L]<675  then       ‘    Signal = “Red”
  17. Vx[L]=0                                                       ‘   speed down
  18. EndIf
  19. ‘———————————————   car move  // avoid collision   ———————————————————————–
  20. For i=start To end
  21. Shapes.Move(SHP[L][i]["obj"],Shapes.GetLeft(SHP[L][i]["obj"])-Vx[L],Shapes.GetTop(SHP[L][i]["obj"]))
  22. EndFor
  23. X_AvoidCollision()                                              ‘   speed  control
  24. ‘———————————————–   go over left    next position  ————————————————————————-
  25. If Xpos[L]<-(300+135*L) Then
  26. RNDX=1300 -Xpos[L]+ 135*L*2
  27. For i=start To end
  28. shapes.Move(SHP[L][i]["obj"],Shapes.GetLeft(SHP[L][i]["obj"])+Rndx,Shapes.GetTop(SHP[L][i]["obj"]))
  29. endfor
  30. RNDXSpeed()
  31. endif
  32. EndFor
  33. EndSub
  1. Sub R_Cars_Moving
  2. DN=cars
  3. For L=(cars+2) To (2*cars+1)
  4. Xpos[L]=Shapes.GetLeft(SHP[L][1]["obj"])
  5. ‘———————————————   Restart  ———————————————————————————————–
  6. If  LRNotice=”OK” And  -2000<Xpos[L] and Vx[L]<0.35 then       ‘    if   signal becomes “Blue”
  7. RNDXSpeed()                                                  ‘   new speed
  8. EndIf
  9. ‘———————————————   Yellow Signal  ——————————————————————————————-
  10. If  LRNotice=”Notice” And RemTime<=24 and  370<Xpos[L]  and Xpos[L]<400  then  ‘    Notice area
  11. Vx[L]=Vx[L]*0.5                                              ’   speed down
  12. elseIf  LRNotice=”Notice” And  345<Xpos[L]  and Xpos[L]<420  then
  13. Vx[L]=Vx[L]+0.75                                             ‘   speed down
  14. EndIf
  15. ‘———————————————   Red Signal  ——————————————————————————————-
  16. If  LRNotice=”NG” And  365<Xpos[L]  and Xpos[L]<390  then      ‘    Signal = “Red”
  17. Vx[L]=0                                                      ‘   speed down
  18. EndIf
  19. ‘———————————————   car move  // avoid collision   ———————————————————————–
  20. For i=start To end
  21. Shapes.Move(SHP[L][i]["obj"],Shapes.GetLeft(SHP[L][i]["obj"])+Vx[L],Shapes.GetTop(SHP[L][i]["obj"]))
  22. EndFor
  23. X_AvoidCollision()                                             ‘   speed  control
  24. ‘———————————————–   go over left    next position  ————————————————————————-
  25. If 1000+135*L<Xpos[L] Then
  26. RNDX=-(Xpos[L]+ 135*L*2)
  27. For i=start To end
  28. shapes.Move(SHP[L][i]["obj"],Shapes.GetLeft(SHP[L][i]["obj"])+Rndx,Shapes.GetTop(SHP[L][i]["obj"]))
  29. endfor
  30. RNDXSpeed()
  31. endif
  32. EndFor
  33. EndSub
  1. Sub Up_Cars_Moving
  2. DN=0
  3. For L=(2*cars+2) To (3*cars+1)
  4. Ypos[L]=Shapes.Gettop(SHP[L][1]["obj"])
  5. ‘———————————————   Restart  ———————————————————————————————–
  6. If  UDNotice=”OK” And  -2000<Ypos[L] and Vy[L]<0.35 then        ‘    if   signal becomes “Blue”
  7. RNDYSpeed()                                                   ‘   new speed
  8. EndIf
  9. ‘———————————————   Yellow Signal  ——————————————————————————————-
  10. If  UDNotice=”Notice” And RemTime<=3 and  425<Ypos[L]  and Ypos[L]<450  then  ‘    Notice Area
  11. Vy[L]=Vy[L]*0.75                                              ‘   speed down
  12. elseIf  UDNotice=”Notice” And  350<Ypos[L]  and Ypos[L]<440  then  ‘    Signal = “Yellow”
  13. Vy[L]=Vy[L]+0.75                                              ‘   speed down
  14. EndIf
  15. ‘———————————————   Red Signal  ——————————————————————————————-
  16. If  UDNotice=”NG” And  425<Ypos[L]  and Ypos[L]<450  then       ‘    Signal = “Red”
  17. Vy[L]=0                                                       ‘   speed down
  18. EndIf
  19. ‘———————————————   car move  // avoid collision   ———————————————————————–
  20. For i=1 To 8
  21. Shapes.Move(SHP[L][i]["obj"],Shapes.GetLeft(SHP[L][i]["obj"]),Shapes.GetTop(SHP[L][i]["obj"])-VY[L])
  22. EndFor
  23. Y_AvoidCollision()                                              ‘   speed  control
  24. ‘———————————————–   go over left    next position  ————————————————————————-
  25. If Ypos[L]< -135*(L-2*cars) Then
  26. RNDY=600 -Ypos[L]+ 135*(L-2*cars)*2
  27. For i=start To end-1
  28. shapes.Move(SHP[L][i]["obj"],Shapes.GetLeft(SHP[L][i]["obj"]),Shapes.GetTop(SHP[L][i]["obj"])+RNDY)
  29. endfor
  30. RNDYSpeed()
  31. endif
  32. EndFor
  33. EndSub
  1. Sub Down_Cars_Moving
  2. DN=cars
  3. For L=(3*cars+2) To (4*cars+1)
  4. Ypos[L]=Shapes.Gettop(SHP[L][1]["obj"])
  5. ‘———————————————   Restart  ———————————————————————————————–
  6. If  UDNotice=”OK” And  -2000<Ypos[L] and Vy[L]<0.35 then       ‘    if   signal becomes “Blue”
  7. RNDYSpeed()                                                  ‘   new speed
  8. EndIf
  9. ‘———————————————   Yellow Signal  ——————————————————————————————-
  10. If  UDNotice=”Notice” And RemTime<=3 and  180<Ypos[L]  and Ypos[L]<205  then  ‘   Notice Area
  11. Vy[L]=Vy[L]*0.75                                             ’   speed down
  12. elseIf  UDNotice=”Notice” And  165<Ypos[L]  and Ypos[L]<250  then  ‘    Signal = “Yellow”
  13. Vy[L]=Vy[L]+0.75                                             ‘   speed down
  14. EndIf
  15. ‘———————————————   Red Signal  ——————————————————————————————-
  16. If  UDNotice=”NG” And  180<Ypos[L]  and Ypos[L]<205  then      ‘    Signal = “Red”
  17. Vy[L]=0                                                      ’   speed down
  18. EndIf
  19. ‘———————————————   car move  // avoid collision   ———————————————————————–
  20. For i=1 To 8
  21. Shapes.Move(SHP[L][i]["obj"],Shapes.GetLeft(SHP[L][i]["obj"]),Shapes.GetTop(SHP[L][i]["obj"])+VY[L])
  22. EndFor
  23. Y_AvoidCollision()                                             ‘   speed  control
  24. ‘———————————————–   go over left    next position  ————————————————————————-
  25. If Ypos[L]> 700+135*(L-3*cars-1) Then
  26. RNDY=-Ypos[L]- 135*(L-3*cars-1)*2
  27. For i=start To end-1
  28. shapes.Move(SHP[L][i]["obj"],Shapes.GetLeft(SHP[L][i]["obj"]),Shapes.GetTop(SHP[L][i]["obj"])+RNDY)
  29. endfor
  30. RNDYSpeed()
  31. endif
  32. EndFor
  33. EndSub
  1. Sub RemainTime
  2. CycleTime=40                                                ’    LR ; 40 sec   UD ; 40 sec
  3. DT=(Clock.ElapsedMilliseconds-t0)/1000                      ‘   Elapsed time ;  sec
  4. RemTime=text.GetSubText(1000+math.round(CycleTime-DT),2,3)  ‘   Remained time  ( Count down)
  5. For k=21 To 24
  6. Shapes.SetText( SHP[1][K]["obj"],RemTime)                 ‘   show  remained time
  7. EndFor
  8. If (CycleTime/2>DT and DT>=CycleTime/2-10)  Then            ‘   LR trafic  ;  Yellow signal blinking
  9. blink_LR_Yellow()
  10. elseIf (CycleTime>DT and DT>=CycleTime-10)  Then            ’   UD trafic  ;  Yellow signal blinking
  11. blink_UD_Yellow()
  12. elseIf CycleTime/2+1>DT and DT>=CycleTime/2 Then            ‘  UD trafic  ;  Can Go !  Signals for UD  :Blue
  13. UD_Trafic_Go()
  14. elseIf CycleTime+1>DT and DT>=CycleTime Then                ’  LR trafic  ;  Can Go !   Signals for LR  :Blue
  15. LR_Trafic_Go()
  16. t0= Clock.ElapsedMilliseconds                             ‘  CycleTime reset
  17. DT=0
  18. EndIf
  19. endsub
  1. Sub LR_Trafic_Go
  2. LRNotice=”OK”
  3. UDNotice=”NG”
  4. ON["R"]=”1=1;2=1;3=0;4=0″
  5. ON["Y"]=”1=0;2=0;3=0;4=0″
  6. ON["B"]=”1=0;2=0;3=1;4=1″
  7. LightON()
  8. endsub
  1. Sub blink_LR_Yellow
  2. LRNotice=”Notice”
  3. UDNotice=”NG”
  4. ON["R"]=”1=1;2=1;3=0;4=0″
  5. ON["Y"]=”1=0;2=0;3=1;4=1″   ‘  for  LR
  6. ON["B"]=”1=0;2=0;3=0;4=0″
  7. LightON()
  8. Program.Delay(20)
  9. ON["Y"]=”1=0;2=0;3=0;4=0″   ‘
  10. LightON()
  11. EndSub
  1. Sub blink_UD_Yellow
  2. LRNotice=”NG”
  3. UDNotice=”Notice”
  4. ON["R"]=”1=0;2=0;3=1;4=1″
  5. ON["Y"]=”1=1;2=1;3=0;4=0″  ‘  for UD
  6. ON["B"]=”1=0;2=0;3=0;4=0″
  7. LightON()
  8. Program.Delay(20)
  9. ON["Y"]=”1=0;2=0;3=0;4=0″   ‘
  10. LightON()
  11. EndSub
  1. Sub UD_Trafic_Go
  2. LRNotice=”NG”
  3. UDNotice=”OK”
  4. ON["R"]=”1=0;2=0;3=1;4=1″
  5. ON["Y"]=”1=0;2=0;3=0;4=0″
  6. ON["B"]=”1=1;2=1;3=0;4=0″
  7. LightON()
  8. endsub
  1. Sub AllClear
  2. ON["R"]=”1=0;2=0;3=0;4=0″
  3. ON["Y"]=”1=0;2=0;3=0;4=0″
  4. ON["B"]=”1=0;2=0;3=0;4=0″
  5. LightON()
  6. endsub
  1. Sub LightON
  2. For k=1 To 4     ‘  1,2   Left  Upper &  Right Lower    3 ,4  Right  Upper &  Left Lower
  3. shapes.SetOpacity(SHP[1][5*(K-1)+3]["obj"],10+90*ON["R"][K])  ‘  Red
  4. shapes.SetOpacity(SHP[1][5*(K-1)+4]["obj"],10+90*ON["Y"][K])  ‘  Yellow
  5. shapes.SetOpacity(SHP[1][5*(K-1)+5]["obj"],10+90*ON["B"][K])  ‘  Blue
  6. endfor
  7. EndSub
  1. Sub Shapes_Init
  2. X0 = 250  ‘ x offset
  3. Y0 = 150  ‘ y offset
  4. ‘———————————————————————————————————————-
  5. shp[1][1] = “func=rect;x=213;y=50;width=26;height=85;bc=#3B9440;pc=#3B9440;pw=2;”   ‘  Left  Upper
  6. shp[1][2] = “func=rect;x=224;y=135;width=8;height=16;bc=#000000;pc=#000000;pw=2;”   ‘  Pole
  7. shp[1][3] = “func=ell;x=220;y=80;width=14;height=15;bc=#FF0000;pc=#FF0000;pw=2;”    ‘  Red
  8. shp[1][4] = “func=ell;x=220;y=98;width=14;height=15;bc=#FFFF00;pc=#FFFF00;pw=2;”    ‘  Yellow
  9. shp[1][5] = “func=ell;x=220;y=116;width=14;height=14;bc=#0000FF;pc=#0000FF;pw=2;”   ‘  Blue
  10. ‘———————————————————————————————————————-
  11. shp[1][6] = “func=rect;x=364;y=269;width=26;height=85;bc=#3B9440;pc=#3B9440;pw=2;”  ‘  Right Lower
  12. shp[1][7] = “func=rect;x=373;y=252;width=8;height=16;bc=#000000;pc=#000000;pw=2;”
  13. shp[1][8] = “func=ell;x=371;y=310;width=14;height=14;bc=#FF0000;pc=#FF0000;pw=2;”   ‘  Red
  14. shp[1][9] = “func=ell;x=371;y=292;width=14;height=14;bc=#FFFF00;pc=#FFFF00;pw=2;”   ‘  Yellow
  15. shp[1][10] = “func=ell;x=371;y=274;width=14;height=14;bc=#0000FF;pc=#0000FF;pw=2;”  ‘  Blue
  16. ‘———————————————————————————————————————-
  17. shp[1][11] = “func=rect;x=378;y=116;width=85;height=20;bc=#3B9440;pc=#3B9440;pw=2;”  ‘  Right Upper
  18. shp[1][12] = “func=rect;x=355;y=124;width=22;height=8;bc=#000000;pc=#000000;pw=2;”
  19. shp[1][13] = “func=ell;x=418;y=119;width=14;height=14;bc=#FF0000;pc=#FF0000;pw=2;”   ‘  Red
  20. shp[1][14] = “func=ell;x=400;y=119;width=14;height=14;bc=#FFFF00;pc=#FFFF00;pw=2;”   ‘  Yellow
  21. shp[1][15] = “func=ell;x=382;y=119;width=14;height=14;bc=#0000FF;pc=#0000FF;pw=2;”   ‘  Blue
  22. ‘———————————————————————————————————————-
  23. shp[1][16] = “func=rect;x=145;y=259;width=85;height=24;bc=#3B9440;pc=#3B9440;pw=2;”  ‘  Left  Lower
  24. shp[1][17] = “func=rect;x=231;y=267;width=16;height=8;bc=#000000;pc=#000000;pw=2;”
  25. shp[1][18] = “func=ell;x=177;y=263;width=14;height=14;bc=#FF0000;pc=#FF0000;pw=2;”   ‘  Red
  26. shp[1][19] = “func=ell;x=194;y=263;width=14;height=14;bc=#FFFF00;pc=#FFFF00;pw=2;”   ‘  Yellow
  27. shp[1][20] = “func=ell;x=213;y=263;width=14;height=14;bc=#0000FF;pc=#0000FF;pw=2;”   ‘  Blue
  28. ‘———————————————————————————————————————-
  29. shp[1][21] = “func=text;x=216;y=60;text=120;bc=#FF0000;fs=14;fn=Coulier New;”        ‘   Remaining time  #1  Left Upper
  30. shp[1][22] = “func=text;x=366;y=330;text=120;bc=#FF0000;fs=14;fn=Coulier New;”       ‘   Remaining time  #1  Right Lower
  31. shp[1][23] = “func=text;x=438;y=116;text=120;bc=#FF0000;fs=14;fn=Coulier New;”        ‘   Remaining time  #2  Right Upper
  32. shp[1][24] = “func=text;x=151;y=262;text=120;bc=#FF0000;fs=14;fn=Coulier New;”        ‘   Remaining time  #1  Left Lowerer
  33. EndSub
  1. Sub shapecars
  2. ‘————————————–  Left oriented cars ——————————————————————————–
  3. s=0.55
  4. start=1
  5. End=9
  6. cars=5
  7. For L=2 To (cars+1)
  8. shp[L][1] = “func=rect;x=4;y=23;width=130;height=25;bc=#00F0CA;pc=#000000;pw=2;”
  9. shp[L][2] = “func=ell;x=20;y=33;width=23;height=23;bc=#9D756A;pc=#000000;pw=2;”
  10. shp[L][3] = “func=ell;x=95;y=32;width=23;height=23;bc=#9D756A;pc=#000000;pw=2;”
  11. shp[L][4] = “func=rect;x=48;y=2;width=54;height=23;bc=#E0F0CA;pc=#000000;pw=2;”
  12. shp[L][5] = “func=tri;x=41;y=5;x1=7;y1=0;x2=0;y2=17;x3=15;y3=17;bc=#E0F0CA;pc=#E0F0CA;pw=2;”
  13. shp[L][6] = “func=tri;x=91;y=5;x1=9;y1=0;x2=0;y2=17;x3=18;y3=17;bc=#E0F0CA;pc=#E0F0CA;pw=2;”
  14. shp[L][7] = “func=ell;x=0;y=26;width=11;height=12;bc=#FFFF00;pc=#FF0000;pw=2;”
  15. shp[L][8] = “func=ell;x=58;y=5;width=10;height=15;bc=#6A5ACD;pc=#6A5ACD;pw=4;”
  16. shp[L][9] = “func=text;x=80;y=5;text=”+(L-1)+”;bc=#FF0000;fs=22;fn=Coulier New;”
  17. Shapes_Add()
  18. For i=start To end
  19. shapes.Move(SHP[L][i]["obj"],Shapes.GetLeft(SHP[L][i]["obj"])+700+(L-2)*160,Shapes.GetTop(SHP[L][i]["obj"])+210)
  20. EndFor
  21. RNDXSpeed()
  22. EndFor
  23. ‘————————————– Right oriented cars ——————————————————————————–
  24. For L=(cars+2) To (2*cars+1)
  25. shp[L][1] = “func=rect;x=6;y=83;width=130;height=25;bc=#E000CA;pc=#000000;pw=2;”
  26. shp[L][2] = “func=ell;x=20;y=93;width=23;height=23;bc=#9D756A;pc=#000000;pw=2;”
  27. shp[L][3] = “func=ell;x=95;y=92;width=23;height=23;bc=#9D756A;pc=#000000;pw=2;”
  28. shp[L][4] = “func=rect;x=48;y=62;width=54;height=23;bc=#E0F0CA;pc=#000000;pw=2;”
  29. shp[L][5] = “func=tri;x=41;y=65;x1=7;y1=0;x2=0;y2=17;x3=15;y3=17;bc=#E0F0CA;pc=#E0F0CA;pw=2;”
  30. shp[L][6] = “func=tri;x=91;y=65;x1=9;y1=0;x2=0;y2=17;x3=18;y3=17;bc=#E0F0CA;pc=#E0F0CA;pw=2;”
  31. shp[L][7] = “func=ell;x=128;y=86;width=11;height=12;bc=#FFFF00;pc=#FF0000;pw=2;”
  32. shp[L][8] = “func=ell;x=85;y=61;width=10;height=15;bc=#6A5ACD;pc=#6A5ACD;pw=4;”
  33. shp[L][9] = “func=text;x=60;y=60;text=”+(L-cars-1)+”;bc=#FF0000;fs=22;fn=Coulier New;”
  34. Shapes_Add()
  35. For i=start To end
  36. shapes.Move(SHP[L][i]["obj"],Shapes.GetLeft(SHP[L][i]["obj"])-200-(L-cars-2)*160,Shapes.GetTop(SHP[L][i]["obj"])+125)
  37. EndFor
  38. RNDXSpeed()
  39. EndFor
  40. ‘—————————————Up oriented cars ——————————————————————————-
  41. end2=8
  42. For L=(2*cars+2) To (3*cars+1)
  43. shp[L][1] = “func=ell;x=2;y=0;width=34;height=93;bc=#DBD229;pc=#DBD229;pw=2;”
  44. shp[L][2] = “func=ell;x=2;y=7;width=11;height=7;bc=#FF0000;pc=#FF0000;pw=2;”
  45. shp[L][3] = “func=ell;x=25;y=7;width=11;height=7;bc=#FF0000;pc=#FF0000;pw=2;”
  46. shp[L][4] = “func=rect;x=31;y=19;width=6;height=14;bc=#000000;pc=#6A5ACD;pw=2;”
  47. shp[L][5] = “func=rect;x=1;y=19;width=6;height=14;bc=#000000;pc=#6A5ACD;pw=2;”
  48. shp[L][6] = “func=rect;x=0;y=60;width=6;height=14;bc=#000000;pc=#6A5ACD;pw=2;”
  49. shp[L][7] = “func=rect;x=31;y=60;width=6;height=14;bc=#000000;pc=#6A5ACD;pw=2;”
  50. shp[L][8] = “func=text;x=12;y=35;text=”+(L-2*cars-1)+”;bc=#FF0000;fs=22;fn=Coulier New;”
  51. Shapes_Add()
  52. For i=start To end2
  53. shapes.Move(SHP[L][i]["obj"],Shapes.GetLeft(SHP[L][i]["obj"])+260,Shapes.GetTop(SHP[L][i]["obj"])+500+(L-(2*cars+2))*160)
  54. EndFor
  55. RNDYSpeed()
  56. EndFor
  57. ‘—————————————Down oriented cars ——————————————————————————-
  58. For L=(3*cars+2) To (4*cars+1)
  59. shp[L][1] = “func=ell;x=2;y=0;width=34;height=93;bc=#E090CA;pc=#DBD229;pw=2;”
  60. shp[L][2] = “func=ell;x=2;y=77;width=11;height=7;bc=#FF0000;pc=#FF0000;pw=2;”
  61. shp[L][3] = “func=ell;x=25;y=77;width=11;height=7;bc=#FF0000;pc=#FF0000;pw=2;”
  62. shp[L][4] = “func=rect;x=31;y=19;width=6;height=14;bc=#000000;pc=#6A5ACD;pw=2;”
  63. shp[L][5] = “func=rect;x=1;y=19;width=6;height=14;bc=#000000;pc=#6A5ACD;pw=2;”
  64. shp[L][6] = “func=rect;x=0;y=60;width=6;height=14;bc=#000000;pc=#6A5ACD;pw=2;”
  65. shp[L][7] = “func=rect;x=31;y=60;width=6;height=14;bc=#000000;pc=#6A5ACD;pw=2;”
  66. shp[L][8] = “func=text;x=12;y=40;text=”+(L-3*cars-1)+”;bc=#FF0000;fs=22;fn=Coulier New;”
  67. Shapes_Add()
  68. For i=start To end2
  69. shapes.Move(SHP[L][i]["obj"],Shapes.GetLeft(SHP[L][i]["obj"])+320,Shapes.GetTop(SHP[L][i]["obj"])-130-( L – (3*cars+2) )*160)
  70. EndFor
  71. RNDYSpeed()
  72. EndFor
  73. ‘ ‘———————————————————————————————————————-
  74. GraphicsWindow.Show()
  75. t0= Clock.ElapsedMilliseconds   ‘   start tim
  76. EndSub
  1. Sub GUI
  2. GraphicsWindow.Title=” Trafic Signals and Car action  “
  3. GraphicsWindow.top=10
  4. GraphicsWindow.Left=20
  5. GraphicsWindow.Hide()
  6. GraphicsWindow.Width=1200
  7. GraphicsWindow.Height=700
  8. GraphicsWindow.BackgroundColor=”DarkGreen”
  9. GraphicsWindow.BrushColor=”Gray”
  10. GraphicsWindow.PenColor=”Gray”
  11. GraphicsWindow.FillEllipse(50,-50,1000,770)
  12. GraphicsWindow.BrushColor=”DarkGreen”
  13. GraphicsWindow.PenColor=”DarkGreen”
  14. GraphicsWindow.FillEllipse(100,-10,900,680)
  15. GraphicsWindow.BrushColor=”Gray”
  16. GraphicsWindow.PenColor=”Gray”
  17. GraphicsWindow.FillRectangle(-100,300,1400,100)
  18. GraphicsWindow.FillRectangle(500,-100,100,1000)
  1. GraphicsWindow.BrushColor=”White”
  2. GraphicsWindow.PenColor=”White”
  3. For i=1 To 20
  4. GraphicsWindow.FillRectangle(30+(i-1)*100,350-5,30,5)
  5. GraphicsWindow.FillRectangle(550,-30+(i-1)*80,5,30)
  6. endfor
  7. GraphicsWindow.FillRectangle(475,300,5,30)
  8. GraphicsWindow.FillRectangle(625,370,5,30)
  9. GraphicsWindow.FillRectangle(500,418,35,5)
  10. GraphicsWindow.FillRectangle(565,275,35,5)
  11. STPX=”1=475;2=625;3=500;4=565″      ‘  stop Line
  12. STPY=”1=300;2=370;3=418;4=275″
  13. ‘———————————————————————————————————————-
  14. s=1
  15. L=1
  16. start=1
  17. End=24
  18. Shapes_Add()
  19. AllClear()
  20. LR_Trafic_Go()
  21. EndSub
  1. Sub shapes_Add
  2. For i = start To End
  3. GraphicsWindow.PenWidth = SHP[L][i]["pw"]*s
  4. GraphicsWindow.PenColor = SHP[L][i]["pc"]
  5. GraphicsWindow.BrushColor = SHP[L][i]["bc"]
  6. If SHP[L][i]["func"] = “rect” Then
  7. SHP[L][i]["obj"] = Shapes.AddRectangle(SHP[L][i]["width"]*s, SHP[L][i]["height"]*s)
  8. ElseIf SHP[L][i]["func"] = “ell” Then
  9. SHP[L][i]["obj"] = Shapes.AddEllipse(SHP[L][i]["width"]*s, SHP[L][i]["height"]*s)
  10. ElseIf SHP[L][i]["func"] = “tri” Then
  11. SHP[L][i]["obj"] = Shapes.AddTriangle(SHP[L][i]["x1"]*s, SHP[L][i]["y1"]*s, SHP[L][i]["x2"]*s, SHP[L][i]["y2"]*s, SHP[L][i]["x3"]*s, SHP[L][i]["y3"]*s)
  12. ElseIf shp[L][i]["func"] = “text” Then
  13. fs = shp[L][i]["fs"]
  14. GraphicsWindow.FontSize = fs * s
  15. GraphicsWindow.FontName = shp[L][i]["fn"]
  16. shp[L][i]["obj"] = Shapes.AddText(shp[L][i]["text"])
  17. EndIf
        Shapes.Move(SHP[L][i]["obj"], X0 + SHP[L][i]["x"]*s, Y0 + SHP[L][i]["y"]*s)
     EndFor
   Endsub