English 中文(简体)
你们将如何根据一种制造的血管体形成一种微粒的电流? RUSS CANVAS JS
原标题:How would you create a particle SURFACE emitter based on a created canvas shape? HTMLS CANVAS JS

我有一个图形(四分之一圈子),我是利用html信封功能创建的:

  • moveTo
  • LineTo
  • QuadraticCurveTo

我如何将形状探索成微粒,然后将其送回成圈?

问题回答

我不想为你们写这部法典,因为它需要一定时间,我相信你能够找到网上的例子,但我要告诉大家,为了做到这一点,你需要知道的理论。

  1. Create an in-memory canvas (using document.createElement( canvas )) that will never be seen on the page. This canvas must be at least as large as your object. I m going to assume it is exactly as large as your object. We ll call this tempCanvas and it has tempCtx
  2. Draw your object to tempCtx.
  3. There will be some event that you didn t mention exactly but I m sure you have in mind. Either you press a button or click on the object and it "explodes". For the sake of picking something I ll assume you want it to explode on click.

爆炸:

  1. Draw the object onto your normal context: ctx.drawImage(tempCanvas, x, y) so the user sees something
  2. You re going to want to have an array of pixels for the location of each pixel in tempCanvas. So if tempCanvas is 20x30 you ll want an array of [20][30] to correspond.
  3. You have to keep data for each of those pixels. Specifically, their starting point, which is easy, because pixel [2][4] s starting point is (2,4)! And also their current location, which is identical to starting point at first but will change on each frame.
  4. When the explosion event occurs keep track of the original mouse x and y position.
  5. At this point for every single pixel you have a vector which means you have a direction. If you clicked in the middle of the object you ll want to save the mouse coordinates of (10,15) (see note 1). So now all of the pixels of the to-be-exploded image have their trajectory. There s a bit of math here that I m taking for granted, but if you search separate topics either on SO or on the internet you ll find out how to find the slope/etc of these lines and continue them.
  6. For every frame hereafter you must take each pixel [x][y] and use ctx.drawImage(tempCanvas, x, y, 1, 1, newX, newY, 1, 1) where x and y are the same as the pixel s [x][y] and the newX and newY are calculated using the vector and finding what the next point would be along its line.

其结果将是从原点点点略多的某个地点抽取图像的每个图形。 如果你在框架之后继续这样做,就会看看该物体是否爆炸。

这是一条总的想法。 让我知道,其中是否有任何内容不明确。

说明 1. 您的正常血管胜出的频率与发射物体相同。 也许该物体被放置在10时05分,因此,你真心要点击110 115而不是10.15。 仅为了简单起见,我略去掉。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签