我想知道是否有任何JavaScript庫來幫助渲染圖形。我搜索谷歌,沒有找到任何工具。我想在畫布上製作高斯曲線。Html5 Canvas Javascript庫?
0
A
回答
2
這花了我15秒找到。玩它,直到它得到你喜歡的。
$(document).ready(drawGaussian);
var canvasContext;
var points;
var noise = 0;
function drawGaussian()
{
canvasContext = document.getElementById("gaussian-canvas").getContext("2d");
document.getElementById("gaussian-canvas").onclick = cycleNoise;
cycleNoise();
}
function cycleNoise()
{
canvasContext.clearRect(0, 0, 400, 400);
var m = Math.random() > .4
var amount = Math.round(Math.random() * 20000);
var size = Math.round(Math.random() * 3)+1;
document.getElementById("particles").innerHTML = amount;
document.getElementById("size").innerHTML = size;
switch(noise)
{
case 0:
drawGaussianField(amount, size, 200, 200, 400, 100, m);
document.getElementById("type").innerHTML = (m ? "Monochromatic" : "Chromatic") + " Field";
break;
case 1:
drawGaussianCurves(amount, size, 200, 200, 400, 150, m);
document.getElementById("type").innerHTML = (m ? "Monochromatic" : "Chromatic") + " Curves";
break;
case 2:
drawGaussianDiamond(amount, size, 200, 200, 400, 130, m);
document.getElementById("type").innerHTML = (m ? "Monochromatic" : "Chromatic") + " Diamond";
break;
case 3:
drawGaussianOval(amount, size, 200, 200, 300, 300, m);
document.getElementById("type").innerHTML = (m ? "Monochromatic" : "Chromatic") + " Circle";
break;
case 4:
drawGaussianBurst(amount, size, 200, 200, 120, 120, m);
document.getElementById("type").innerHTML = (m ? "Monochromatic" : "Chromatic") + " Burst";
break;
}
noise++;
if(noise > 4) noise = 0;
}
function drawGaussianField(amount, thickness, x, y, width, height, monochromatic)
{
for(i = 0; i < amount; i++)
{
points = getGaussianPoints();
setColor(monochromatic);
canvasContext.fillRect(x + ((width*.5) * points[3]), y + ((height*.5) * points[2]), thickness, thickness);
}
}
function drawGaussianCurves(amount, thickness, x, y, width, height, monochromatic){
for(i = 0; i < amount; i++)
{
points = getGaussianPoints();
setColor(monochromatic);
canvasContext.fillRect(x + ((width*.5) * points[0]), y + ((height*.5) * points[2]), thickness, thickness);
}
}
function drawGaussianDiamond(amount, thickness, x, y, width, height, monochromatic){
for(i = 0; i < amount; i++)
{
points = getGaussianPoints();
setColor(monochromatic);
canvasContext.fillRect(x + ((width*.5) * points[0]), y + ((height*.5) * points[3]), thickness, thickness);
}
}
function drawGaussianOval(amount, thickness, x, y, width, height, monochromatic){
for(i = 0; i < amount; i++)
{
points = getGaussianPoints();
setColor(monochromatic);
canvasContext.fillRect(x + ((width*.5) * points[0]), y + ((height*.5) * points[1]), thickness, thickness);
}
}
function drawGaussianBurst(amount, thickness, x, y, width, height, monochromatic){
for(i = 0; i < amount; i++)
{
points = getGaussianPoints();
setColor(monochromatic);
canvasContext.fillRect(x + ((width*.5) * points[2]), y + ((height*.5) * points[3]), thickness, thickness);
}
}
function setColor(val){
if(val)
{
canvasContext.fillStyle = '#ffffff';
}
else
{
canvasContext.fillStyle = "#"+Math.floor(Math.random()*16777215).toString(16);
}
}
function getGaussianPoints(){
var x1, x2, w, y1, y2;
do {
x1 = 2.0 * Math.random() - 1.0;
x2 = 2.0 * Math.random() - 1.0;
w = x1 * x1 + x2 * x2;
} while (w >= 1.0);
w = Math.sqrt((-2.0 * Math.log(w))/w);
y1 = x1 * w;
y2 = x2 * w;
return [x1, x2, y1, y2];
}
2
2
3
我已經使用並推薦KineticJS library在拉斐爾,紙和加工之間砸雜誌比較不錯。它會定期進行維護和更新。
1
Paper.js對於HTML5畫布非常有用。如前所述,您應該避免使用基於SVG或VML的庫,因爲大多數庫不能在Android設備上運行。
相關問題
- 1. Javascript Html5 canvas問題
- 2. Javascript,HTML5 Canvas,Score功能
- 3. javascript canvas html5性能問題
- 4. HTML5 - Canvas事件處理庫?
- 5. Html5 Canvas to Canvas Blit
- 6. Ajax - HTML5 Canvas
- 7. HTML5 Canvas animation clearRect
- 8. Dart HTML5 Canvas Library?
- 9. HTML5,Canvas和FireFox
- 10. HTML5 Canvas,shadowColor&shadowBlur
- 11. html5 canvas strokeStyle?
- 12. HTML5 Canvas Game Bug
- 13. Html5-canvas Bug
- 14. HTML5 Large canvas
- 15. soft edges html5 canvas
- 16. HTML5 Canvas Growing Circles
- 17. Html5 Canvas overlay
- 18. HTML5 canvas hittesting
- 19. HTML5 Canvas to Facebook
- 20. HTML5 canvas drop counter
- 21. Facebook Like HTML5 Canvas
- 22. Html5 canvas drawImage stretched
- 23. HTML5 Canvas Circle Text
- 24. HTML5 - canvas createLinearGradient vertical
- 25. Html5 Canvas Limitations
- 26. HTML5 Canvas drawImage TideSDK
- 27. HTML5 Canvas對象
- 28. HTML5 Canvas Scale position
- 29. HTML5和Canvas/createImageData
- 30. HTML5 canvas to PDF
我預計這將在不到20分鐘內作爲重複或投票問題關閉。目前您發現了哪些工具? – 2012-03-11 03:20:12
唯一值得的地方是html5畫布教程...但沒有「圖書館」 – Delarn 2012-03-11 03:25:14
https://www.google.com/search?q=canvas+libraries - > [第一個搜索結果](http:/ /javascript.open-libraries.com/utilities/drawing/10-best-javascript-drawing-and-canvas-libraries/)。 – 2012-03-11 03:30:12