2012-03-11 7 views
0

그래픽을 렌더링하는 데 도움이되는 자바 스크립트 라이브러리가 있는지 알고 싶습니다. Google을 검색했지만 도구를 찾지 못했습니다. 캔버스에 Gauss 커브를 만들고 싶습니다.Html5 Canvas Javascript libraries?

+0

20 분 이내에 중복 질문이나 투표 질문으로 마감 될 것으로 예상됩니다. 지금까지 어떤 도구를 찾았습니까? –

+0

그만한 가치가있는 곳은 html5 캔버스 자습서입니다 ... "라이브러리"가 없습니다 – Delarn

+3

https://www.google.com/search?q=canvas+libraries -> [첫 번째 검색 결과] (http : /javascript.open-libraries.com/utilities/drawing/10-best-javascript-drawing-and-canvas-libraries/). –

답변

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]; 
} 
+0

고마워! 어디서 찾았 니? 인터넷은 이상한 곳입니다! – Delarn

+0

@Delarn 당신은 잠시 후에 익숙해 질 것입니다.) –

+0

저는 웹 개발자를 10 년 동안두고 왔으며, 이제는 새로운 재미있는 기술이 나와서 그것을 다시 불러옵니다. 그리고 좋은 정보를 찾는 것은 아주 어렵습니다. 당신의 도움을 주셔서 감사합니다. – Delarn

2

몇 가지 html5 캔버스 자바 스크립트 라이브러리가 있습니다.

+0

고마워 할 것입니다! – Delarn

2

Here 내가 사용하고 KineticJS library 추천 한 자바 스크립트 라이브러리

+0

고마워 ... 나는 안드로이드에 대한 developping 그래서 rapahel 큰 없습니다;)하지만 감사합니다! – Delarn

3

라파엘, 종이 및 처리 사이에 잡지 스매싱에서 좋은 비교가 paper.js 더 완전한 사람 중 하나입니다. 적극적으로 유지 관리되고 정기적으로 업데이트됩니다.

1

Paper.js는 HTML5 캔버스에 매우 적합합니다. 이전에 언급했듯이 SVG 또는 VML 기반의 라이브러리는 안드로이드 장치에서 작동하지 않기 때문에 피해야합니다.