Advertisement
Guest User

draw_map.py

a guest
Oct 14th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.21 KB | None | 0 0
  1. from eye import *
  2. from math import cos, sin, pi
  3.  
  4. class Robo:
  5.     def __init__(self, map):
  6.         self.map = map
  7.         self.x = self.map.max_x / 2
  8.         self.y = self.map.max_y / 2
  9.         self.phi = 90
  10.         VWSetPosition(int(self.x),int(self.y),90)
  11.         self.current_color = "red"
  12.  
  13.     def draw_circle(self):
  14.         a = LIDARGet();
  15.         for i in range(len(a)):
  16.             angle = i
  17.             dist = a[(i + self.phi) %360]
  18.             x = self.x - cos(angle / 180.0 * pi) * dist
  19.             y = self.y - sin(angle / 180.0 * pi) * dist
  20.             circle="<circle cx=" + '"' + str(x) +'"'
  21.             circle+=" cy=" + '"' + str(y) +'"'
  22.             circle+= " r="+'"'+str(3)+'"'
  23.             circle+=" stroke ="+'"'+self.current_color+'"'
  24.             circle+=" stroke-width="+'"'+str(2)+'"'
  25.             circle+= " fill="+'"'+"white"+'"' + " />\n"
  26.             self.map.image.write(circle)
  27.  
  28.     def get(self):
  29.         self.x,self.y,self.phi = VWGetPosition()
  30.         self.y = self.map.max_y - self.y
  31.         # self.x = self.map.max_x - self.x
  32.  
  33.     def draw(self):
  34.         self.get()
  35.         self.draw_circle()
  36.         s = "\n\t<rect x=" + '"' + str(self.x)+ '"'
  37.         s +=  " y=" + '"' + str(self.y) + '"'
  38.         s += " width=" +'"' + str(10)+ '"'
  39.         s += " height=" +'"' +  str(10) + '"'
  40.         s +=" style= " + '"' + "fill:" + self.current_color + "();stroke-width:1;stroke:rgb(0,0,0)" + '"' + " />\n"
  41.         self.map.image.write(s)
  42.  
  43.  
  44. class Map:
  45.     def __init__(self, file):
  46.         self.image = open( file +".svg", "w+")
  47.         self.max_x = 4000
  48.         self.max_y = 4000
  49.         s = "<svg width=" +'"' + str(30 + self.max_x) + '"' +" height=" + '"' + str(30+ self.max_y) + '"' + ">"
  50.         self.image.write(s)
  51.         s = "\n\t<rect x=" + '"' + "0"+ '"'
  52.         s +=  " y=" + '"' + "0" + '"'
  53.         s += " width=" +'"' + str(30 + self.max_x)+ '"'
  54.         s += " height=" +'"' +  str(30 + self.max_y) + '"'
  55.         s +=" style= " + '"' + "fill:rgb" + str((255,255,255)) + "();stroke-width:1;stroke:rgb(0,0,0)" + '"' + " />"
  56.         self.image.write(s)
  57.         self.robot = Robo(self)
  58.  
  59.     def end(self):
  60.         self.image.write("\n</svg>")
  61.         self.image.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement