gpt4 book ai didi

javascript - 渐变到圆圈

转载 作者:太空宇宙 更新时间:2023-11-04 12:13:00 24 4
gpt4 key购买 nike

<head>
<title></title>
</head>

<body>
<canvas id="mycanvas" width="800" height="600" style="border: 1px solid black;">
upload yor browser old man!
</canvas>

<script type="text/javascript">

var c = document.getElementById("mycanvas");
var cxt = c.getContext( "2d" );

grad = cxt.createLinearGradient( 0 , 0 , 200 , 200 );

grad.addColorStop( 0 , "blue" );
grad.addColorStop( 1 , "green" );

cxt.fillStyle = grad;
cxt.arc( 400 , 300 , 250 , 0 , Math.PI * 2 , true );
cxt.fill();
</script>

</body>

我正在尝试将渐变放入圆圈中,问题是圆圈只是绿色,渐变失去了蓝色,或者渐变不起作用。谢谢。

最佳答案

这是因为你的渐变在你的圈子开始之前就结束了:

        var c = document.getElementById("mycanvas");
var cxt = c.getContext( "2d" );

grad = cxt.createLinearGradient( 0 , 0 , 200 , 200 );

grad.addColorStop( 0 , "blue" );
grad.addColorStop( 1 , "green" );

cxt.fillStyle = grad;
cxt.rect(0,0,c.width, c.height);
cxt.fill();
cxt.strokeStyle = "#000";
cxt.arc( 400 , 300 , 250 , 0 , Math.PI * 2 , true );
cxt.fill();
cxt.stroke();
<canvas id="mycanvas" width="800" height="600" style="border: 1px solid black;">
</canvas>

关于javascript - 渐变到圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28912853/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com