How CAN i draw the symbol "om" in python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abhishek07
    New Member
    • Feb 2010
    • 3

    How CAN i draw the symbol "om" in python

    I am attaching the image of the symbol please help... its urgent....pleas e reply
    This is the url of wher u can see the symbol... its an assignment....
    [URL="http://www.yogaelement s.com/blog/wp-content/uploads/2008/02/om4.jpg"]

    Need not be exact copy

    i have also attached the image
    Attached Files
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    You have posted a very vague question without showing any effort to solve the problem for yourself. I can give you an answer, but I won't write the code for you.

    Create a Tkinter canvas.
    Draw a polygon or a series polygons with fill

    I attached an example of a canvas with a filled polygon.
    Attached Files

    Comment

    • abhishek07
      New Member
      • Feb 2010
      • 3

      #3
      i still cant do this...please help me... ihave tried a lot

      please help me someone

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        abhishek07,

        I would suggest laying out a grid, say 200x200, over the symbol and record Cartesian points at the vertices and along arcs to approximate the symbol. After that, you can create the filled polygons on a Tkinter canvas. Here's a basic example of creating a Tkinter canvas with filled polygons.
        Code:
        import random
        from Tkinter import *
        
        class Pt(object):
        
            def __init__(self, x=0.0, y=0.0):
                self.x = float(x)
                self.y = float(y)
        
            def __add__(self, other):
                return Pt(self.x+other.x, self.y+other.y)
        
            def __sub__(self, other):
                return Pt(self.x-other.x, self.y-other.y)
        
            def __mul__(self, f):
                return Pt(self.x*f, self.y*f)
        
            def __div__(self, f):
                return Pt(self.x/f, self.y/f)
        
            def ray(self, limit):
                return self, Pt(limit, self.y)
        
            def __iter__(self):
                for a in [self.x, self.y]:
                    yield a
        
            def __str__(self):
                return 'Pt(%0.4f, %0.4f)' % (self.x,self.y)
        
            def __repr__(self):
                return 'Pt(%0.4f, %0.4f)' % (self.x,self.y)
        
        if __name__ == '__main__':
            limit = 400    
            pt1 = Pt(random.choice(range(0,limit)), random.choice(range(0,limit)))
            polygon = [Pt(280,380),
                       Pt(360,20),
                       Pt(100,34),
                       Pt(30,5),
                       Pt(19,240)]
        
            root = Tk()
            w = Canvas(root, width=limit+10, height=limit+10)
            w.create_rectangle(0,0,limit+10,limit+10,fill="#444444444")
            expandPts = []
            for pt in polygon:
                expandPts.append(pt.x)
                expandPts.append(pt.y)
            # draw closed polygon
            polyID = w.create_polygon(*expandPts)
            w.itemconfig(polyID, fill="#fff000000",
                         activefill="#000000fff",
                         outline="#000000000",
                         width=1)
            
            # draw ray from random point
            w.create_line(pt1.x, pt1.y,
                          pt1.ray(limit+10)[1].x,
                          pt1.ray(limit+10)[1].y,
                          fill="#ff0",width=2,
                          activefill='#0f0')
            # create a blip
            w.create_line(pt1.x-4, pt1.y-4,
                          pt1.x+4, pt1.y+4,
                          fill="#ffffff",width=2)
            w.create_line(pt1.x-4, pt1.y+4,
                          pt1.x+4, pt1.y-4,
                          fill="#ffffff",width=2)
            w.pack()
            root.mainloop()

        Comment

        • bvdet
          Recognized Expert Specialist
          • Oct 2006
          • 2851

          #5
          What the heck - This version is interactive. Left click to select points on the canvas. Right click to draw a polygon and a horizontal ray beginning at a randomly selected point.
          Code:
          import random
          from Tkinter import *
          
          class Pt(object):
          
              def __init__(self, x=0.0, y=0.0):
                  self.x = float(x)
                  self.y = float(y)
          
              def __add__(self, other):
                  return Pt(self.x+other.x, self.y+other.y)
          
              def __sub__(self, other):
                  return Pt(self.x-other.x, self.y-other.y)
          
              def __mul__(self, f):
                  return Pt(self.x*f, self.y*f)
          
              def __div__(self, f):
                  return Pt(self.x/f, self.y/f)
          
              def ray(self, limit):
                  return self, Pt(limit, self.y)
          
              def __iter__(self):
                  for a in [self.x, self.y]:
                      yield a
          
              def __str__(self):
                  return 'Pt(%0.4f, %0.4f)' % (self.x,self.y)
          
              def __repr__(self):
                  return 'Pt(%0.4f, %0.4f)' % (self.x,self.y)
          
          if __name__ == '__main__':
              limit = 400
              ptList = []
              def draw_blip(pt, size):
                  # create a blip
                  w.create_line(pt.x-size, pt.y-size,
                                pt.x+size, pt.y+size,
                                fill="#ffffff",width=2)
                  w.create_line(pt.x-size, pt.y+size,
                                pt.x+size, pt.y-size,
                                fill="#ffffff",width=2)
                  
              def addPts(event):
                  ptList.append(Pt(event.x, event.y))
                  draw_blip(Pt(event.x, event.y), 1)
              def finish(event):
                  event.widget.unbind("<ButtonRelease-1>")
                  event.widget.unbind("<ButtonRelease-3>")
                  pt1 = Pt(random.choice(range(0,limit)), random.choice(range(0,limit)))
                  expandPts = []
                  for pt in ptList:
                      expandPts.append(pt.x)
                      expandPts.append(pt.y)
                  # draw closed polygon
                  polyID = w.create_polygon(*expandPts)
                  w.itemconfig(polyID, fill="#fff000000",
                               activefill="#000000fff",
                               outline="#000000000",
                               width=1)
                  
                  # draw ray from random point
                  w.create_line(pt1.x, pt1.y,
                                pt1.ray(limit+10)[1].x,
                                pt1.ray(limit+10)[1].y,
                                fill="#ff0",width=2,
                                activefill='#0f0')
                  draw_blip(pt1, 4)
          
              root = Tk()
              w = Canvas(root, width=limit+10, height=limit+10)
              w.bind("<ButtonRelease-1>", addPts)
              w.bind("<ButtonRelease-3>", finish, "+")
              w.create_rectangle(0,0,limit+10,limit+10,fill="#666")
              w.pack()
              root.mainloop()

          Comment

          Working...