admin管理员组文章数量:1403452
I want to create lines that look more like hand-drawn lines by adding randomness to them. I currently use this formula to modify the coordinates
x-10+Math.floor(Math.random()*20)
This random distribution is linear, I would like to use something that makes it more likely to hit the target. X
according to something that looks like, but doesn't have to be a bell-curve. How can this be done?
I want to create lines that look more like hand-drawn lines by adding randomness to them. I currently use this formula to modify the coordinates
x-10+Math.floor(Math.random()*20)
This random distribution is linear, I would like to use something that makes it more likely to hit the target. X
according to something that looks like, but doesn't have to be a bell-curve. How can this be done?
- 1 github./errcw/gaussian – Dai Commented Apr 6, 2015 at 19:35
- You can define a bell curve as an array of points (for example) and randomly pick from that array. But that is a bit brute force, are you looking for something like this? – Spencer Wieczorek Commented Apr 6, 2015 at 19:43
- Many alternatives there, most are plex or voted down because they are incorrect. I only need something that looks a bit bell-curve-ish, it's not to specific. Does anyone have a sugestion? – Himmators Commented Apr 6, 2015 at 20:21
- 1 Relevant: stackoverflow./q/29325069/251311 – zerkms Commented Apr 6, 2015 at 20:25
1 Answer
Reset to default 7Use the probability density function that defines the standard normal distribution:
function stdNormalDistribution (x) {
return Math.pow(Math.E,-Math.pow(x,2)/2)/Math.sqrt(2*Math.PI);
}
The function is symmetric around 0, which means stdNormalDistribution(x) == stdNormalDistribution(-x).
Source: Wikipedia: Normal Distribution
本文标签: Create a normal distributionlooking pattern in javascriptStack Overflow
版权声明:本文标题:Create a normal distribution-looking pattern in javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744376021a2603266.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论