circuit strat, first version
[aversive.git] / projects / microb2010 / tests / oa / graph.py
index d5946f1..48e9cc3 100644 (file)
@@ -166,11 +166,45 @@ def build_path(ptlist):
     x, y = zip(*poly.vertices)
     return x,y
 
+def nearest_corn(x, y):
+    OFFX=150
+    OFFY=222
+    STEPX=450
+    STEPY=500
+
+    x -= OFFX
+    x += STEPX/2
+    x /= STEPX
+
+    y -= OFFY
+    y += STEPY/2
+    if (x & 1) == 1:
+        y -= STEPY/2
+    y /= STEPY
+
+    i = (x * 2)
+    j = (y * 2) + (x & 1)
+    if i >= WAYPOINTS_NBX:
+        return None
+    if j >= WAYPOINTS_NBY:
+        return None
+
+    if (i & 1) == 0:
+        y = OFFSET_CORN_Y
+    else:
+        y = OFFSET_CORN_Y + STEP_CORN_Y/2
+    y += (j * STEP_CORN_Y)
+
+    x = OFFSET_CORN_X + (i * STEP_CORN_X)
+
+    return x, y
+
+
 def build_area(ax):
     # area
     x,y = build_poly([(0,0), (3000,0), (3000,2100), (0,2100)])
     ax.plot(x, y, 'g-')
-    
+
     x,y = build_poly([(0,0), (0,500), (500,500), (500,0)])
     ax.plot(x, y, 'y-')
 
@@ -179,16 +213,60 @@ def build_area(ax):
 
     x,y = build_poly([(740,0), (740,500), (2260,500), (2260,0)])
     ax.plot(x, y, 'g--')
+
+    """
+    # courbes a 2 balles
+    x,y = build_path([(375,0), (375,2050)])
+    ax.plot(x, y, 'r-')
+
+    x,y = build_path([(150,1972), (2850,472)])
+    ax.plot(x, y, 'r-')
+
+    x,y = build_path([(0,1722), (3000,1722)])
+    ax.plot(x, y, 'r-')
+
+    x,y = build_path([(150,972), (1950,1972)])
+    ax.plot(x, y, 'r-')
+
+    acoef = (2850-150)/5.
+    bcoef = (472-1972)/5.
+    x,y = build_path([(600,1972), (600+bcoef, 1972-acoef)])
+    ax.plot(x, y, 'r-')
+
+    p = PatchCollection([Circle((2400,972), 225)],
+                        cmap=matplotlib.cm.jet,
+                        alpha=0.5, facecolor=(1.,0.,0.))
+    ax.add_collection(p)
+
+    """
+
+    """
+    #courbes a 2 balles 50
+    for xx in range(0, 3000, 100):
+        print xx
+        for yy in range(0, 2100, 100):
+            pouet = nearest_corn(xx, yy)
+            if pouet == None:
+                continue
+            xxx, yyy = pouet
+            x,y = build_path([(xx,yy), (xxx,yyy)])
+            ax.plot(x, y, 'r-')
+    """
+
    # limit
     #x,y = build_poly([(250,250), (2750,250), (2750,1850), (250,1850)])
     #ax.plot(x, y, 'g--')
-    
+
+    xtick = [i * STEP_CORN_X + OFFSET_CORN_X for i in range(WAYPOINTS_NBX)]
+    ax.set_xticks(xtick)
+    ytick = [(i-1) * STEP_CORN_Y/2 + OFFSET_CORN_Y for i in range(WAYPOINTS_NBY*2)]
+    ax.set_yticks(ytick)
+
     init_corn_table(random.randint(0,8), random.randint(0,3))
 
     waypoints = init_waypoints()
     mark_all_neigh(5,6)
-    
+
     wcorn = []
     bcorn = []
     points = []
@@ -246,13 +324,15 @@ def build_area(ax):
 
 def graph(filename):
     fig = plt.figure()
-    ax = fig.add_subplot(111)
+    ax = fig.add_subplot(111, aspect='equal')
 
     build_area(ax)
 
-    ax.grid()
+    ax.grid(color = (0.3, 0.3, 0.3))
     ax.set_xlim(-100, 3100)
     ax.set_ylim(-100, 2200)
+    #ax.set_xlim(0, 825)
+    #ax.set_ylim(1472, 1972)
     #ax.set_title('spline paths')
     #plt.show()
     fig.savefig(filename)