Tomorrow is the Tanabata, in Python had a girlfriend might be killed gift!

Tomorrow is the Tanabata, you know there are women vote or are chasing sister, certainly has the brains to buy what other new CD gift, a gift you feel if the girls put in some effort, and it is certainly favorability doubled ah .

Today to share with you the cost of a dime with Python made a good faith but full of small gifts. But we need to be reminded: this gift requires a little thought to comprehend sister, sister kind of impatient, do not give her, as it may be to break up the artifact.

Here it says, how to make this gift.

In simple terms it is a piece of A4 paper, print tables, ah, the table is doing with? In fact, hand-painted two-dimensional code, of course, you know the contents of the two-dimensional code, use the following hand-painted two-dimensional code app, it will be divided into a grid, which prompts you blacked out.

 

Python to do with his girlfriend a gift Tanabata might be killed

 

 

However, this seemingly routine is overused

Python to do with his girlfriend a gift Tanabata might be killed

 

So clearly today that this is an upgraded version of hand-painted two-dimensional code, the cost is still a dime, not only want to bother you, the girl is also going to bother, so have fun thing

Python to do with his girlfriend a gift Tanabata might be killed

 

"Number woven games"

Come, we go step by step, we first talk about the number of weaving this game, then you probably know the intention. Number of organizations (nonogram) Japanese Sudoku game.

It is the number of weaving follows a rule, easy to understand. Branches and columns, the rows and columns are marked some figures, such as the first line of the chart 7127, representing the first row has four separate lines, respectively, and 7 grains accounted for 7,1,2, and each line separated by a minimum of space.

Traditionally, the player is filled black grid to "×" mark certain number does not need to fill the lattice. So smart you certainly will know that the first column of 71,117 what does it mean.

Python to do with his girlfriend a gift Tanabata might be killed

 

 

So is the number of organizations such as play, give your digital pictures only ranks, needs its own grid blacked out according to the rules, so you know, we have to do is figure below, the two-dimensional code to hide them. Black girls, to sweep the yard.

Python to do with his girlfriend a gift Tanabata might be killed

 

 

"Create hidden two-dimensional code number and Weaving"

You say how to make it on the map?

For awkward, it is said at the beginning of the hand-drawn two-dimensional code app, as it will be divided into 21 * 21 or more grid, which tells you the blackened, you know what the appropriate number of organizations fill in the numbers.

Python to do with his girlfriend a gift Tanabata might be killed

 

The above approach may indeed cumbersome, digital wrote, had to finish printing.

I supposed to do?

Here is a Python out of time, written in Python a two-dimensional code input text, a key generated by the program and the number of weaving images to print directly

Python to do with his girlfriend a gift Tanabata might be killed

 

The complete code is as follows:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import savefig
import qrcode
def qr_matrix(data):
qr = qrcode.QRCode(version=1, box_size=1, border=1)
qr.add_data(data)
return np.asarray(qr.get_matrix(), dtype = int)
def _rle(matrix):
# find run start and ends
d = np.diff(matrix)
row, start_pos = np.where(d > 0)
_, end_pos = np.where(d < 0)
# find run lengths
run_lengths = end_pos - start_pos
# split runs from different rows into separate arrays
split_on = np.cumsum(np.bincount(row - 1))[:-1]
return np.split(run_lengths, split_on)
def run_length_encode(matrix):
rle_row = _rle(matrix)
rle_col = _rle(matrix.T)
return rle_row, rle_col
def nonogram_qr(data):
qr = qr_matrix(data)
row_rle, col_rle = run_length_encode(qr)
shape = np.array(qr.shape) - 2
return shape, row_rle, col_rle
def draw_nonogram(shape, row_rle, col_rle):
r, c = shape
f = open('qr.griddler', "w")
f.write('MK Version 3.0')
f.write('
')
f.write('
')
f.write(str(r)+' '+str(c))
f.write('
')
f.write('
')
q=np.zeros((r,c),dtype=int)
for qq in q:
f.write(str(qq)[1:-1].replace("0", "?"))
f.write('
')
f.write('
')
for col in col_rle:
f.writelines(str(col[::-1])[1:-1])
f.write('
')
f.write('
')
for row in row_rle:
f.writelines(str(row[::-1])[1:-1])
f.write('
')
fig, ax = plt.subplots(figsize=(10, 10))
plt.axis('off')
plt.axis('equal')
# draw the grid for the nonogram:
for i in range(r + 1):
ax.plot([0, c], [-i, -i], 'k-')
for j in range(c + 1):
ax.plot([j, j], [0, -r], 'k-')
# draw the numbers onto the grid
for i, row in enumerate(row_rle):
for idx, val in enumerate(row[::-1]):
ax.annotate(xy=(-idx - 0.5, -i - 0.5), s=val, ha='center', va='center')
for j, col in enumerate(col_rle):
for idx, val in enumerate(col[::-1]):
ax.annotate(xy=(j + 0.5, idx + 0.5), s=val, ha='center', va='center')
# adjust x and y limits
lim_left = max([len(x) for x in row_rle + col_rle]) + 1
lim_right = max(r, c) + 1
ax.set_xlim(-lim_left, lim_right)
ax.set_ylim(-lim_right, lim_left)
return ax
name=input('请输入二维码内容(比如我爱你?):')
ax = draw_nonogram(*nonogram_qr(name))
print('制作完成,图片名字叫做:打印吧.jpg')
savefig("打印吧.jpg")
# plt.show()

当然不想这么麻烦的话,我这里把程序也打包好了,各位直接运行exe 程序即可。

下面说说这个打包程序。

如下,下载解压,运行(注意可能打开速度挺慢,耐心等待黑框出现),输入二维码文字。

Python to do with his girlfriend a gift Tanabata might be killed

 

 

然后回车,等待,就能在软件目录看到打印吧.jpg。

这个图片你要准备的一毛钱礼物

Python to do with his girlfriend a gift Tanabata might be killed

 

,如下所示:

Python to do with his girlfriend a gift Tanabata might be killed

 

 

而细心的你肯定还看到另一个箭头的文件:qr.griddler,嗯,这个也很有意思,我们接着说。

「数织解密软件」

In fact it, the number of weaving the difficulty of this generation or more the size of 21 * 21 can still be pricey, can not let his girlfriend do not come out ah, ah you get a reminder in the side, then this decryption software comes in handy.

We must extract open, open qr.griddler we previously generated as follows.

Then click on the arrow buttons to decrypt the following, (a small probability that the phenomenon will occur multiple solutions, but there are two-dimensional code fault tolerance, so the sweep of the text is the same) as action figure:

Python to do with his girlfriend a gift Tanabata might be killed

 

 

Python to do with his girlfriend a gift Tanabata might be killed

 

 

It is also the process of verification, if no solution out of the question, but this procedure should be nothing issue, we should do away with it

Python to do with his girlfriend a gift Tanabata might be killed

 

"summary"

This gift seriously out of the whole, it is estimated to spend an hour, Tanabata good time, take advantage of Kazakhstan.

Guess you like

Origin www.cnblogs.com/qingdeng123/p/11311685.html