-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
86 lines (74 loc) · 1.87 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// canvas
let width = 590;
let height = 570;
let drawdown_width = 500;
let drawdown_height = 500;
let cellSize = 10;
let drawdown;
// controls
let pan = 0;
let pZoom = 10; // Perlin noise zoom level
let glitchMod = 0;
let showLines = false;
// draft
let wefts = Math.floor(drawdown_height / cellSize); // Rows
let warps = Math.floor(drawdown_width / cellSize); // Columns
// structures
let jsonData;
function preload() {
jsonData = loadJSON('structures.json');
}
function setup() {
createCanvas(width, height);
textFont('Arial', 10);
textAlign(RIGHT);
let seed = int(random(1, 100));
noiseSeed(seed);
drawdown = new Drawdown(wefts, warps);
drawdown.loadPattern("twoByTwoTwill");
// create draft data
drawdown.createThreading();
drawdown.createTieup();
}
function draw() {
background(255);
// create unglitched liftplan
drawdown.createLiftPlan();
// glitch liftplan
drawdown.glitchLiftPlan();
// generate drawdown from liftplan
drawdown.createDrawdown();
// display draft
drawdown.printDraft();
noLoop()
}
function keyPressed() {
if (key === 'g') {
glitchMod++;
console.log("glitchMod: ", glitchMod);
loop();
} else if (key === 'd') {
glitchMod--;
console.log("glitchMod: ", glitchMod);
loop();
} else if (key === 'r') {
showLines = !showLines;
loop();
} else if (keyCode === UP_ARROW) {
pZoom += cellSize;
console.log("pZoom: ", pZoom);
loop();
} else if (keyCode === DOWN_ARROW) {
pZoom -= cellSize;
console.log("pZoom: ", pZoom);
loop();
} else if (keyCode === LEFT_ARROW) {
pan -= cellSize;
console.log("pan: ", pan);
loop();
} else if (keyCode === RIGHT_ARROW) {
pan += cellSize;
console.log("pan: ", pan);
loop();
}
}