Make tartan weaver do a tilable image
This commit is contained in:
parent
7438074515
commit
9efcff9445
|
@ -2,7 +2,7 @@ Title: Tartans
|
|||
Header: <script src="weave.js"></script>
|
||||
Header: <script src="presets.js"></script>
|
||||
|
||||
<canvas id="loom" width="800" height="600" style="width: 100%; background: #444;">
|
||||
<canvas id="loom" width="800" height="800" style="width: 100%; background: #444;">
|
||||
Sorry, you need HTML5 and JavaScript for this.
|
||||
<img src="nmloe.png">
|
||||
</canvas>
|
||||
|
@ -11,7 +11,6 @@ Header: <script src="presets.js"></script>
|
|||
<select id="preset"><option>Presets:</option></select>
|
||||
<input id="sett" size="30">
|
||||
<span style="white-space: nowrap;">
|
||||
Zoom: <select id="thick"><option>0.8</option><option>1</option><option selected>2</option><option>3</option></select>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
//
|
||||
|
||||
var maxSaturation = 200;
|
||||
var yarnWeight = 3;
|
||||
|
||||
function Yarn(r, g, b) {
|
||||
var rgb = [Math.round(r*maxSaturation), Math.round(g*maxSaturation), Math.round(b*maxSaturation)]
|
||||
|
@ -54,7 +55,7 @@ function Loom(ctx, warp, threadwidth) {
|
|||
var width = ctx.canvas.width;
|
||||
var height = ctx.canvas.height;
|
||||
|
||||
ctx.lineWidth = Number(threadwidth || 2);
|
||||
ctx.lineWidth = Number(threadwidth || yarnWeight);
|
||||
|
||||
// Avoid infinite loop
|
||||
if (warp.length == 0) {
|
||||
|
@ -62,7 +63,7 @@ function Loom(ctx, warp, threadwidth) {
|
|||
}
|
||||
|
||||
// Draw the weft
|
||||
for (var x = 0; x < width; ) {
|
||||
for (var x = 0; x <= width; ) {
|
||||
for (var i in warp) {
|
||||
ctx.strokeStyle = warp[i];
|
||||
ctx.beginPath();
|
||||
|
@ -173,18 +174,22 @@ function weave(pattern, width) {
|
|||
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
var sett = settOfString(pattern);
|
||||
|
||||
var x = width * sett.length * 2;
|
||||
canvas.width = x;
|
||||
canvas.height = x;
|
||||
|
||||
var l = new Loom(ctx, sett, width);
|
||||
l.plaid();
|
||||
}
|
||||
|
||||
function update(reset) {
|
||||
var settInput = document.getElementById("sett");
|
||||
var thickInput = document.getElementById("thick");
|
||||
weave(settInput.value, thick.value);
|
||||
weave(settInput.value, yarnWeight);
|
||||
|
||||
if (reset) {
|
||||
var s = encodeURIComponent(settInput.value).replace(/%20/g, "+");
|
||||
window.location.hash = "s=" + s + "&w=" + thickInput.value;
|
||||
window.location.hash = "s=" + s;
|
||||
|
||||
document.getElementById("preset").value = "Presets:";
|
||||
document.getElementById("desc").innerText = "";
|
||||
|
@ -224,15 +229,11 @@ if (window.location.hash) {
|
|||
|
||||
function init() {
|
||||
document.getElementById("sett").addEventListener("input", update);
|
||||
document.getElementById("thick").addEventListener("input", update);
|
||||
|
||||
|
||||
if (qs["s"]) {
|
||||
document.getElementById("sett").value = qs["s"];
|
||||
}
|
||||
if (qs["w"]) {
|
||||
document.getElementById("thick").value = qs["w"];
|
||||
}
|
||||
|
||||
var presetName = qs["p"];
|
||||
var presetInput = document.getElementById("preset")
|
||||
|
|
Loading…
Reference in New Issue