Skip to content

Instantly share code, notes, and snippets.

@santhoshtr
Created February 13, 2026 10:05
Show Gist options
  • Select an option

  • Save santhoshtr/17a56c594617fd044d0b4c4d64ba59b8 to your computer and use it in GitHub Desktop.

Select an option

Save santhoshtr/17a56c594617fd044d0b4c4d64ba59b8 to your computer and use it in GitHub Desktop.
Untitled Metapost Sample #metapost-sandbox
% 设置输出文件名
outputtemplate := "%j.svg";
beginfig(1);
% --- 1. 变量声明 ---
numeric u, hex_R, hex_W;
numeric stem_w, bar_h, f_top_y;
color main_color;
path boundary_path;
picture fh_pattern;
% --- 2. 参数精调 ---
u := 1mm;
hex_R := 40u; % 六边形半径
hex_W := hex_R * sqrt(3) / 2; % 六边形半宽
stem_w := 14u; % 竖条宽度 (加粗,更有logo感)
bar_h := 6.5u; % 横条的半高度 (横条总粗细 = 13u)
f_top_y := 16u; % F顶部横条的中心高度
main_color := (0.1, 0.1, 0.1); % 纯深色,无分界线
% --- 3. 定义六边形外轮廓 ---
boundary_path := (0, hex_R) -- (hex_W, hex_R/2) -- (hex_W, -hex_R/2)
-- (0, -hex_R) -- (-hex_W, -hex_R/2) -- (-hex_W, hex_R/2) -- cycle;
% --- 4. 构建融合图案 ---
% 核心思路:绘制几个矩形块,让它们在空间上重叠,
% 因为颜色相同,Metapost 会将它们渲染成一个没有缝隙的整体。
fh_pattern := image(
% [竖向结构]
% 1. 左竖条 (F的背)
fill (-hex_W, -hex_R - u) -- (-hex_W + stem_w, -hex_R - u)
-- (-hex_W + stem_w, hex_R + u) -- (-hex_W, hex_R + u) -- cycle withcolor main_color;
% 2. 中竖条 (共用柱:F的右侧界 & H的左腿)
% 居中放置
fill (-stem_w/2, -hex_R - u) -- (stem_w/2, -hex_R - u)
-- (stem_w/2, hex_R + u) -- (-stem_w/2, hex_R + u) -- cycle withcolor main_color;
% 3. 右竖条 (H的右腿)
fill (hex_W - stem_w, -hex_R - u) -- (hex_W, -hex_R - u)
-- (hex_W, hex_R + u) -- (hex_W - stem_w, hex_R + u) -- cycle withcolor main_color;
% [横向连接 - 这里的填充会把竖条连接起来,融为一体]
% 4. 下层横梁 (贯穿整体)
% 连接 左-中 (F的中间横画) 和 中-右 (H的中间横画)
% 在视觉上,这是一条横跨整个logo的长条,位于中心位置
fill (-hex_W, -bar_h) -- (hex_W, -bar_h)
-- (hex_W, bar_h) -- (-hex_W, bar_h) -- cycle withcolor main_color;
% 5. 上层横梁 (F的顶部横画)
% 连接 左-中
fill (-hex_W, f_top_y - bar_h) -- (stem_w/2, f_top_y - bar_h)
-- (stem_w/2, f_top_y + bar_h) -- (-hex_W, f_top_y + bar_h) -- cycle withcolor main_color;
);
% --- 5. 剪裁 ---
% 用六边形“切”掉矩形多余的边角,形成完美的边缘
clip fh_pattern to boundary_path;
% 绘制
draw fh_pattern;
endfig;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment