设计与产品github.com
T * sin(t) ≈ 圣诞树(2013)
T * sin (t) ≈ Christmas tree (2013)
2013 — 2020,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是一个用三角函数/参数方程生成圣诞树的创意编程项目,2013 年发布后多次登上 Hacker News。页面把简洁的数学曲线变成节日视觉,并引发了许多不同语言和工具的复现与变体。
为什么经久不衰:它把短小优雅的数学公式变成可运行、可改编的视觉作品,复现门槛低又充满节日趣味,所以多年后仍被反复分享。
HN 评论精选
提供了一段可直接运行的 Python/matplotlib 复现代码。
用 numpy 和 matplotlib 可以快速画出 3D 版:用螺旋线生成绿色和红色星点,再加一个金色顶星(代码略)。
Anon84查看英文原文
And in (quick and dirty) Python, with matplotlib: import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = fig.gca(projection='3d') theta = np.linspace(-4 * np.pi, 4 * np.pi, 100) r = 4*np.pi+theta z = -r x = r * np.cos(theta) y = r * np.sin(theta) ax.plot(x, y, z, 'g*') r2 = 4*np.pi+theta+np.pi/2 z2 = -r2+np.pi x2 = r * np.cos(theta+np.pi/2) y2 = r * np.sin(theta+np.pi/2) ax.plot(x2, y2, z2, 'r*') ax.scatter3D(0, 0, 5, color='gold', s=200, marker="d") ax.axis('off') :)
推荐 Wolfram 社区里的另一种圣诞树变体。
这个 Wolfram 变体大概是我最喜欢的版本。
shakna查看英文原文
This one [0][1] is probably my favourite variation. [0] https://community.wolfram.com/c/portal/getImageAttachment?filename=tree.gif&userId=93201 [1] Silvia Hao's reply at https://community.wolfram.com/groups/-/m/t/175891 (Also, why doesn't it have id attributes for individual replies?)
指出可以在 Desmos 中交互式动画复现。
在 Desmos 图形计算器里快速复现了;点 t_0 旁边的播放键即可动画。
jwmerrill查看英文原文
Quick reimplementation in the desmos graphing calculator: https://www.desmos.com/calculator/brjshfkaof Press play next to t_0 to animate.
怀旧地对比早年笨拙实现,感慨优雅代码的魅力。
这让我想起刚用 Turbo Pascal 编程时,用图形模式和三角函数画圣诞树;我只用 if-then 写了上千行。看到这棵更优雅的树,让我想起自己为什么选择这个职业。
zafka查看英文原文
This reminds me of when I first started programming in Turbo Pascal. I made a Christmas tree using graphic mode and trig functions. I also only used if-then statements so i ended up with about a thousand lines :) Looking at this more elegant tree reminds me of why I went into this career.
历次讨论
同类还值得读
贝塞尔曲线入门
A Primer on Bézier Curves
Pomax 编写的贝塞尔曲线在线教程,从基础概念一路讲到曲线求交、投影、曲率等进阶内容,并配有可交互的示例和配套的 bezier.js 库。
设计与产品上首页 7 次 · 2014–2022pomax.github.io编辑精选WebGL 水面模拟
WebGL Water
Evan Wallace 制作的 WebGL Water 演示:在浏览器里实时渲染一片水面,展示折射、反射和焦散等 GPU 图形效果。
设计与产品上首页 6 次 · 2011–2025madebyevan.com设计建议:永远不要使用黑色
Design Tip: Never Use Black
设计随笔提出“永远不要用纯黑”的建议,主张在界面和绘画中改用深灰或带色相的暗色,并借阴影与色彩关系来论证。
设计与产品上首页 5 次 · 2012–2021ianstormtaylor.com用于思考不可想象之物的媒介
Media for Thinking the Unthinkable
Bret Victor 的这个页面围绕《Media for Thinking the Unthinkable》展开,探讨我们用来思考和表达复杂问题的媒介,以及以文字/符号为主的传…
设计与产品上首页 5 次 · 2013–2020worrydream.com编辑精选页面重量很重要
Page Weight Matters
博文讲 YouTube 工程师 Chris Zacharias 的一次页面瘦身实验:团队做了一个更轻量的页面版本,起初从整体平均加载时间看反而更慢;按地理区域分层后才发现,轻量版…
设计与产品上首页 4 次 · 2012–2022blog.chriszacharias.com