def draw_three(symbols,name): plt.figure() side = 10 zoom = 3 angle = math.pi/8 polygon = plt.Polygon([(0,0),(0,-side),(side*math.cos(angle),side*math.sin(angle)-side),(side*math.cos(angle),side*math.sin(angle))],fill=False) plt.gca().add_patch(polygon) plt.gca().text(side*math.cos(angle)/2, (side*math.sin(angle)- side)/2, symbols[0], # rotation value should in degrees # rotation=self.alphabet_rotation * (180/math.pi) , fontsize=zoom*side, multialignment='center', verticalalignment='center', horizontalalignment='center', # fontproperties=zhfont1 ) polygon = plt.Polygon([(0,0),(0,-side),(-side*math.cos(angle),side*math.sin(angle)-side),(-side*math.cos(angle),side*math.sin(angle))],fill=False) plt.gca().add_patch(polygon) plt.gca().text(-side*math.cos(angle)/2, (side*math.sin(angle)- side)/2, symbols[1], # rotation value should in degrees # rotation=self.alphabet_rotation * (180/math.pi) , fontsize=zoom*side, multialignment='center', verticalalignment='center', horizontalalignment='center', # fontproperties=zhfont1 ) polygon = plt.Polygon([(0,0),(side*math.cos(angle),side*math.sin(angle)),(0,2*side*math.sin(angle)),(-side*math.cos(angle),side*math.sin(angle)) ],fill=False) plt.gca().add_patch(polygon) plt.gca().text(0, side*math.sin(angle),symbols[2], # rotation value should in degrees # rotation=self.alphabet_rotation * (180/math.pi) , fontsize=zoom*side, multialignment='center', verticalalignment='center', horizontalalignment='center', # fontproperties=zhfont1 ) plt.axis('image') plt.axis('off') plt.savefig('./'+name+'.png')
def draw_type(layout_type=1): """ This will draw a type. """ # More randomnes unique # symbols = ["#","-","*","**","^","?"] # symbols = random.choice(['1','2','3','4','5','6'] symbols = ['#','*','-','?','^','**',u'\u2605',u'\u2020',u'\u002B'] random.shuffle(symbols) # symbols = [random.choice(['#','*','1','-','?','2','^','**','**\n*']) for i in range(6)] # symbols = [1,2,3,4,5,6] side = 10 X_base = 0 Y_base = 0 zoom=3 triplets = [ (2,5,1),(6,2,1),(2,3,5),(2,3,6), (1,4,6),(4,1,5),(4,6,3),(5,3,4)] wrong_triplets = [ (2,1,4),(2,4,5),(4,6,2),(2,3,4)] plt.figure() # Firs four are always drawn the same way for i in range(4): # draw 1-4 polygon = plt.Rectangle((0,-i*side),side,side,fill=False) plt.gca().text(side/2, -(i*side-side/2), symbols[i], # rotation value should in degrees # rotation=self.alphabet_rotation * (180/math.pi) , fontsize= side * zoom , multialignment='center', verticalalignment='center', horizontalalignment='center', # fontproperties=zhfont1 ) plt.gca().add_patch(polygon) if layout_type == 1: # Type 1 # 1 # | # 5-2-6 # | # 3 # | # 4 # # 2-1-5 # 2-1-6 # 2-3-5 # 2-3-6 # 4-1-6 # 4-1-5 # 4-3-6 # 4-3-5 # Draw 5 polygon = plt.Rectangle((-side,-side),side,side,fill=False) plt.gca().text(-side/2, -side/2, symbols[4], # rotation value should in degrees # rotation=self.alphabet_rotation * (180/math.pi) , fontsize=zoom*side, multialignment='center', verticalalignment='center', horizontalalignment='center', # fontproperties=zhfont1 ) plt.gca().add_patch(polygon) # # Draw 6 polygon = plt.Rectangle((side,-side),side,side,fill=False) plt.gca().text(side+side/2, -side/2, symbols[5], # rotation value should in degrees # rotation=self.alphabet_rotation * (180/math.pi) , fontsize=zoom*side, multialignment='center', verticalalignment='center', horizontalalignment='center', # fontproperties=zhfont1 ) plt.gca().add_patch(polygon) elif layout_type == 2: # Type 2 # 5-1 # | # 2-6 # | # 3 # | # 4 # # 2-1-5 # 2-1-6 # 2-3-5 # 2-3-6 # 4-1-6 # 4-1-5 # 4-3-6 # 4-3-5 # Draw 5 polygon = plt.Rectangle((-side,0),side,side,fill=False) plt.gca().text(-side/2, +side/2, symbols[4], # rotation value should in degrees # rotation=self.alphabet_rotation * (180/math.pi) , fontsize=zoom*side, multialignment='center', verticalalignment='center', horizontalalignment='center', # fontproperties=zhfont1 ) plt.gca().add_patch(polygon) # # Draw 6 polygon = plt.Rectangle((side,-side),side,side,fill=False) plt.gca().text(side+side/2, -side/2, symbols[5], # rotation value should in degrees # rotation=self.alphabet_rotation * (180/math.pi) , fontsize=zoom*side, multialignment='center', verticalalignment='center', horizontalalignment='center', # fontproperties=zhfont1 ) plt.gca().add_patch(polygon) elif layout_type == 3: # pass # Type 2 # 1 # | # 5-2 # | # 3-6 # | # 4 # # 2-1-5 # 2-1-6 # 2-3-5 # 2-3-6 # 4-1-6 # 4-1-5 # 4-3-6 # 4-3-5 # Draw 5 polygon = plt.Rectangle((-side,-side),side,side,fill=False) plt.gca().text(-side/2, -side/2, symbols[4], # rotation value should in degrees # rotation=self.alphabet_rotation * (180/math.pi) , fontsize=zoom*side, multialignment='center', verticalalignment='center', horizontalalignment='center', # fontproperties=zhfont1 ) plt.gca().add_patch(polygon) # # Draw 6 polygon = plt.Rectangle((side,-2*side),side,side,fill=False) plt.gca().text(side+side/2, -side/2-side, symbols[5], # rotation value should in degrees # rotation=self.alphabet_rotation * (180/math.pi) , fontsize=zoom*side, multialignment='center', verticalalignment='center', horizontalalignment='center', # fontproperties=zhfont1 ) plt.gca().add_patch(polygon) elif layout_type == 4: # Type 2 # 5-1 # | # 2 # | # 3-6 # | # 4 # Draw 5 polygon = plt.Rectangle((-side,0),side,side,fill=False) plt.gca().text(-side/2, -side/2+side, symbols[4], # rotation value should in degrees # rotation=self.alphabet_rotation * (180/math.pi) , fontsize=zoom*side, multialignment='center', verticalalignment='center', horizontalalignment='center', # fontproperties=zhfont1 ) plt.gca().add_patch(polygon) # # Draw 6 polygon = plt.Rectangle((side,-2*side),side,side,fill=False) plt.gca().text(side+side/2, -side/2-side, symbols[5], # rotation value should in degrees # rotation=self.alphabet_rotation * (180/math.pi) , fontsize=zoom*side, multialignment='center', verticalalignment='center', horizontalalignment='center', # fontproperties=zhfont1 ) plt.gca().add_patch(polygon) elif layout_type == 5: # Type 2 # 1 # | # 5-2 # | # 3 # | # 4-6 # # Draw 5 polygon = plt.Rectangle((-side,-side),side,side,fill=False) plt.gca().text(-side/2, -side/2, symbols[4], # rotation value should in degrees # rotation=self.alphabet_rotation * (180/math.pi) , fontsize=zoom*side, multialignment='center', verticalalignment='center', horizontalalignment='center', # fontproperties=zhfont1 ) plt.gca().add_patch(polygon) # # Draw 6 polygon = plt.Rectangle((side,-3*side),side,side,fill=False) plt.gca().text(side+side/2, -side/2-2*side, symbols[5], # rotation value should in degrees # rotation=self.alphabet_rotation * (180/math.pi) , fontsize=zoom*side, multialignment='center', verticalalignment='center', horizontalalignment='center', # fontproperties=zhfont1 ) plt.gca().add_patch(polygon) plt.axis('image') plt.axis('off') plt.savefig('./dicelayout.png') random.shuffle(triplets) random.shuffle(wrong_triplets) for i in range(3): temp_triplet = triplets[i] draw_three([symbols[j-1] for j in temp_triplet],'dice'+str(i+1)) for i in range(3): temp_triplet = wrong_triplets[i] draw_three([symbols[j-1] for j in temp_triplet],'dice_'+str(i+1))
XX = int(random.random() * 10) + 3 XX = int(random.random()) + 3 print(XX, "isXX") B = Polygon(no_of_sides=XX, size=random.random() * 40) B.clone_circumcircle(A) # Center remains same as A but the radius can be anything less than A's raduis B.circumcircle.radius = 0.8 * B.circumcircle.radius B.makeShape() # B.drawPolygon() polys.append(B) A = B for pl in polys: pl.drawPolygon() plt.axis('image') plt.axis('off') plt.savefig("./plot/seq/plot" + str(i) + "original_.png") # Original transform func_names = [] params = [] plt.figure() for k, pl in enumerate(polys): func_name = funcs[int(random.random() * len(funcs))] func_names.append(func_name) func_call = getattr(pl, func_name)