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))
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) if func_name == 'swap_polygons': index = i - 1 if i > 0 else i + 1
A.makeRandomCircumcircle() polys.append(A) A.drawPolygon() # plt.axis('off') # plt.axis('image') plt.figure() for i in range(len(polys)): if i % 2 != 0: polys[i].gen_inside(polys[i - 1]) polys[i - 1].hatch = None polys[i].hatch = 'random' polys[i].drawPolygon() plt.axis('off') plt.axis('image') plt.savefig('./series' + str(i) + '.png') plt.figure() else: polys[i].drawPolygon() plt.axis('off') plt.axis('image') plt.savefig('./series' + str(i) + '.png') rules = ['gen_inside', 'gen_outside', 'flip'] for l in range(3): rulen_index = int(random.random()) * len(rules) plt.figure() counter = 0 for i in range(len(polys) - 1): fig = plt.figure() # rules[]
temp = None for i in range(len(sides)): # size = max(random.random()+0.5,0.3+i)* random.choice([70,100]) size = (i + 1)**2 * 100 # print size temp = Polygon(no_of_sides=sides[i], isRegular=False) temp.circumcircle = Circumcircle(size, XX[i], YY[i]) temp.makeShape() temp.drawPolygon() polys.append(temp) plt.axis('image') plt.axis('off') # plt.show() plt.savefig('./fold1.png', transparent=True) # save a flipped version os.system('convert fold1.png -flop flipfold1.png') one = IMG.open('fold1.png').convert('RGBA') two = IMG.open('flipfold1.png').convert('RGBA') IMG.alpha_composite(one, two).save("merge.png") img = cv2.imread('./merge.png', 0) print img.shape height, width = img.shape os.system( 'convert fold1.png -strokewidth 1 -fill none -stroke black -draw \"stroke-dasharray 5 3 line '
# same center and radius B.clone_circumcircle(A) # Center remains same as A but the radius can be anything less than A's raduis B.circumcircle.radius = 0.5 * A.circumcircle.radius # make the sides B.makeShape() # draw the polygon on the canvas B.drawPolygon() seqs_of_polygons.append(B) A.circumcircle.radius = B.circumcircle.radius plt.axis('image') plt.axis('off') # No axis to be drawn # FIX : Save the image in high quality plt.savefig('./plot/trans/plot'+str(l)+'.png') img = cv2.imread('./plot/trans/plot'+str(l)+'.png',0) img = cropImage(img) cv2.imwrite('./plot/trans/plot'+str(l)+'.png',img) plt.figure() for i in range(len(seqs_of_polygons)): if i == 0: seqs_of_polygons[i].flip() elif i == 1: seqs_of_polygons[i].rotate(math.pi * 0.5) elif i == 2: seqs_of_polygons[i].flip('hori') elif i == 3: seqs_of_polygons[i].rotate(math.pi * 0.75)