当前位置:网站首页>【七夕节】浪漫七夕,代码传情。将爱意变成绚烂的立体场景,给她(他)一个惊喜!(送代码)
【七夕节】浪漫七夕,代码传情。将爱意变成绚烂的立体场景,给她(他)一个惊喜!(送代码)
2022-08-05 02:50:00 【IT里的交易员】
将爱意变成绚烂的立体场景,给她(他)一个惊喜!
又是一年七夕节! coder的浪漫当然也少不了coding。这里给大家用python+js展示一款表白神器。希望天下有情人终成眷属,两口子恩爱如初!
话不多少,上代码!
一、python代码(情话转二进制编码)
python的功能,将想表达的汉字转为点阵图对应的二进制的编码。文中HZK16为16*16的汉字点阵字库,需要下载后保存到D盘根目录。
HZK16字库文件下载链接:https://pan.baidu.com/s/1D_6yk79-pfGL4_Xif4DILg?pwd=qxkl 提取码:qxkl
# -*- coding: utf-8 -*-
def hanzi_dianzhen(hanzi):
'''函数功能:将输入的汉字转换位点阵图的二进制字符串'''
gbk = hanzi.encode('GBK')
# print('hanzi gbk',gbk)
L = list(gbk)
offset = 94*(L[0]-0xa0 -1) + L[1]-0xa0-1
offset = offset*32
# print('offset is :%d' % offset)
f = open('D:\\HZK16','rb')
# 查询字库获取
f.seek(offset)
display = f.read(32)
display = list(display)
comp = [0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01]#分别为只有第8位为1(10000000),第7位为1...用来相&得出相应位是否为1
# 获取汉字codekey
codekey = []
for i in range(16):
for j in range(2):
codekey.append(display[i*2+j])
# 将codekey转为二进制,碰到1则输出,碰到0则输出空格,实现汉字点阵打印。
bin_string = ''
for i in range(len(codekey)):
bits = bin(int(str(hex(codekey[i])),16))[2:].zfill(8)
if i % 2 ==0: print('\n')
for k in range(8):
if bits[k] == '1':
print('*',end=' ')
else:
print(' ',end=' ')
bin_string += str(bits)
# print('\n')
# print('汉字:',hanzi)
# print('汉字codekey:',codekey)
# print('汉字bin_string:',bin_string)
return str(bin_string)
def print_bin_list(bin_list):
'''将点阵字符串输出为汉字,每隔256(16*16)位,换行输出下一个汉字。'''
for i in range(len(bin_list)):
for j in bin_list[i]:
if j % 16 ==0: print('\n')
if j == '1':
print('*',end=' ')
else:
print(' ',end=' ')
if __name__=='__main__':
hanzi_string = '宁宁我爱你,今宵共七夕!' # 自己替换想表达的文字。
bin_list = []
for i in hanzi_string:
bin_list.append(hanzi_dianzhen(i))
# 打印输出,检验结果是否正确
print('\n复制汉字字符串的二进制编码list到编程猫里,替换相应字符串。\n',bin_list)
输出一个字,大家能看出来是什么字么?
二、js代码部分(二进制编码生成立体场景)
这里需要使用到编程猫的代码岛3.0环境(https://box3.codemao.cn/)。注册登录后,进入创作学习->地图,点击“新建地图”。
选择空白地图
在左侧选择脚本,并录入以下js代码,点击右上角三角即可运行。
js脚本如下,将bits_list 的赋值替换为刚才python代码的输出结果,点击运行即可测试脚本:
/* 在指定位置快速建造一个实心的矩形 */
function cubefill(vox, sx, sy, sz, xsize, ysize, zsize){
var xend = sx+xsize
var yend = sy+ysize
var zend = sz+zsize
for(var x=sx;x<xend;x++){
for(var y=sy;y<yend;y++){
for(var z=sz;z<zend;z++){
voxels.setVoxel(x,y,z,vox)
}}}
}
cubefill('carpet_03',0,9,0,256,1,256)
/* 在指定位置快速建造一个汉字 */
function hanzi(vox, sx, sy, sz, bits){
// 初始化设定x,y,z坐标
var x = sx;
var y = sy+16;
var z = sz
for (var i=0;i<bits.length;i++){
if (i % 16 ==0){
x = sx;
y = y - 1;
}
if (bits[i] == '1'){
voxels.setVoxel(x, y , z, vox)
}
else{
voxels.setVoxel(x, y , z, 0)
}
x = x + 1;
}
}
/* 汉字点阵码list */
let bits_list = ['0000001000000000000000010000000001111111111111100100000000000010100000000000010000000000000000001111111111111110000000010000000000000001000000000000000100000000000000010000000000000001000000000000000100000000000000010000000000000101000000000000001000000000', '0000001000000000000000010000000001111111111111100100000000000010100000000000010000000000000000001111111111111110000000010000000000000001000000000000000100000000000000010000000000000001000000000000000100000000000000010000000000000101000000000000001000000000', '0000010010000000000011101010000001111000100100000000100010010000000010001000010011111111111111100000100010000000000010001001000000001010100100000000110001100000000110000100000001101000101000000000100100100000000010100001010000101000000101000001000000001100', '0000000001111000001111111000000000010001000100000000100100100000011111111111111001000010000000101000001000000100011111111111100000000100000000000000011111110000000010100010000000001001010000000001000010000000000100010110000000100010000111000000110000001000', '0001000100000000000100010000000000010001000000000010001111111100001000100000010001100100000010001010100001000000001000000100000000100001010100000010000101001000001000100100110000100100010001000010000001000000001000000100000000100001010000000010000010000000', '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001100000000000001111000000000000111100000000000001100000000000000010000000000000010000000000000010000000000000000000000000000', '0000000100000000000000010000000000000010100000000000010001000000000010000010000000010010000100000010000110001110110000001000010000000000000000000001111111110000000000000001000000000000001000000000000000100000000000000100000000000000100000000000000100000000', '0000001000000000000000010000000001111111111111100100000100000010100010010010010000000101010100000001111111111000000100000001000000010000000100000001111111110000000100000001000000010000000100000001111111110000000100000001000000010000010100000001000000100000', '0000100000100000000010000010000000001000001000000000100000101000011111111111110000001000001000000000100000100000000010000010000000001000001000000000100000100100111111111111111000000000000000000000010001000000000011000011000000010000000110000010000000001000', '0000001000000000000000100000000000000010000000000000001000000000000000100000000000000010000001000000001111111110111111100000000000000010000000000000001000000000000000100000000000000010000001000000001000000100000000100000010000000001111111000000000000000000', '0000001000000000000000100000000000000010000010000000011111111100000001000000100000001000000010000001000000010000001001000001000001000011001000000000000101000000000000001000000000000001000000000000001000000000000001000000000000011000000000000110000000000000', '0000000000000000000000011000000000000011110000000000001111000000000000111100000000000011110000000000001111000000000000011000000000000001100000000000000110000000000000000000000000000001100000000000001111000000000000011000000000000000000000000000000000000000']
/* 在指定位置快速建造汉字 */
for (var i=0;i<bits_list.length;i++){
hanzi('pink_light',60+i*17,10,60,bits_list[i])
}
- 设置雪花效果(漫天飘下红色爱心),设置阳光,还可以设置背景音乐。
最后点击左侧最下的项目,进行保存。
三、浪漫出现,美好即将开始!
(这里是截屏,当然还可以配上音乐录制成视频,惊喜加倍哦!)
愿得一人心,白头不相离。 这首诗来自卓文君与司马相如的爱情故事,被一直延用至今,甚至被谱写成歌曲传唱。遇一人白首,这是大多数人的美好愿望,如果遇到了就好好珍惜。
while True:
if We_Were_in_Love == True:
print('相爱一起到永远!')
爱不需要解释,但不妨让浪漫偶尔点缀下…
边栏推荐
- 627. Change of gender
- dmp (dump) dump file
- In 2022, you still can't "low code"?Data science can also play with Low-Code!
- Note that Weifang generally needs to pay attention to issuing invoices
- How to sort multiple fields and multiple values in sql statement
- 链表的简单描述及代码的简单实现
- DAY22: sqli-labs shooting range clearance wp (Less01~~Less20)
- mysql tree structure query problem
- 1484. Sell Products by Date
- [Decryption] Can the NFTs created by OpenSea for free appear in my wallet without being chained?
猜你喜欢
Flink 1.15.1 Cluster Construction (StandaloneSession)
Apache DolphinScheduler, a new generation of distributed workflow task scheduling platform in practice - Medium
CPDA|How Operators Learn Data Analysis (SQL) from Negative Foundations
Countdown to 2 days|Cloud native Meetup Guangzhou Station, waiting for you!
J9 Digital Currency: What is the creator economy of web3?
QT MV\MVC structure
mysql can't Execute, please solve it
Data storage practice based on left-order traversal
Data to enhance Mixup principle and code reading
Pisanix v0.2.0 released | Added support for dynamic read-write separation
随机推荐
Countdown to 2 days|Cloud native Meetup Guangzhou Station, waiting for you!
数据增强Mixup原理与代码解读
leetcode 15
Lexicon - the maximum depth of a binary tree
How OpenGL works
云原生(三十二) | Kubernetes篇之平台存储系统介绍
J9 Digital Currency: What is the creator economy of web3?
1873. 计算特殊奖金
你要的七夕文案,已为您整理好!
Use SuperMap iDesktopX data migration tool to migrate map documents and symbols
C language implements a simple number guessing game
[C language] Detailed explanation of stacks and queues (define, destroy, and data operations)
Principle and Technology of Virtual Memory
2022了你还不会『低代码』?数据科学也能玩转Low-Code啦!
The design idea of DMicro, the Go microservice development framework
倒计时 2 天|云原生 Meetup 广州站,等你来!
mysql树状结构查询问题
select tag custom style
627. Change of gender
Regular expression to match a certain string in the middle