-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
122 lines (101 loc) · 2.46 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* Global Variables */
/* Background Variables */
var backgroundColor = '#2D1976'
/* BASELINE VARIABLES */
var baselineColor = '#ff0000'
var baselineWeight = 3
var baselineShouldRender = false
/* PRIMATIVE VARIABLES */
var primativeStrokeColor = '#D03DA7'
var primativeStrokeOpacity = 85
var primativeFillColor = '#000C7F'
var primativeFillOpacity = 50
var rotation = 2.7,
rotationMin = -45,
rotationMax = 45,
rotationStep = 0.1
var scaling = 2.3,
scalingMin = 0.1,
scalingMax = 10.0,
scalingStep = 0.1
var count = 100,
countMin = 1,
countMax = 360
var step = 8,
stepMin = 0,
stepMax = 300
var primativeStrokeWeight = 1.0,
primativeStrokeWeightMin = 1.0,
primativeStrokeWeightMax = 10.0
var gui;
var guiVisible = true
function setup() {
createCanvas(window.innerWidth, window.innerHeight)
angleMode(DEGREES)
blendMode(ADD)
gui = createGui('Stripe Pattern Control Panel | F1: show/hide | F2: collapse/expand')
gui.addGlobals(
'backgroundColor',
// 'baselineShouldRender',
// 'baselineColor',
// 'baselineWeight',
'primativeStrokeColor',
'primativeStrokeOpacity',
'primativeStrokeWeight',
'primativeFillColor',
'primativeFillOpacity',
'scaling',
'rotation',
'count',
'step'
)
gui.prototype.saveInLocalStorage('8-uh-stripe-patterns')
gui.prototype.setWidth(400)
gui.prototype.collapse()
noLoop()
}
function draw() {
clear()
background(backgroundColor)
push()
translate(width * 0.5, height * 0.5)
baseline()
stripePattern()
pop()
}
function baseline() {
if(baselineShouldRender) {
stroke(baselineColor)
strokeWeight(baselineWeight)
line(-width * 0.5,0, width,0)
}
}
function stripePattern() {
// Set stroke color & alpha
var sc = color(primativeStrokeColor)
sc._array[3] = map(primativeStrokeOpacity, 0, 100, 0, 1)
stroke(sc)
strokeWeight(primativeStrokeWeight)
// Set fill color & alpha
var fc = color(primativeFillColor)
fc._array[3] = map(primativeFillOpacity, 0, 100, 0, 1)
fill(fc)
for(let i = -count; i <= count; i++) {
push()
translate(i*step, 0)
scale(scaling, scaling)
rotate(i * rotation)
triangle(0, 0, -50, 100, 50, 100)
pop()
}
}
function keyPressed() {
switch(key) {
case 'p': // somehow this maps to F1... yeah... i don't get it either
gui.prototype.toggleVisibility()
break;
case 'q':
gui.prototype.toggleCollapsed()
break
}
}