-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
51 lines (44 loc) · 1.1 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
let grid
let paragraph
let gridIndex = 2
function setup() {
createCanvas(450, 460)
colorMode(HSB)
strokeWeight(1)
grid = new PolarGrid(0, 0, 200)
paragraph = document.createElement('textarea')
paragraph.style.position = 'absolute'
paragraph.style.width = '0px'
paragraph.style.height = '0px'
paragraph.style.left = '-50px'
document.body.appendChild(paragraph)
}
function draw() {
background(0, 0, 11)
stroke(0)
grid.show()
fill(grid.color)
noStroke()
rect(0, 410, 50, 50)
}
function mouseClicked() {
if (mouseX > 0 && mouseX < 50 && mouseY > 410 && mouseY < 460)
copyColor()
}
function copyColor() {
let array = grid.color.levels
array.pop()
let string = array.map(x => x.toString(16).padStart(2, '0')).join('').toUpperCase()
paragraph.innerText = '#' + string
paragraph.select()
document.execCommand('copy')
}
function changeGrid() {
if (gridIndex == 1) {
gridIndex += 1
grid = new PolarGrid(0, 0, 200)
} else if (gridIndex == 2) {
gridIndex -= 1
grid = new CartesianGrid(0, 0, 400, 400)
}
}