importturtlefrommathimport*cor=0importkandinskyturtle.speed(0)draw=Falseloc=turtlepx=float(8)py=float(14)sw=int(64)sh=int(64)fov=float(0.22)fd=float(10)tx=0fl=Falsehit=Falsety=0h=float(0)loc.goto(5.5,5.5)loc.penup()loc.hideturtle()loc.goto(3,3)loc.rt(180)pa=(loc.heading()-13)*((22/7)/180)pi=22/7px=loc.position()[1]py=loc.position()[0]cal=mx*fov# use multiline string define to make the map easier to
# see/adjust
map='''
x64\nx.62x\nx.62x\nx.62x\nx.62x\nx.62x\nx.28b10.24x\nx.4g6.18b.8b.24x\nx.4g.4g.7g11b.8b5.20x\nx.4g.4g.7g.10b.8b.3b.20x\nx.4g.5g.6g.23b.20x\nx.4g.5g.6g.10b.8b.3b.20x\nx.4g5.g6.g.3g7b.8b5.20x\nx.4g.10g.g.3g.6b.8b.24x\nx.4g.10g3.3g3.5b3.b5.24x\nx.4g.10g.7g.6b.3b.27x\nx.4g.18g.6b.3b.27x\nx.4g.10g.7g.6b.3b.27x\nxg5.10g9.6b.3b.27x\nx.3g2.10g.14b.3b.27x\nx.3g7.g4.10b6.3b3.25x\nx.3g.4g.3g.12b.10b.25x\ng2.g2.4g.3g.12b.2b3.3b3.25x\nx.3g6.3g.12b.2b3.3b.27x\nx.3g.4g.3g.12b.2b3.3b.27x\nx.8g.3g.12b6.3b.27x\nx.3g.4g.3g.17b.3b.27x\nx.3g7.g4.15b2.b2.16x10.x\nx.3g2.9g.9g6.5g7.9x.8x.x\nx.3g2.9g.9g.15g2.9x.8x.x\nx.3g2.9g.9g.15gx11.8x.x\nx.4g.9g.9g.16x.9x.8x.x\nx.14g.9g.35x.x\nx.4g.9g.9g.16x.9x.8x.x\nx.3g2.9g.9g.15gx3.4x4.8x.x\nx.3g2.9g.9g.15g2.x2.2x.3x.8x.x\nx.3g2.9g.9g6x2.x2g6.3x.2x.3x.8x.x\nx.3g6.g5.15x.3x.9x.2x.3x3.x2.x3.x\nx.3g5.3g.18x.3x.9x.2x.6x.2x.4x\nx.3g5.3g.18x.3x.9x.2x.14x\nx.3g.3g.3g.18x.3x.9x.2x.14x\nx.7g.3g.18x.3x.9x.2x.2x.x.x.x.5x\nx.3g.3g.3g.18x.3x.9x.2x3.x.x.x.x2.3x\nx.3g5.3g.18x.3x.9x.3x.9x.3x\nx.3g5.3g12.7x.3x.9x.13x.3x\nx.15g.6g3.5x.3x.9x.3x.9x.3x\nx.24g.5x.3x.9x6.x.x.x.x2.3x\nx.15g.6g3.5x.3x.15x.x.x.x.5x\ng24.7x.3x.27x\nx.25x7.2x6.22x\nx.25x.4x.3x.4x.22x\nx.25x.13x.22x\nx.25x.4x.3x.4x.22x\nx.25x.4x.3x.4x.22x\nx.25x6.3x6.22x\nx.25x.4x.3x.4x.22x\nx.25x.13x.22x\nx.25x.4x.3x.4x.22x\nx.25x6.3x6.22x\nx.25x.13x.22x\nx.25x.13x.22x\nx.25x.13x.22x\nx.25x.13x.22x\nx64
'''.strip()# strip just removes any whitespace at the beginning and end
# generate ma1, note this could easily be extended
# to auto-detect width and height.
ma1=[]forrowinmap.splitlines():ma1.extend(row)# strip the neewline from the map
mx=my=int(sqrt(len(ma1)))# autodetect map square
print(ma1)print(mx)print(my)defdo_color(c,dis):shade=int(255-(dis*1.2*12.75))ifc=="b":returnshade,shade,0ifc=="g":returnshade,shade,shadeifc=="x":return0,0,shadewhileTrue:foriinrange (int(sw)):ra=float(((pa-0.11)+(i)/(mx)*fov))spot='r'ey=float(cos(ra))ex=float (sin(ra))dis=float (0)whilehit==Falseanddis<fd:dis=dis+0.5tx=int(px+ex*dis)ty=int(py+ey*dis)iftx<0ortx>=mxorty<0orty>=my:hit=Trueelse:cor=0spot=(tx*mx+ty)forciinrange (len(ma1)):cor=cor+int(ma1[ci-1][1])ifcor>=spot:spot=(ma1[ci-1][0])breakif(spot!='o'):hit=Trueifdis>=fd:spot='o'hit=Trueifhit:h=40-(dis*4)kandinsky.fill_rect(17+(i*7),0,7,int(240-(((40-h)/2)*5)),(do_color(int(spot),dis)))kandinsky.fill_rect(17+(i*7),0,7,int((((40-h)/2)*5)),(50,50,50))ifi==sw-1:kandinsky.draw_string(str(turtle.position()),10,200)k=kandinsky.get_keys()if"up"inkandi==(sw-1):loc.fd(0.1)px=loc.pos()[1]py=loc.pos()[0]#if(ma1[int(px-0.1)*mx+int(py-0.1)]!="."):
#loc.fd(-0.1)
kandinsky.fill_rect(0,0,320,240,(50,50,50))if"down"inkandi==(sw-1):loc.fd(-0.1)px=loc.pos()[1]py=loc.pos()[0]#if(ma1[int(px-0.1)*mx+int(py-0.1)]!="."):
#loc.fd(0.1)
kandinsky.fill_rect(0,0,320,240,(50,50,50))if"left"inkandi==(sw-1):loc.lt(-3)radian=(loc.heading()-13.33)*(pi/180)pa=radiankandinsky.fill_rect(0,0,320,240,(50,50,50))if"right"inkandi==(sw-1):loc.lt(3)radian=(loc.heading()-13.333)*(pi/180)pa=radiankandinsky.fill_rect(0,0,320,240,(50,50,50))hit=False# Type your text here
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.