Skip to content

Instantly share code, notes, and snippets.

@danbst
Last active Oct 3, 2021
Embed
What would you like to do?
Attempt to implement BeamNG.drive in python turtle
{"test1": [[[-50.0, 0, 0], [-50.0, 83.0, 1.0], [-50.0, 85.0, 32.0], [-50.0, 51.0, 35.0], [-38.167938931297705, 47.0, 131.0], [-38.167938931297705, 52.0, 131.0], [-28.571428571428573, 57.0, 175.0], [-29.239766081871345, 51.0, 171.0], [-37.31343283582089, 45.0, 134.0], [-28.901734104046245, 50.0, 173.0], [-25.641025641025642, 50.0, 195.0], [-25.380710659898476, -9.0, 197.0], [-34.96503496503497, -14.0, 143.0], [-50.0, -10.0, 43.0], [-50.0, -56.0, 43.0], [-50.0, -49.0, -2.0], [-50.0, -17.0, -4.0], [-50.0, -13.0, 20.0], [-50.0, 42.0, 22.0], [-50.0, 44.0, -5.0], [-50.0, 82.0, -0.0]], [[50.0, 0, 0], [50.0, 83.0, 1.0], [50.0, 85.0, 32.0], [50.0, 51.0, 35.0], [38.167938931297705, 47.0, 131.0], [38.167938931297705, 52.0, 131.0], [28.571428571428573, 57.0, 175.0], [29.239766081871345, 51.0, 171.0], [37.31343283582089, 45.0, 134.0], [28.901734104046245, 50.0, 173.0], [25.641025641025642, 50.0, 195.0], [25.380710659898476, -9.0, 197.0], [34.96503496503497, -14.0, 143.0], [50.0, -10.0, 43.0], [50.0, -56.0, 43.0], [50.0, -49.0, -2.0], [50.0, -17.0, -4.0], [50.0, -13.0, 20.0], [50.0, 42.0, 22.0], [50.0, 44.0, -5.0], [50.0, 82.0, -0.0]], [[-50.0, 0, 0], [50.0, 0, 0]], [[-50.0, 83.0, 1.0], [50.0, 83.0, 1.0]], [[-50.0, 85.0, 32.0], [50.0, 85.0, 32.0]], [[-50.0, 51.0, 35.0], [50.0, 51.0, 35.0]], [[-38.167938931297705, 47.0, 131.0], [38.167938931297705, 47.0, 131.0]], [[-38.167938931297705, 52.0, 131.0], [38.167938931297705, 52.0, 131.0]], [[-28.571428571428573, 57.0, 175.0], [28.571428571428573, 57.0, 175.0]], [[-29.239766081871345, 51.0, 171.0], [29.239766081871345, 51.0, 171.0]], [[-37.31343283582089, 45.0, 134.0], [37.31343283582089, 45.0, 134.0]], [[-28.901734104046245, 50.0, 173.0], [28.901734104046245, 50.0, 173.0]], [[-25.641025641025642, 50.0, 195.0], [25.641025641025642, 50.0, 195.0]], [[-25.380710659898476, -9.0, 197.0], [25.380710659898476, -9.0, 197.0]], [[-34.96503496503497, -14.0, 143.0], [34.96503496503497, -14.0, 143.0]], [[-50.0, -10.0, 43.0], [50.0, -10.0, 43.0]], [[-50.0, -56.0, 43.0], [50.0, -56.0, 43.0]], [[-50.0, -49.0, -2.0], [50.0, -49.0, -2.0]], [[-50.0, -17.0, -4.0], [50.0, -17.0, -4.0]], [[-50.0, -13.0, 20.0], [50.0, -13.0, 20.0]], [[-50.0, 42.0, 22.0], [50.0, 42.0, 22.0]], [[-50.0, 44.0, -5.0], [50.0, 44.0, -5.0]], [[-50.0, 82.0, -0.0], [50.0, 82.0, -0.0]]], "test2": [[[-50.0, 0, 0], [-50.0, 81.0, 5.0], [-50.0, 80.0, 28.0], [-50.0, 84.0, 27.0], [-50.0, 58.0, 29.0], [-50.0, 36.0, 32.0], [-50.0, 43.0, 58.0], [-32.89473684210526, 42.0, 152.0], [-42.016806722689076, 42.0, 119.0], [-28.735632183908045, 41.0, 174.0], [-25.380710659898476, 43.0, 197.0], [-28.40909090909091, 48.0, 176.0], [-34.24657534246575, 41.0, 146.0], [-25.77319587628866, 39.0, 194.0], [-25.12562814070352, -25.0, 199.0], [-28.40909090909091, 11.0, 176.0], [-33.78378378378378, -27.0, 148.0], [-50.0, -11.0, 37.0], [-50.0, -58.0, 33.0], [-50.0, -47.0, -5.0], [-50.0, -8.0, -6.0], [-50.0, -5.0, 18.0], [-50.0, 6.0, 24.0], [-50.0, 18.0, 25.0], [-50.0, 46.0, 6.0], [-50.0, 66.0, 5.0], [-50.0, 81.0, 5.0]], [[50.0, 0, 0], [50.0, 81.0, 5.0], [50.0, 80.0, 28.0], [50.0, 84.0, 27.0], [50.0, 58.0, 29.0], [50.0, 36.0, 32.0], [50.0, 43.0, 58.0], [32.89473684210526, 42.0, 152.0], [42.016806722689076, 42.0, 119.0], [28.735632183908045, 41.0, 174.0], [25.380710659898476, 43.0, 197.0], [28.40909090909091, 48.0, 176.0], [34.24657534246575, 41.0, 146.0], [25.77319587628866, 39.0, 194.0], [25.12562814070352, -25.0, 199.0], [28.40909090909091, 11.0, 176.0], [33.78378378378378, -27.0, 148.0], [50.0, -11.0, 37.0], [50.0, -58.0, 33.0], [50.0, -47.0, -5.0], [50.0, -8.0, -6.0], [50.0, -5.0, 18.0], [50.0, 6.0, 24.0], [50.0, 18.0, 25.0], [50.0, 46.0, 6.0], [50.0, 66.0, 5.0], [50.0, 81.0, 5.0]], [[-50.0, 0, 0], [50.0, 0, 0]], [[-50.0, 81.0, 5.0], [50.0, 81.0, 5.0]], [[-50.0, 80.0, 28.0], [50.0, 80.0, 28.0]], [[-50.0, 84.0, 27.0], [50.0, 84.0, 27.0]], [[-50.0, 58.0, 29.0], [50.0, 58.0, 29.0]], [[-50.0, 36.0, 32.0], [50.0, 36.0, 32.0]], [[-50.0, 43.0, 58.0], [50.0, 43.0, 58.0]], [[-32.89473684210526, 42.0, 152.0], [32.89473684210526, 42.0, 152.0]], [[-42.016806722689076, 42.0, 119.0], [42.016806722689076, 42.0, 119.0]], [[-28.735632183908045, 41.0, 174.0], [28.735632183908045, 41.0, 174.0]], [[-25.380710659898476, 43.0, 197.0], [25.380710659898476, 43.0, 197.0]], [[-28.40909090909091, 48.0, 176.0], [28.40909090909091, 48.0, 176.0]], [[-34.24657534246575, 41.0, 146.0], [34.24657534246575, 41.0, 146.0]], [[-25.77319587628866, 39.0, 194.0], [25.77319587628866, 39.0, 194.0]], [[-25.12562814070352, -25.0, 199.0], [25.12562814070352, -25.0, 199.0]], [[-28.40909090909091, 11.0, 176.0], [28.40909090909091, 11.0, 176.0]], [[-33.78378378378378, -27.0, 148.0], [33.78378378378378, -27.0, 148.0]], [[-50.0, -11.0, 37.0], [50.0, -11.0, 37.0]], [[-50.0, -58.0, 33.0], [50.0, -58.0, 33.0]], [[-50.0, -47.0, -5.0], [50.0, -47.0, -5.0]], [[-50.0, -8.0, -6.0], [50.0, -8.0, -6.0]], [[-50.0, -5.0, 18.0], [50.0, -5.0, 18.0]], [[-50.0, 6.0, 24.0], [50.0, 6.0, 24.0]], [[-50.0, 18.0, 25.0], [50.0, 18.0, 25.0]], [[-50.0, 46.0, 6.0], [50.0, 46.0, 6.0]], [[-50.0, 66.0, 5.0], [50.0, 66.0, 5.0]], [[-50.0, 81.0, 5.0], [50.0, 81.0, 5.0]]], "car2": [[[-50.0, 0, 0], [-50.0, 242.0, 4.0], [-50.0, 235.0, 26.0], [-50.0, 108.0, 46.0], [-50.0, 70.0, 83.0], [-50.0, 15.0, 83.0], [-50.0, -63.0, 59.0], [-50.0, -84.0, 27.0], [-50.0, -87.0, -0.0], [-50.0, -58.0, 2.0], [-50.0, -53.0, 26.0], [-50.0, -37.0, 39.0], [-50.0, -15.0, 34.0], [-50.0, -3.0, 27.0], [-50.0, 0.0, 12.0], [-50.0, 10.0, 5.0], [-50.0, 31.0, 4.0], [-50.0, 63.0, 3.0], [-50.0, 83.0, 3.0], [-50.0, 110.0, -1.0], [-50.0, 138.0, -4.0], [-50.0, 167.0, -5.0], [-50.0, 171.0, 22.0], [-50.0, 191.0, 23.0], [-50.0, 212.0, 17.0], [-50.0, 232.0, 9.0], [-50.0, 238.0, -8.0]], [[50.0, 0, 0], [50.0, 242.0, 4.0], [50.0, 235.0, 26.0], [50.0, 108.0, 46.0], [50.0, 70.0, 83.0], [50.0, 15.0, 83.0], [50.0, -63.0, 59.0], [50.0, -84.0, 27.0], [50.0, -87.0, -0.0], [50.0, -58.0, 2.0], [50.0, -53.0, 26.0], [50.0, -37.0, 39.0], [50.0, -15.0, 34.0], [50.0, -3.0, 27.0], [50.0, 0.0, 12.0], [50.0, 10.0, 5.0], [50.0, 31.0, 4.0], [50.0, 63.0, 3.0], [50.0, 83.0, 3.0], [50.0, 110.0, -1.0], [50.0, 138.0, -4.0], [50.0, 167.0, -5.0], [50.0, 171.0, 22.0], [50.0, 191.0, 23.0], [50.0, 212.0, 17.0], [50.0, 232.0, 9.0], [50.0, 238.0, -8.0]], [[-50.0, 0, 0], [50.0, 0, 0]], [[-50.0, 242.0, 4.0], [50.0, 242.0, 4.0]], [[-50.0, 235.0, 26.0], [50.0, 235.0, 26.0]], [[-50.0, 108.0, 46.0], [50.0, 108.0, 46.0]], [[-50.0, 70.0, 83.0], [50.0, 70.0, 83.0]], [[-50.0, 15.0, 83.0], [50.0, 15.0, 83.0]], [[-50.0, -63.0, 59.0], [50.0, -63.0, 59.0]], [[-50.0, -84.0, 27.0], [50.0, -84.0, 27.0]], [[-50.0, -87.0, -0.0], [50.0, -87.0, -0.0]], [[-50.0, -58.0, 2.0], [50.0, -58.0, 2.0]], [[-50.0, -53.0, 26.0], [50.0, -53.0, 26.0]], [[-50.0, -37.0, 39.0], [50.0, -37.0, 39.0]], [[-50.0, -15.0, 34.0], [50.0, -15.0, 34.0]], [[-50.0, -3.0, 27.0], [50.0, -3.0, 27.0]], [[-50.0, 0.0, 12.0], [50.0, 0.0, 12.0]], [[-50.0, 10.0, 5.0], [50.0, 10.0, 5.0]], [[-50.0, 31.0, 4.0], [50.0, 31.0, 4.0]], [[-50.0, 63.0, 3.0], [50.0, 63.0, 3.0]], [[-50.0, 83.0, 3.0], [50.0, 83.0, 3.0]], [[-50.0, 110.0, -1.0], [50.0, 110.0, -1.0]], [[-50.0, 138.0, -4.0], [50.0, 138.0, -4.0]], [[-50.0, 167.0, -5.0], [50.0, 167.0, -5.0]], [[-50.0, 171.0, 22.0], [50.0, 171.0, 22.0]], [[-50.0, 191.0, 23.0], [50.0, 191.0, 23.0]], [[-50.0, 212.0, 17.0], [50.0, 212.0, 17.0]], [[-50.0, 232.0, 9.0], [50.0, 232.0, 9.0]], [[-50.0, 238.0, -8.0], [50.0, 238.0, -8.0]]], "piramid": [[[-50.0, 0, 0], [-50.0, 260.0, 9.0], [-50.0, 258.0, 33.0], [-50.0, 221.0, 30.0], [-50.0, 222.0, 66.0], [-50.0, 192.0, 67.0], [-48.07692307692307, 183.0, 104.0], [-46.72897196261682, 148.0, 107.0], [-36.231884057971016, 144.0, 138.0], [-34.96503496503497, 111.0, 143.0], [-30.303030303030305, 108.0, 165.0], [-28.901734104046245, 73.0, 173.0], [-23.696682464454977, 70.0, 211.0], [-23.041474654377883, 28.0, 217.0], [-20.833333333333336, 26.0, 240.0], [-20.408163265306122, -11.0, 245.0], [-23.255813953488374, -11.0, 215.0], [-22.727272727272727, -47.0, 220.0], [-26.881720430107524, -47.0, 186.0], [-26.7379679144385, -98.0, 187.0], [-33.11258278145695, -96.0, 151.0], [-33.78378378378378, -149.0, 148.0], [-48.543689320388346, -142.0, 103.0], [-44.64285714285714, -193.0, 112.0], [-50.0, -187.0, 58.0], [-50.0, -234.0, 48.0], [-50.0, -225.0, 5.0], [-50.0, 256.0, 6.0]], [[50.0, 0, 0], [50.0, 260.0, 9.0], [50.0, 258.0, 33.0], [50.0, 221.0, 30.0], [50.0, 222.0, 66.0], [50.0, 192.0, 67.0], [48.07692307692307, 183.0, 104.0], [46.72897196261682, 148.0, 107.0], [36.231884057971016, 144.0, 138.0], [34.96503496503497, 111.0, 143.0], [30.303030303030305, 108.0, 165.0], [28.901734104046245, 73.0, 173.0], [23.696682464454977, 70.0, 211.0], [23.041474654377883, 28.0, 217.0], [20.833333333333336, 26.0, 240.0], [20.408163265306122, -11.0, 245.0], [23.255813953488374, -11.0, 215.0], [22.727272727272727, -47.0, 220.0], [26.881720430107524, -47.0, 186.0], [26.7379679144385, -98.0, 187.0], [33.11258278145695, -96.0, 151.0], [33.78378378378378, -149.0, 148.0], [48.543689320388346, -142.0, 103.0], [44.64285714285714, -193.0, 112.0], [50.0, -187.0, 58.0], [50.0, -234.0, 48.0], [50.0, -225.0, 5.0], [50.0, 256.0, 6.0]], [[-50.0, 0, 0], [50.0, 0, 0]], [[-50.0, 260.0, 9.0], [50.0, 260.0, 9.0]], [[-50.0, 258.0, 33.0], [50.0, 258.0, 33.0]], [[-50.0, 221.0, 30.0], [50.0, 221.0, 30.0]], [[-50.0, 222.0, 66.0], [50.0, 222.0, 66.0]], [[-50.0, 192.0, 67.0], [50.0, 192.0, 67.0]], [[-48.07692307692307, 183.0, 104.0], [48.07692307692307, 183.0, 104.0]], [[-46.72897196261682, 148.0, 107.0], [46.72897196261682, 148.0, 107.0]], [[-36.231884057971016, 144.0, 138.0], [36.231884057971016, 144.0, 138.0]], [[-34.96503496503497, 111.0, 143.0], [34.96503496503497, 111.0, 143.0]], [[-30.303030303030305, 108.0, 165.0], [30.303030303030305, 108.0, 165.0]], [[-28.901734104046245, 73.0, 173.0], [28.901734104046245, 73.0, 173.0]], [[-23.696682464454977, 70.0, 211.0], [23.696682464454977, 70.0, 211.0]], [[-23.041474654377883, 28.0, 217.0], [23.041474654377883, 28.0, 217.0]], [[-20.833333333333336, 26.0, 240.0], [20.833333333333336, 26.0, 240.0]], [[-20.408163265306122, -11.0, 245.0], [20.408163265306122, -11.0, 245.0]], [[-23.255813953488374, -11.0, 215.0], [23.255813953488374, -11.0, 215.0]], [[-22.727272727272727, -47.0, 220.0], [22.727272727272727, -47.0, 220.0]], [[-26.881720430107524, -47.0, 186.0], [26.881720430107524, -47.0, 186.0]], [[-26.7379679144385, -98.0, 187.0], [26.7379679144385, -98.0, 187.0]], [[-33.11258278145695, -96.0, 151.0], [33.11258278145695, -96.0, 151.0]], [[-33.78378378378378, -149.0, 148.0], [33.78378378378378, -149.0, 148.0]], [[-48.543689320388346, -142.0, 103.0], [48.543689320388346, -142.0, 103.0]], [[-44.64285714285714, -193.0, 112.0], [44.64285714285714, -193.0, 112.0]], [[-50.0, -187.0, 58.0], [50.0, -187.0, 58.0]], [[-50.0, -234.0, 48.0], [50.0, -234.0, 48.0]], [[-50.0, -225.0, 5.0], [50.0, -225.0, 5.0]], [[-50.0, 256.0, 6.0], [50.0, 256.0, 6.0]]], "bus": [[[-50.0, 0, 0], [-50.0, 345.0, 15.0], [-50.0, 343.0, 69.0], [-37.59398496240601, 318.0, 133.0], [-34.96503496503497, 261.0, 143.0], [-38.167938931297705, 283.0, 131.0], [-50.0, 289.0, 89.0], [-50.0, 217.0, 83.0], [-38.75968992248062, 215.0, 129.0], [-37.59398496240601, 284.0, 133.0], [-34.72222222222222, 259.0, 144.0], [-34.72222222222222, 199.0, 144.0], [-34.96503496503497, 164.0, 143.0], [-38.46153846153846, 179.0, 130.0], [-50.0, 188.0, 88.0], [-50.0, 121.0, 87.0], [-39.682539682539684, 118.0, 126.0], [-38.75968992248062, 178.0, 129.0], [-35.21126760563381, 168.0, 142.0], [-34.72222222222222, 81.0, 144.0], [-38.167938931297705, 89.0, 131.0], [-50.0, 96.0, 92.0], [-50.0, 26.0, 87.0], [-38.75968992248062, 25.0, 129.0], [-37.59398496240601, 89.0, 133.0], [-34.72222222222222, 79.0, 144.0], [-34.72222222222222, -14.0, 144.0], [-34.72222222222222, -77.0, 144.0], [-37.878787878787875, -116.0, 132.0], [-49.504950495049506, -129.0, 101.0], [-50.0, -126.0, 60.0], [-50.0, -123.0, 17.0], [-50.0, -92.0, 10.0], [-50.0, -66.0, 14.0], [-50.0, -43.0, 21.0], [-50.0, -38.0, 51.0], [-50.0, -31.0, 60.0], [-50.0, -9.0, 60.0], [-50.0, 1.0, 54.0], [-50.0, 14.0, 50.0], [-50.0, 29.0, 25.0], [-50.0, 29.0, 15.0], [-50.0, 67.0, 11.0], [-50.0, 142.0, 15.0], [-50.0, 200.0, 15.0], [-50.0, 247.0, 15.0], [-50.0, 247.0, 34.0], [-50.0, 251.0, 38.0], [-50.0, 258.0, 41.0], [-50.0, 276.0, 53.0], [-50.0, 277.0, 54.0], [-50.0, 321.0, 55.0], [-50.0, 320.0, 33.0], [-50.0, 319.0, 19.0], [-50.0, 338.0, 18.0], [-50.0, 345.0, 47.0], [-50.0, 373.0, 49.0], [-50.0, 342.0, 65.0]], [[50.0, 0, 0], [50.0, 345.0, 15.0], [50.0, 343.0, 69.0], [37.59398496240601, 318.0, 133.0], [34.96503496503497, 261.0, 143.0], [38.167938931297705, 283.0, 131.0], [50.0, 289.0, 89.0], [50.0, 217.0, 83.0], [38.75968992248062, 215.0, 129.0], [37.59398496240601, 284.0, 133.0], [34.72222222222222, 259.0, 144.0], [34.72222222222222, 199.0, 144.0], [34.96503496503497, 164.0, 143.0], [38.46153846153846, 179.0, 130.0], [50.0, 188.0, 88.0], [50.0, 121.0, 87.0], [39.682539682539684, 118.0, 126.0], [38.75968992248062, 178.0, 129.0], [35.21126760563381, 168.0, 142.0], [34.72222222222222, 81.0, 144.0], [38.167938931297705, 89.0, 131.0], [50.0, 96.0, 92.0], [50.0, 26.0, 87.0], [38.75968992248062, 25.0, 129.0], [37.59398496240601, 89.0, 133.0], [34.72222222222222, 79.0, 144.0], [34.72222222222222, -14.0, 144.0], [34.72222222222222, -77.0, 144.0], [37.878787878787875, -116.0, 132.0], [49.504950495049506, -129.0, 101.0], [50.0, -126.0, 60.0], [50.0, -123.0, 17.0], [50.0, -92.0, 10.0], [50.0, -66.0, 14.0], [50.0, -43.0, 21.0], [50.0, -38.0, 51.0], [50.0, -31.0, 60.0], [50.0, -9.0, 60.0], [50.0, 1.0, 54.0], [50.0, 14.0, 50.0], [50.0, 29.0, 25.0], [50.0, 29.0, 15.0], [50.0, 67.0, 11.0], [50.0, 142.0, 15.0], [50.0, 200.0, 15.0], [50.0, 247.0, 15.0], [50.0, 247.0, 34.0], [50.0, 251.0, 38.0], [50.0, 258.0, 41.0], [50.0, 276.0, 53.0], [50.0, 277.0, 54.0], [50.0, 321.0, 55.0], [50.0, 320.0, 33.0], [50.0, 319.0, 19.0], [50.0, 338.0, 18.0], [50.0, 345.0, 47.0], [50.0, 373.0, 49.0], [50.0, 342.0, 65.0]], [[-50.0, 0, 0], [50.0, 0, 0]], [[-50.0, 345.0, 15.0], [50.0, 345.0, 15.0]], [[-50.0, 343.0, 69.0], [50.0, 343.0, 69.0]], [[-37.59398496240601, 318.0, 133.0], [37.59398496240601, 318.0, 133.0]], [[-34.96503496503497, 261.0, 143.0], [34.96503496503497, 261.0, 143.0]], [[-38.167938931297705, 283.0, 131.0], [38.167938931297705, 283.0, 131.0]], [[-50.0, 289.0, 89.0], [50.0, 289.0, 89.0]], [[-50.0, 217.0, 83.0], [50.0, 217.0, 83.0]], [[-38.75968992248062, 215.0, 129.0], [38.75968992248062, 215.0, 129.0]], [[-37.59398496240601, 284.0, 133.0], [37.59398496240601, 284.0, 133.0]], [[-34.72222222222222, 259.0, 144.0], [34.72222222222222, 259.0, 144.0]], [[-34.72222222222222, 199.0, 144.0], [34.72222222222222, 199.0, 144.0]], [[-34.96503496503497, 164.0, 143.0], [34.96503496503497, 164.0, 143.0]], [[-38.46153846153846, 179.0, 130.0], [38.46153846153846, 179.0, 130.0]], [[-50.0, 188.0, 88.0], [50.0, 188.0, 88.0]], [[-50.0, 121.0, 87.0], [50.0, 121.0, 87.0]], [[-39.682539682539684, 118.0, 126.0], [39.682539682539684, 118.0, 126.0]], [[-38.75968992248062, 178.0, 129.0], [38.75968992248062, 178.0, 129.0]], [[-35.21126760563381, 168.0, 142.0], [35.21126760563381, 168.0, 142.0]], [[-34.72222222222222, 81.0, 144.0], [34.72222222222222, 81.0, 144.0]], [[-38.167938931297705, 89.0, 131.0], [38.167938931297705, 89.0, 131.0]], [[-50.0, 96.0, 92.0], [50.0, 96.0, 92.0]], [[-50.0, 26.0, 87.0], [50.0, 26.0, 87.0]], [[-38.75968992248062, 25.0, 129.0], [38.75968992248062, 25.0, 129.0]], [[-37.59398496240601, 89.0, 133.0], [37.59398496240601, 89.0, 133.0]], [[-34.72222222222222, 79.0, 144.0], [34.72222222222222, 79.0, 144.0]], [[-34.72222222222222, -14.0, 144.0], [34.72222222222222, -14.0, 144.0]], [[-34.72222222222222, -77.0, 144.0], [34.72222222222222, -77.0, 144.0]], [[-37.878787878787875, -116.0, 132.0], [37.878787878787875, -116.0, 132.0]], [[-49.504950495049506, -129.0, 101.0], [49.504950495049506, -129.0, 101.0]], [[-50.0, -126.0, 60.0], [50.0, -126.0, 60.0]], [[-50.0, -123.0, 17.0], [50.0, -123.0, 17.0]], [[-50.0, -92.0, 10.0], [50.0, -92.0, 10.0]], [[-50.0, -66.0, 14.0], [50.0, -66.0, 14.0]], [[-50.0, -43.0, 21.0], [50.0, -43.0, 21.0]], [[-50.0, -38.0, 51.0], [50.0, -38.0, 51.0]], [[-50.0, -31.0, 60.0], [50.0, -31.0, 60.0]], [[-50.0, -9.0, 60.0], [50.0, -9.0, 60.0]], [[-50.0, 1.0, 54.0], [50.0, 1.0, 54.0]], [[-50.0, 14.0, 50.0], [50.0, 14.0, 50.0]], [[-50.0, 29.0, 25.0], [50.0, 29.0, 25.0]], [[-50.0, 29.0, 15.0], [50.0, 29.0, 15.0]], [[-50.0, 67.0, 11.0], [50.0, 67.0, 11.0]], [[-50.0, 142.0, 15.0], [50.0, 142.0, 15.0]], [[-50.0, 200.0, 15.0], [50.0, 200.0, 15.0]], [[-50.0, 247.0, 15.0], [50.0, 247.0, 15.0]], [[-50.0, 247.0, 34.0], [50.0, 247.0, 34.0]], [[-50.0, 251.0, 38.0], [50.0, 251.0, 38.0]], [[-50.0, 258.0, 41.0], [50.0, 258.0, 41.0]], [[-50.0, 276.0, 53.0], [50.0, 276.0, 53.0]], [[-50.0, 277.0, 54.0], [50.0, 277.0, 54.0]], [[-50.0, 321.0, 55.0], [50.0, 321.0, 55.0]], [[-50.0, 320.0, 33.0], [50.0, 320.0, 33.0]], [[-50.0, 319.0, 19.0], [50.0, 319.0, 19.0]], [[-50.0, 338.0, 18.0], [50.0, 338.0, 18.0]], [[-50.0, 345.0, 47.0], [50.0, 345.0, 47.0]], [[-50.0, 373.0, 49.0], [50.0, 373.0, 49.0]], [[-50.0, 342.0, 65.0], [50.0, 342.0, 65.0]]], "ex": [[[-50.0, 0, 0], [-45.45454545454545, 276.0, 110.0], [-50.0, 286.0, 79.0], [-50.0, 334.0, 75.0], [-38.75968992248062, 344.0, 129.0], [-36.4963503649635, 323.0, 137.0], [-17.73049645390071, 288.0, 282.0], [-18.38235294117647, 283.0, 272.0], [-17.921146953405017, 78.0, 279.0], [-28.901734104046245, -29.0, 173.0], [-37.59398496240601, -29.0, 133.0], [-34.24657534246575, -139.0, 146.0], [-50.0, -145.0, -1.0], [-50.0, -91.0, 9.0], [-50.0, -82.0, 53.0], [-50.0, -74.0, 57.0], [-50.0, -51.0, 64.0], [-50.0, -22.0, 61.0], [-50.0, -20.0, 40.0], [-50.0, -2.0, 7.0], [-50.0, 22.0, 3.0], [-50.0, 26.0, 41.0], [-50.0, 26.0, 51.0], [-50.0, 27.0, 64.0], [-50.0, 69.0, 71.0], [-50.0, 72.0, 58.0], [-50.0, 73.0, 24.0], [-50.0, 77.0, 5.0], [-50.0, 96.0, 3.0], [-50.0, 105.0, 93.0], [-49.01960784313725, 73.0, 102.0], [-29.069767441860467, 51.0, 172.0], [-28.40909090909091, 20.0, 176.0], [-48.07692307692307, 18.0, 104.0], [-37.03703703703704, -9.0, 135.0], [-30.120481927710845, -6.0, 166.0], [-18.939393939393938, 88.0, 264.0], [-17.73049645390071, 77.0, 282.0], [-19.37984496124031, 92.0, 258.0], [-19.53125, 268.0, 256.0], [-18.181818181818183, 286.0, 275.0], [-19.607843137254903, 271.0, 255.0], [-35.97122302158274, 308.0, 139.0], [-40.32258064516129, 326.0, 124.0], [-50.0, 321.0, 88.0], [-50.0, 296.0, 89.0], [-43.85964912280702, 278.0, 114.0]], [[50.0, 0, 0], [45.45454545454545, 276.0, 110.0], [50.0, 286.0, 79.0], [50.0, 334.0, 75.0], [38.75968992248062, 344.0, 129.0], [36.4963503649635, 323.0, 137.0], [17.73049645390071, 288.0, 282.0], [18.38235294117647, 283.0, 272.0], [17.921146953405017, 78.0, 279.0], [28.901734104046245, -29.0, 173.0], [37.59398496240601, -29.0, 133.0], [34.24657534246575, -139.0, 146.0], [50.0, -145.0, -1.0], [50.0, -91.0, 9.0], [50.0, -82.0, 53.0], [50.0, -74.0, 57.0], [50.0, -51.0, 64.0], [50.0, -22.0, 61.0], [50.0, -20.0, 40.0], [50.0, -2.0, 7.0], [50.0, 22.0, 3.0], [50.0, 26.0, 41.0], [50.0, 26.0, 51.0], [50.0, 27.0, 64.0], [50.0, 69.0, 71.0], [50.0, 72.0, 58.0], [50.0, 73.0, 24.0], [50.0, 77.0, 5.0], [50.0, 96.0, 3.0], [50.0, 105.0, 93.0], [49.01960784313725, 73.0, 102.0], [29.069767441860467, 51.0, 172.0], [28.40909090909091, 20.0, 176.0], [48.07692307692307, 18.0, 104.0], [37.03703703703704, -9.0, 135.0], [30.120481927710845, -6.0, 166.0], [18.939393939393938, 88.0, 264.0], [17.73049645390071, 77.0, 282.0], [19.37984496124031, 92.0, 258.0], [19.53125, 268.0, 256.0], [18.181818181818183, 286.0, 275.0], [19.607843137254903, 271.0, 255.0], [35.97122302158274, 308.0, 139.0], [40.32258064516129, 326.0, 124.0], [50.0, 321.0, 88.0], [50.0, 296.0, 89.0], [43.85964912280702, 278.0, 114.0]], [[-50.0, 0, 0], [50.0, 0, 0]], [[-45.45454545454545, 276.0, 110.0], [45.45454545454545, 276.0, 110.0]], [[-50.0, 286.0, 79.0], [50.0, 286.0, 79.0]], [[-50.0, 334.0, 75.0], [50.0, 334.0, 75.0]], [[-38.75968992248062, 344.0, 129.0], [38.75968992248062, 344.0, 129.0]], [[-36.4963503649635, 323.0, 137.0], [36.4963503649635, 323.0, 137.0]], [[-17.73049645390071, 288.0, 282.0], [17.73049645390071, 288.0, 282.0]], [[-18.38235294117647, 283.0, 272.0], [18.38235294117647, 283.0, 272.0]], [[-17.921146953405017, 78.0, 279.0], [17.921146953405017, 78.0, 279.0]], [[-28.901734104046245, -29.0, 173.0], [28.901734104046245, -29.0, 173.0]], [[-37.59398496240601, -29.0, 133.0], [37.59398496240601, -29.0, 133.0]], [[-34.24657534246575, -139.0, 146.0], [34.24657534246575, -139.0, 146.0]], [[-50.0, -145.0, -1.0], [50.0, -145.0, -1.0]], [[-50.0, -91.0, 9.0], [50.0, -91.0, 9.0]], [[-50.0, -82.0, 53.0], [50.0, -82.0, 53.0]], [[-50.0, -74.0, 57.0], [50.0, -74.0, 57.0]], [[-50.0, -51.0, 64.0], [50.0, -51.0, 64.0]], [[-50.0, -22.0, 61.0], [50.0, -22.0, 61.0]], [[-50.0, -20.0, 40.0], [50.0, -20.0, 40.0]], [[-50.0, -2.0, 7.0], [50.0, -2.0, 7.0]], [[-50.0, 22.0, 3.0], [50.0, 22.0, 3.0]], [[-50.0, 26.0, 41.0], [50.0, 26.0, 41.0]], [[-50.0, 26.0, 51.0], [50.0, 26.0, 51.0]], [[-50.0, 27.0, 64.0], [50.0, 27.0, 64.0]], [[-50.0, 69.0, 71.0], [50.0, 69.0, 71.0]], [[-50.0, 72.0, 58.0], [50.0, 72.0, 58.0]], [[-50.0, 73.0, 24.0], [50.0, 73.0, 24.0]], [[-50.0, 77.0, 5.0], [50.0, 77.0, 5.0]], [[-50.0, 96.0, 3.0], [50.0, 96.0, 3.0]], [[-50.0, 105.0, 93.0], [50.0, 105.0, 93.0]], [[-49.01960784313725, 73.0, 102.0], [49.01960784313725, 73.0, 102.0]], [[-29.069767441860467, 51.0, 172.0], [29.069767441860467, 51.0, 172.0]], [[-28.40909090909091, 20.0, 176.0], [28.40909090909091, 20.0, 176.0]], [[-48.07692307692307, 18.0, 104.0], [48.07692307692307, 18.0, 104.0]], [[-37.03703703703704, -9.0, 135.0], [37.03703703703704, -9.0, 135.0]], [[-30.120481927710845, -6.0, 166.0], [30.120481927710845, -6.0, 166.0]], [[-18.939393939393938, 88.0, 264.0], [18.939393939393938, 88.0, 264.0]], [[-17.73049645390071, 77.0, 282.0], [17.73049645390071, 77.0, 282.0]], [[-19.37984496124031, 92.0, 258.0], [19.37984496124031, 92.0, 258.0]], [[-19.53125, 268.0, 256.0], [19.53125, 268.0, 256.0]], [[-18.181818181818183, 286.0, 275.0], [18.181818181818183, 286.0, 275.0]], [[-19.607843137254903, 271.0, 255.0], [19.607843137254903, 271.0, 255.0]], [[-35.97122302158274, 308.0, 139.0], [35.97122302158274, 308.0, 139.0]], [[-40.32258064516129, 326.0, 124.0], [40.32258064516129, 326.0, 124.0]], [[-50.0, 321.0, 88.0], [50.0, 321.0, 88.0]], [[-50.0, 296.0, 89.0], [50.0, 296.0, 89.0]], [[-43.85964912280702, 278.0, 114.0], [43.85964912280702, 278.0, 114.0]]]}
import turtle
import time
import random
import json
from math import sin, cos, pi, sqrt
def draw_car(t1):
t1.penup()
t1.goto(-50, -50)
t1.pendown()
for i in range(4):
t1.forward(100)
t1.left(90)
def line(x1, y1, x2, y2, t):
t.penup()
t.goto(x1, y1)
t.pendown()
t.goto(x2, y2)
t.penup()
size = 1000
N = 20
def draw_grid(t1):
t1.penup()
for i in range(N+1):
x1, y1 = size*(-1 + i*2/N), -size
x2, y2 = size*(-1 + i*2/N), size
line(x1,y1,x2,y2,t1)
x1, y1 = -size, size*(1 - i*2/N)
x2, y2 = size, size*(1 - i*2/N)
line(x1,y1,x2,y2,t1)
turtle.tracer(0, 0)
class TurtleShapeRecorder:
def __init__(self, t=None):
self.x = 0.0
self.y = 0.0
self.direction = 0.0
self.mesh = []
self.polyline = []
self.is_penup = False
self.turtle = t
self.goto(0, 0)
def goto(self, x, y):
self.x = x
self.y = y
if not self.is_penup:
self.polyline.append((self.x, self.y))
def forward(self, value):
self.goto(self.x + value*cos(self.direction),
self.y + value*sin(self.direction))
def left(self, value):
value = value*pi/180
self.direction = (self.direction + value) % (2*pi)
def right(self, value):
self.left(-value)
def penup(self):
if not self.is_penup:
self.is_penup = True
if self.polyline:
if len(self.polyline) > 1:
self.mesh.append(self.polyline)
self.polyline = []
def pendown(self):
if self.is_penup:
self.is_penup = False
self.polyline.append((self.x, self.y))
def getmesh(self):
self.penup()
print(self.polyline)
print(self.mesh)
return self.mesh
def rotated(x, y, angle, center=(0, 0)):
sin_, cos_ = sin(angle), cos(angle)
x0, y0 = center
newx = x0 + (x-x0)*cos_ - (y-y0)*sin_
newy = y0 + (x-x0)*sin_ + (y-y0)*cos_
return (newx, newy)
def perspective(x, y, z=0, camera=None, f=500):
"""
Perspective transformation. XY is horizontal
plane. Object Z is zero by default, change it if
you want to elevate object above the plane
"""
if camera:
xc, yc, zc = camera
else:
xc, yc, zc = 0, 0, 100
if y == yc:
# todo: return something better
return (0, 0)
elif y < yc:
r = f
else:
r = f/abs(y - yc)
return ((x - xc)*r, (z - zc)*r)
class MovingObject:
def __init__(self, mesh=None, turtle_f=None):
self.x = 0
self.y = 0
self.z = 0
self.speed = [0, 0]
self.acc = [0, 0]
self.friction = 800
self.acctimer = None
self.focal_dist = 300
self.tilt = 0
if turtle_f:
shape = TurtleShapeRecorder()
turtle_f(shape)
self.mesh = shape.getmesh()
else:
self.mesh = mesh
self.direction = 0
self.angularSpeed = 0
self.angularAcc = 0
def update(self, dt):
if self.acctimer is not None:
self.acctimer += dt
if self.acctimer > 1:
self.acctimer = None
self.acc = [0, 0]
speedAbs = sqrt(self.speed[0]**2 + self.speed[1]**2)
if speedAbs:
frictionsx = -self.speed[0]/speedAbs*self.friction
frictionsy = -self.speed[1]/speedAbs*self.friction
else:
frictionsx = frictionsy = 0
self.speed[0] += (frictionsx + self.acc[0])*dt
self.speed[1] += (frictionsy + self.acc[1])*dt
self.x += self.speed[0]*dt
self.y += self.speed[1]*dt
self.direction += self.angularSpeed*dt
def turnleft(self, value):
self.direction += value
self.speed = [*rotated(*self.speed, value)]
self.acc = [*rotated(*self.acc, value)]
print(self.speed, self.acc)
def forward(self, acc=1):
self.acc = [*rotated(1000*acc, 0, self.direction)]
self.acctimer = 0.0
def drawview(self, x, y, z=0, camera=None):
if self != camera:
x, y = rotated(x, y, self.direction - pi/2)
x, y = rotated(self.x + x, self.y + y, pi/2-camera.direction,
center=(camera.x, camera.y))
y, z = rotated(y, self.z + z, camera.tilt,
center=(camera.y, camera.z))
return perspective(x, y, z,
camera=(camera.x, camera.y-camera.focal_dist, 100))
else:
return perspective(self.x + x, self.y + y, z,
camera=(camera.x, camera.y-camera.focal_dist, 100))
def redraw(self, drawT, camera):
for poly in self.mesh:
drawT.penup()
if len(poly[0]) == 2:
x, y, z = *poly[0], 0
else:
x, y, z = poly[0]
drawT.goto(*self.drawview(x, y, z + self.z, camera))
drawT.pendown()
for point in poly:
if len(point) == 2:
x, y, z = *point, 0
else:
x, y, z = point
drawT.goto(*self.drawview(x, y, self.z + z, camera))
def car_editor(shapebuilder):
turtle.showturtle()
turtle.penup()
turtle.home()
turtle.shape('circle')
turtle.stamp()
def onclick(x, y):
turtle.goto(x, y)
turtle.pendown()
shapebuilder.goto(x, y)
shapebuilder.pendown()
turtle.onscreenclick(onclick)
def stopper():
car_editor.run = False
turtle.onkeypress(stopper, 'Return')
turtle.listen()
car_editor.run = True
while car_editor.run:
turtle.update()
turtle.clear()
turtle.hideturtle()
turtle.onscreenclick(None)
setupHandlers()
return shapebuilder.getmesh()
def make_3d_car(editor=True, turtle_f=None):
shape = TurtleShapeRecorder()
if editor:
shape = car_editor(shape)
else:
turtle_f(shape)
shape = shape.getmesh()
newshape = []
width = 50
middle = []
for polyline in shape:
newline_left = []
newline_right = []
for y, z in polyline:
scalor = max(z/100, 1)
x = width/scalor
newline_left.append((-x, y, z))
newline_right.append((x, y, z))
middle.append([(-x, y, z), (x, y, z)])
newshape.append(newline_left)
newshape.append(newline_right)
newshape.extend(middle)
return newshape
objects = []
car1 = MovingObject(mesh=make_3d_car(False, draw_car))
car1.z = 5
grid = MovingObject(turtle_f=draw_grid)
objects.append(car1)
objects.append(grid)
drawT = turtle.Turtle()
drawT.hideturtle()
tm = 0
def setupHandlers():
turtle.onkeypress(lambda: car1.turnleft(0.1), "Left")
turtle.onkeypress(lambda: car1.turnleft(-0.1), "Right")
turtle.onkeypress(lambda: car1.forward(), "Up")
turtle.onkeypress(lambda: car1.forward(-1), "Down")
turtle.listen()
global tm
tm = time.time()
def switch_cam():
global car_camera
car_camera = not car_camera
print('switch')
def load_cars(filepath="./all_cars.json"):
try:
with open(filepath, 'r') as f:
return json.load(f)
except FileNotFoundError:
return {}
def save_cars(cars, filepath="./all_cars.json"):
with open(filepath, 'w') as f:
json.dump(cars, f)
turtle.onscreenclick(lambda x, y: switch_cam(), 3)
dt = 0
car_camera = False
edit_car = turtle.Turtle()
edit_car.shape('square')
edit_car.penup()
edit_car.color('green')
edit_car.shapesize(1, 4)
edit_car.goto(-300, 200)
def update_car():
global car1
car_name = turtle.textinput('Назва машини',"""
Ви відкрили редактор машин.
Зробіть кліками профіль автомобіля.
Коли закінчили редагування, натисність клавішу [ENTER]
Чорна крапка посередині екрану показує, де знаходиться
центр автомобіля. Логічніше всього, щоб на цей центр
потрапили задні колеса, бо навколо цієї точки
буде поворот автомобіля.
Введіть ім'я для майбутнього автомобіля:
""")
all_cars = load_cars()
drawT.clear()
objects.remove(car1)
car1 = MovingObject(mesh=make_3d_car())
all_cars[car_name] = car1.mesh
save_cars(all_cars)
objects.append(car1)
setupHandlers()
edit_car.onclick(lambda x, y: update_car())
select_car = turtle.Turtle()
select_car.shape('square')
select_car.penup()
select_car.color('orange')
select_car.shapesize(1, 4)
select_car.goto(-300, 150)
def select_car_handler():
all_cars = load_cars()
car_name = turtle.textinput('Вибери машину', f"""
Вибери одну з машин:
{','.join(all_cars.keys())}
""")
if car_name in all_cars:
car1.mesh = all_cars[car_name]
setupHandlers()
select_car.onclick(lambda x, y: select_car_handler())
setupHandlers()
for car in load_cars().values():
newcar = MovingObject(mesh=car)
newcar.x = random.randrange(-size, size)
newcar.y = random.randrange(-size, size)
objects.append(newcar)
flyingcam = MovingObject(mesh=[])
flyingcam.x = 0
flyingcam.z = 300
flyingcam.focal_dist = size*2
flyingcam.direction = pi
flyingcam.tilt = pi/5
flyingcam.angularSpeed = pi*2/100
objects.append(flyingcam)
while True:
tm = time.time()
drawT.clear()
for obj in objects:
obj.update(dt)
obj.redraw(drawT, camera=(car1 if car_camera else flyingcam))
turtle.update()
dt = time.time() - tm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment