Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Linear transformation of a fish, to celebrate the 100th anniversary of D'Arcy Thompson's On Growth And Form, http://bit.ly/2GhFftW
<html>
<body>
<style>
td {
width: 100px;
border:thin solid lightGrey;
}
</style>
<svg width="100%" height="400px" xmlns="http://www.w3.org/2000/svg">
<g transform="matrix(1,0,0,1,0,0)">
<image xlink:href="https://i0.wp.com/thefishh.com/wp-content/uploads/2015/06/Fish-Pest-Rosy-Barb-600.jpg" x="0" y="0" width="600px" height="343px"/>
</g>
</svg>
<table>
<tr>
<td contenteditable>1</td>
<td contenteditable>0</td>
<td contenteditable>0</td>
</tr>
<tr>
<td contenteditable>0</td>
<td contenteditable>1</td>
<td contenteditable>0</td>
</tr>
<tr>
<td contenteditable>0</td>
<td contenteditable>0</td>
<td contenteditable>1</td>
</tr>
</table>
<button onclick="apply()">Apply</button>
<button onclick="reset()">Reset</button>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script>
function apply() {
let tmp = [];
let m = [];
$('td').map((i,o)=>{tmp[i] = parseFloat($(o).text())});
m = tmp.slice(0,6)
$('g').attr('transform',`matrix(${m[0]},${m[3]},${m[1]},${m[4]},${m[2]},${m[5]})`);
}
function reset() {
const matrix = [1,0,0,0,1,0,0,0,1];
$('td').map((i,o)=>$(o).html(matrix[i]));
apply();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.