如何定制一款属于程序员的卫衣

24次阅读

共计 3702 个字符,预计需要花费 10 分钟才能阅读完成。

厌倦了枯燥机械重复流水线的工作,每天时不时的被打断,不知道什么时候就被人圈到一群里,然后就要紧急支持一个事情。支线任务实在太多,晨会规划的主线任务实在没时间做,而且很多事逻辑负责,上下文切换成本太高,工作效率低下,还容易出 bug。

工作的越久,支撑的业务也就越来越多。想到其他二三线公司的同学或者是创业公司的同学都早就不在写业务代码了,想想自己的状态还是很失落的,再看着同样三年醇的同学都是专家,心里更是笑 cry 了。

情绪还是宣泄嘛,所以弄了一个卫衣来自嘲一番,主题curd boy,本想怎么设计个 logo,想了下太难了,也太费时间。后面使用一个wordcloud python 库来生成词云,然后重点突出下curd boy 更好体现了繁杂工作中的本质。

我翻开自己的 git commit 一查,这代码没有年代,歪歪斜斜的每行都写着 “ 业务驱动 ” 四个字。我横竖睡不着,仔细看了半夜,才从字缝里看出字来,满本都写着两个词是 “CURD Boy”!

独乐乐不如众乐乐

想有这个自嘲的肯定不止我一个人,不如给群友么一起来制作,客服告诉我人越多越便宜,最后凑到了 30 人,然后被告知和 5 个人价格一个,感觉被套路了,前面一直不说多少钱,原来别人的便宜是有阶梯的,到 50 人才能更便宜,真是白折腾了。而且还要承担衣服不好看被群里吐槽的风险。

发起个活动真不容易,还要对接客服,还要对接有意愿买衣服的同学,看大家喜欢什么款式。

踩了个坑,商家不支持分别发货,只支持集中发给我一个人。所以我还需要把大家的衣服二次快递分发给大家。

所以又弄了个表单收集大家的衣服颜色、尺寸和收货地址。运营的工作也真是枯燥,把商家的尺寸、颜色手动搬过来。

还要督促大家填表,真是操碎了心,还不如 5 人成团了,哈哈。

我是怎么做的呢

虽然工作很枯燥, 咱们总得给自己找点乐子吧. 其实挺 low 的,不过就是好玩嘛,curd boy的事需要优雅么?

第一步 弄个简单词库

首先, 从 highlight.js 提取我常用的语言的关键字, 然后又随便搞了些我脑袋里立马能想出来的一些名词、函数等。然后给一些需要重点突出的词增加权重。

<?php
$map = [
    "go" => "default func interface map struct chan else goto package switch const fallthrough if range type  for import return var go defer",
    "java" => "false synchronized int abstract float private char boolean var static null if const for true while long strictfp finally protected import native final void enum else  transient catch instanceof byte super volatile  assert short package default double public try this switch  throws protected public private module requires exports do",
    "python" => "and elif is global as in if from raise for except finally print import pass return exec else  not with class assert yield try while  del or def lambda async await",
    "php" => "and include_once list abstract global private echo interface as static endswitch array null if endwhile or const for endforeach self var while isset public protected exit foreach throw elseif include empty require_once do xor return parent clone use else  print eval new catch  exception default die require  enddeclare final try switch continue endfor endif declare unset true false trait goto instanceof insteadof yield finally composer var_dump strstr strlen array_map callback",
    "javascript" => "in of if for while finally var new function do return void else break catch instanceof with throw case default try this switch continue typeof delete let yield const export super debugger as async await static import from as true false null undefined NaN Infinity eval Promise",
    "c c++" => "unsigned long volatile static protected bool template mutable if public friend malloc realloc memchr memcmp memcpy memset do goto auto void enum else break extern using asm case typeid printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan",
    "shell" => "ls cd pwd kill ps top du alias ln awk cat tail",
    "mysql" => "varchar distinct",
    "asm" => "add push mov rbp rsp eax add push mov rbp rsp eax"
];


$str = "";
foreach ($map as $k => $v) {$str .= str_repeat($k." ",5);
    $str .= $v." ";
}

$map = [
    2 => "cmake gcc make install yum wget curl  php-fpm websocket pip tcp udp connect read write close select poll epoll stream",
    3 => "Laravel Symfony SpringBoot strace netstat socket nginx",
];

foreach ($map as $num => $v){$str .= str_repeat($v." ",$num);
}

$str .= str_repeat("CURD",20);
$str .= str_repeat("Boy",20);

file_put_contents("keywords.txt",$str);

第二步 找个称手工具

pip3 install wordcloud
pip3 install matplotlib

第三步 写生成图片脚本

因为要去做衣服,所以我选择生成的是透明的 png, 因为生成图片各个单词的位置是随机的,所以我需要重复生成,然后选择一个 curdboy两个单词都比较居中的使用,所以生成的文件名就用时间戳。

#!/usr/bin/env python3

import wordcloud
import time

words = open("keywords.txt");
text = words.read();

w = wordcloud.WordCloud(
    width = 2363,
    height = 945,
    background_color = None,
    collocations=False,
    scale=3,
    max_words=400,
    max_font_size=380,
    mode='RGBA',
    margin=3,
    font_path='/System/Library/Fonts/Menlo.ttc',
#     colormap = 'tab20'
)
w.generate(text)
w.to_file('curd/'+ str(int(time.time())) +'.png')

colormap 可以控制单词的颜色变化, 经过尝试 tab20 很好看,但是对底色的兼容性不好,比如我要印刷的衣服颜色比较多的话,就容易出现 bug 了。

https://matplotlib.org/exampl… 查看 colormap 配色

第四步 艺术选择

while :; do php keywords.php && ./create.py ; done

循环不停的生成,然后我在“AI”制作的图片中挑选最符合我要求的那个,耗费了我大半天。

有兴趣的同学也可以下载这个库玩玩。平常做 PPT 可以用。

总结

本次活动耗费了一两天的时间,后面还需要发货,成本非常高。没有一个颗顽皮的心,还是不要玩这个了。

正文完
 0