Last active
August 25, 2017 01:50
-
-
Save RoySung/743bde6cc4ae219cafa05346e2281205 to your computer and use it in GitHub Desktop.
simple drawing bitmap by svg // source http://jsbin.com/suhimuraki
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Snap.svg vs Svg.js</title> | |
<script src="https://rawgithub.com/adobe-webplatform/Snap.svg/master/dist/snap.svg.js"></script> | |
</head> | |
<body> | |
<button onclick="handleOutput()">Output</button> | |
<svg id="bitmap" width="1000" height="1000" ></div> | |
<script id="jsbin-javascript"> | |
var svg = Snap('#bitmap'); | |
var arr = []; | |
var x=10,y=10 | |
var handleClick = function(index) { | |
if ( arr[index].attr('fill') == "rgba(0, 0, 0, 0)" ) | |
arr[index].attr({fill: "black"}) | |
else | |
arr[index].attr({fill: "transparent"}) | |
} | |
for (let i = 0; i < x; i++) { | |
for (let j = 0; j < y; j++) { | |
let index = i * x + j | |
arr[index] = svg.paper.rect(j*50, i*50, 50, 50, 0); | |
arr[index].attr({class: 'rows', fill: "transparent", stroke: "black", "stroke-width": 1, onclick: `handleClick(${index})`}) | |
} | |
} | |
// c1.attr({fill: "transparent", stroke: "black", strokeDasharray: "150,50"}) | |
function handleOutput() { | |
let value = arr[0].attr("stroke-width") != '0px' ? 0 : 1 | |
arr.map(row => { | |
row.attr({"stroke-width": value}) | |
}) | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var svg = Snap('#bitmap'); | |
var arr = []; | |
var x=10,y=10 | |
var handleClick = function(index) { | |
if ( arr[index].attr('fill') == "rgba(0, 0, 0, 0)" ) | |
arr[index].attr({fill: "black"}) | |
else | |
arr[index].attr({fill: "transparent"}) | |
} | |
for (let i = 0; i < x; i++) { | |
for (let j = 0; j < y; j++) { | |
let index = i * x + j | |
arr[index] = svg.paper.rect(j*50, i*50, 50, 50, 0); | |
arr[index].attr({class: 'rows', fill: "transparent", stroke: "black", "stroke-width": 1, onclick: `handleClick(${index})`}) | |
} | |
} | |
// c1.attr({fill: "transparent", stroke: "black", strokeDasharray: "150,50"}) | |
function handleOutput() { | |
let value = arr[0].attr("stroke-width") != '0px' ? 0 : 1 | |
arr.map(row => { | |
row.attr({"stroke-width": value}) | |
}) | |
} | |
</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var svg = Snap('#bitmap'); | |
var arr = []; | |
var x=10,y=10 | |
var handleClick = function(index) { | |
if ( arr[index].attr('fill') == "rgba(0, 0, 0, 0)" ) | |
arr[index].attr({fill: "black"}) | |
else | |
arr[index].attr({fill: "transparent"}) | |
} | |
for (let i = 0; i < x; i++) { | |
for (let j = 0; j < y; j++) { | |
let index = i * x + j | |
arr[index] = svg.paper.rect(j*50, i*50, 50, 50, 0); | |
arr[index].attr({class: 'rows', fill: "transparent", stroke: "black", "stroke-width": 1, onclick: `handleClick(${index})`}) | |
} | |
} | |
// c1.attr({fill: "transparent", stroke: "black", strokeDasharray: "150,50"}) | |
function handleOutput() { | |
let value = arr[0].attr("stroke-width") != '0px' ? 0 : 1 | |
arr.map(row => { | |
row.attr({"stroke-width": value}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment