Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[html] 第1910天 使用canvas画一个小汽车 #5876

Open
haizhilin2013 opened this issue Jul 7, 2024 · 1 comment
Open

[html] 第1910天 使用canvas画一个小汽车 #5876

haizhilin2013 opened this issue Jul 7, 2024 · 1 comment
Labels
html html

Comments

@haizhilin2013
Copy link
Collaborator

第1910天 使用canvas画一个小汽车

3+1官网

我也要出题

@haizhilin2013 haizhilin2013 added the html html label Jul 7, 2024
@tuna888
Copy link

tuna888 commented Jul 8, 2024

<script> window.onload = () => { const canvas = document.querySelector("#test"); if (canvas.getContext) { const ctx = canvas.getContext("2d"); ctx.beginPath(); ctx.moveTo(20,100) ctx.lineTo(185,100);

// 车头
ctx.quadraticCurveTo(180, 60, 135, 60);

// 车顶
ctx.arc(95,60,40,0,Math.PI,true);

// 车尾
ctx.quadraticCurveTo(30, 75, 20, 100)

ctx.fillStyle="pink";
ctx.fill();

// 窗户
ctx.beginPath();
ctx.fillStyle="skyblue";
ctx.fill();
ctx.fillRect(75,45,40,20)

// 前轮
ctx.beginPath();
ctx.moveTo(40,100);
ctx.arc(55,100,15,0,Math.PI*2,true);
ctx.fillStyle="#000";
ctx.fill();

// 后轮
ctx.beginPath();
ctx.moveTo(130,100)
ctx.arc(145,100,15,0,Math.PI*2,true);
ctx.fillStyle="#000";
ctx.fill();

// 车灯
ctx.beginPath();
ctx.arc(165,80,5,0,Math.PI*2,true);
ctx.fillStyle="yellow";
ctx.fill();

}
}
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
html html
Projects
None yet
Development

No branches or pull requests

2 participants