“我想给我妈买一只熊猫,该怎么做.” Conversation with gpt-3.5-turbo-0301, from the WildChat-4.8M (AI2) dataset. The Chat Archive, 2023. https://thechatarchive.com/c/01m7h418dembkvhjp29qf7mymz
Copy citation
const canvas = document.getElementById("canvas");
const context = canvas.getContext("2d");
const btn = document.getElementById("btn");
const radius = 200;
const lineWidth = 10;
const colors = ["#FFA07A", "#87CEFA", "#F0E68C", "#FF69B4", "#98FB98", "#E0FFFF", "#7FFFD4", "#F08080", "#90EE90", "#DDA0DD"];
let angle = 0;
let index = 0;
let isRunning = false;
let timer;
function drawSector(startAngle, endAngle, color) {
context.beginPath();
context.moveTo(200, 200);
context.arc(200, 200, radius, startAngle, endAngle);
context.closePath();
context.fillStyle = color;
context.fill();
context.lineWidth = lineWidth;
context.strokeStyle = "#000";
context.stroke();
}
// 等分的角度
const unitAngle = (2 * Math.PI) / foods.length;
// 绘制扇形
for (let i = 0; i < foods.length; i++) {
const startAngle = i * unitAngle;
const endAngle = (i + 1) * unitAngle;
const color = colors[i % colors.length];
drawSector(startAngle, endAngle, color);
context.save();
context.translate(200, 200);
context.rotate(startAngle + unitAngle / 2);
context.fillStyle = "#fff";
context.font = "bold 30px Arial";
context.fillText(foods[i], 70, 0);
context.restore();
}
// 点击按钮,触发抽奖
function startLottery() {
if (isRunning) {
return false;
}
isRunning = true;
index = 0;
btn.disabled = true;
clearTimeout(timer);
rotate();
}
function rotate() {
context.clearRect(0, 0, 400, 400);
context.translate(200, 200);
context.rotate(angle);
context.translate(-200, -200);
for (let i = 0; i < foods.length; i++) {
const startAngle = i * unitAngle + angle;
const endAngle = (i + 1) * unitAngle + angle;
const color = colors[i % colors.length];
drawSector(startAngle, endAngle, color);
context.save();
context.translate(200, 200);
context.rotate(startAngle + unitAngle / 2 + angle);
context.fillStyle = "#fff";
context.font = "bold 30px Arial";
context.fillText(foods[i], 70, 0);
context.restore();
}
angle += Math.PI / 100;
if (angle >= 2 * Math.PI) {
angle = 0;
index = Math.floor(Math.random() * foods.length);
btn.disabled = false;
isRunning = false;
clearTimeout(timer);
alert(`你今天中午吃 ${foods[index]}!`);
} else {
timer = setTimeout(rotate, 30);
}
}
python Copy code
urlpatterns = [
path('', views.index, name='index'),
path('random_food', views.random_food, name='random_food'),
path('lottery', views.lottery, name='lottery'),
]