-
Notifications
You must be signed in to change notification settings - Fork 0
/
WintrGradient.coffee
88 lines (58 loc) · 1.86 KB
/
WintrGradient.coffee
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
###*
* Generate a WINTR gradient based upon our styleguide
*
* @author Christopher Pappas <[email protected]>
* @date 5.9.14
###
WintrGradient =
# Default size of the canvas to be drawn upon
# @type {Number}
DEFAULT_SIZE: 512
# Base colors for composing gradients
# @type {Object}
COLORS:
plum:
light: '#A14F49'
dark: '#5b1915'
green:
light: '#ADD4BF'
dark: '#4E8273'
grey:
light: '#9F9F9F'
dark: '#777777'
pink: '#FD6685'
yellow: '#F8E99E'
aqua: '#A6FCEB'
orange: '#FC9170'
yellowPink: ->
return { start: @COLORS.yellow, stop: @COLORS.pink }
yellowAqua: ->
return { start: @COLORS.yellow, stop: @COLORS.aqua }
pinkAqua: ->
return { start: @COLORS.pink, stop: @COLORS.aqua }
yellowOrange: ->
return { start: @COLORS.yellow, stop: @COLORS.orange }
orangePink: ->
return { start: @COLORS.orange, stop: @COLORS.pink }
yellowGreen: ->
return { start: @COLORS.yellow, stop: @COLORS.green.light }
orangeAqua: ->
return { start: @COLORS.orange, stop: @COLORS.aqua }
# Generates a color gradient by taking an object consisting of
# `start` and `stop` and belending them together within a ctx
# @param {Object} colorRange
# @return {Context}
generate: (colorRange) ->
{start, stop} = colorRange
canvas = document.createElement 'canvas'
canvas.width = @DEFAULT_SIZE
canvas.height = @DEFAULT_SIZE
context = canvas.getContext '2d'
context.rect 0, 0, @DEFAULT_SIZE, @DEFAULT_SIZE
gradient = context.createLinearGradient 0, 0, @DEFAULT_SIZE, @DEFAULT_SIZE
gradient.addColorStop 0, start
gradient.addColorStop 1, stop
context.fillStyle = gradient
context.fill()
return canvas
module.exports = WintrGradient