三维的Github Contribution(加入Nodejs关键词) Nodejs 三维的Github Contribution如何展示
三维的Github Contribution(加入Nodejs关键词)
Nodejs 三维的Github Contribution如何展示
github:https://github.com/SatanWoo/3D-Github-Contribution
第一次写Node.js,想法不是自创的,是来源这个Chrome插件isometric-contributions的想法。
Demo地址:https://github-3d-contribution.herokuapp.com/
第一次写,轻喷哈~谢谢大家啦。
三维的Github Contribution(加入Node.js关键词)
Node.js 三维的Github Contribution如何展示
在本篇博文中,我们将探讨如何使用Node.js来创建一个三维的GitHub贡献图。这个项目灵感来源于一个Chrome插件isometric-contributions,它以一种新颖的方式展示了用户的GitHub贡献。
GitHub Repository: 3D-Github-Contribution
Demo: 3D GitHub Contribution
首先,我们需要安装一些必要的依赖包。这里我们使用axios
来获取GitHub API的数据,以及three.js
来构建三维图形。
npm install axios three express
接下来,我们创建一个简单的Express服务器来处理HTTP请求,并使用Three.js库来渲染三维模型。
// server.js
const express = require('express');
const app = express();
const axios = require('axios');
app.use(express.static('public'));
app.get('/api/contributions', async (req, res) => {
const username = req.query.username;
if (!username) {
return res.status(400).send('Username is required.');
}
try {
const response = await axios.get(`https://api.github.com/users/${username}/events/public`);
const contributions = processContributions(response.data);
res.json(contributions);
} catch (error) {
console.error(error);
res.status(500).send('Failed to fetch contributions.');
}
});
function processContributions(events) {
// 这里可以添加逻辑来解析GitHub事件并生成贡献数据
return events; // 示例返回所有事件
}
app.listen(3000, () => {
console.log('Server running on http://localhost:3000');
});
在客户端,我们可以使用Three.js来渲染这些贡献数据。这里是一个简单的示例:
<!-- public/index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D GitHub Contributions</title>
<style>
body { margin: 0; overflow: hidden; }
</style>
</head>
<body>
<script src="/socket.io/socket.io.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
let scene, camera, renderer;
init();
animate();
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// 添加其他Three.js初始化代码
}
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
</script>
</body>
</html>
以上代码提供了一个基本的框架,你可以在此基础上进一步扩展和完善。例如,你可以在Three.js中创建一个网格来表示每一天的贡献,通过颜色或高度来区分不同的贡献等级。此外,还可以增加交互功能,如鼠标悬停时显示详细信息等。
希望这个示例能帮助你开始你的三维GitHub贡献图项目!如果你有任何问题或建议,欢迎随时反馈。
哈哈,挺有意思。
效果看起来很赞呐