在html画布上下雨动画(rain drop animation on html canvas)
我试图在canvas上创建水滴下降效果。我使用array创建了一些样本滴。为它设置动画我的意思是改变它们的位置我引入了一个setTimeout函数。它适用于单个水滴。因为我的画布上有多个滴它不再工作.drops仍然是静止的。如果setTimeout函数可以用来为所有单独的drop动画?
这里是小提琴jsfiddle
单个拖放单滴动画的动画效果
<html> <head> </head> <body> <script> function makeit(){ var canvas=document.getElementById("mycanvas"); var ctx=canvas.getContext('2d'); canvas.width=600; canvas.height=600; canvas.style.border="1px solid black"; var drop=function (x,y){ ctx.save(); ctx.fillStyle="orange"; ctx.fillRect(0,0,canvas.width,canvas.height); ctx.fill(); ctx.fillStyle="red"; ctx.moveTo(x-5,y); ctx.lineTo(x,y-7); ctx.lineTo(x+5,y); ctx.arc(x,y,5,0,Math.PI); ctx.closePath(); ctx.fill(); ctx.restore(); y=y+3; if(y==canvas.height){ y=0; } var m=setTimeout('drop('+x+','+y+')',20); } var xpos=[10,20,30,40,50,60,70,70,76]; var ypos=[30,20,60,80,76,90,30,40,79]; for(i=0;i<xpos.length;i++){ drop(xpos[i],ypos[i]); } } window.onload=makeit; </script> <canvas id="mycanvas" ></canvas> </body> </html>
I am trying to create water drop falling effect on canvas.I created some sample drops using array.to animate it i mean to change their positions i introduced a setTimeout function.it worked for single water drop.since there are multiple drops on my canvas it is not working anymore.drops remain still.how the setTimeout function can be used to animate all the individual drops?
here is the fiddle jsfiddle
animate effect for an individual drop single drop animation
<html> <head> </head> <body> <script> function makeit(){ var canvas=document.getElementById("mycanvas"); var ctx=canvas.getContext('2d'); canvas.width=600; canvas.height=600; canvas.style.border="1px solid black"; var drop=function (x,y){ ctx.save(); ctx.fillStyle="orange"; ctx.fillRect(0,0,canvas.width,canvas.height); ctx.fill(); ctx.fillStyle="red"; ctx.moveTo(x-5,y); ctx.lineTo(x,y-7); ctx.lineTo(x+5,y); ctx.arc(x,y,5,0,Math.PI); ctx.closePath(); ctx.fill(); ctx.restore(); y=y+3; if(y==canvas.height){ y=0; } var m=setTimeout('drop('+x+','+y+')',20); } var xpos=[10,20,30,40,50,60,70,70,76]; var ypos=[30,20,60,80,76,90,30,40,79]; for(i=0;i<xpos.length;i++){ drop(xpos[i],ypos[i]); } } window.onload=makeit; </script> <canvas id="mycanvas" ></canvas> </body> </html>
原文:https://stackoverflow.com/questions/23834989
最满意答案
您对
google.auth.JWT()
论点似乎是错误的。 请参阅文档中的示例以及此处的googleapis
repo中的JWT示例。 如果您没有为第二个参数传递密钥文件名,则第三个参数应该是文字密钥数据。 所以只需为第三个参数添加null
:let jwtClient = new google.auth.JWT( key.client_email, key.private_key, null, ['https://www.googleapis.com/auth/analytics.readonly'], null );
Your arguments to
google.auth.JWT()
seem to be wrong. See the example in the documentation and the JWT example in thegoogleapis
repo here. The third argument should be the literal key data if you are not passing a key filename for the second argument. So just addnull
for the third argument:let jwtClient = new google.auth.JWT( key.client_email, key.private_key, null, ['https://www.googleapis.com/auth/analytics.readonly'], null );
相关问答
更多-
如何向Google Analytics报告API v4进行身份验证(How to authenticate to Google Analytics Reporting API v4)[2023-04-08]
发现我错过了什么: Google API客户端库“选项”: google.options({ auth: oauth2Client }); //this one is not very optional 与Google Analytics Reporting API v4文档不同,使用客户端库的查询必须具有标头,以便为每个请求指定一个客户端(感谢CVarisco发现客户端库文档不准确..): var request ={ 'headers': {'Content-Type': 'applicati ... -
您在此处将analytics定义为局部变量: jwtClient.authorize(function (err, tokens) { if (err) { console.log(err); return; } let analytics = google.analytics('v3'); queryData(analytics); }); 然后期望它在您的导出中的queryData(analytics)中可用。 你可以做的是在一个promise中解析你的author ...
-
好。 这是一个简单的块对齐问题。 我需要对齐这部分: from apiclient.http import MediaFileUpload try: media = MediaFileUpload('mycsv.csv', mimetype='application/octet-stream', resumable=False) daily_upload = analytics.managemen ...
-
无法使用节点和GA分析API读取null错误的属性“join”(Cannot read property 'join' of null error with node and GA analytics api)[2022-02-02]
您对google.auth.JWT()论点似乎是错误的。 请参阅文档中的示例以及此处的googleapis repo中的JWT示例。 如果您没有为第二个参数传递密钥文件名,则第三个参数应该是文字密钥数据。 所以只需为第三个参数添加null : let jwtClient = new google.auth.JWT( key.client_email, key.private_key, null, ['https://www.googleapis.com/auth/analytics.rea ... -
您可能需要检查您的MongoDB服务是否已启动并在给定端口上运行。 打开命令提示符( WindowsKey+R->cmd->OK )并运行以下命令: netstat -a | find "27017" 这应该给你一些这样的输出: TCP 127.0.0.1:27017
:0 LISTENING 如果你没有看到这一行,你需要启动MongoDB或确保它在默认端口上运行。 第二个错误"Cannot read property 'close' of ... -
尝试升级到更新版本的npm(3.x)。 我已经看到与其他非Appcelerator项目的问题。 Apart from the above process which have been mentioned by my fellow developers, following too will work without making any changes in the environment. This would require the 2-phase build. For reference let u ...
-
GA Analytics Reporting API - 身份验证停止运行(GA Analytics Reporting API - authentication stopped working)[2022-12-31]
我能够通过在托管集成脚本的服务器上运行命令sudo ntpdate ntp.ubuntu.com来解决此问题。 这会使时间与ntp服务器同步。 时间只有几分钟,似乎有很大的不同。 I was able to solve this issue by running the command sudo ntpdate ntp.ubuntu.com on the server hosting integration scripts. This synchronizes the time with the ntp s ... -
就像错误说rows是未定义的。 这是因为没有为该查询返回数据。 来自以下网址的文档: https : //developers.google.com/youtube/analytics/v1/reference/reports/query#response 如果给定查询没有可用数据,则响应中将省略rows元素。 Just like the error says rows is undefined. This is because there is no data being returned for tha ...
-
ga:dfpRevenue受限制(ga:dfpRevenue is Restricted)[2022-09-20]
设置DFP广告管理系统报表集成 预检清单要在GA中查看DFP报告,必须满足以下条件: 您有一个Google Analytics 360帐户。 您网站上的大多数代码都是Google发布商代码(GPT)。 选择将成为DFP和GA Premium管理员的用户。 这仅适用于已设置为使用GPT的360帐户 Set up the DoubleClick for Publishers reporting integration Preflight checklist To see DFP reports in GA th ... -
ga:productPrice通过Analytics Core Reporting API(v3)(ga:productPrice via the Analytics Core Reporting API (v3))[2022-04-15]
Google Analytics中没有名为ga:productPrice维度。 但是GA中还有其他指标,例如ga:transactionRevenue , ga:revenuePerItem , ga:itemRevenue以及其他与交易和收入相关的指标。 以下是电子商务相关维度和指标的列表 。 希望能帮助到你 ! There is no dimension called ga:productPrice in Google Analytics. But there are other metrics in ...