-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolors.html
More file actions
161 lines (150 loc) · 4.98 KB
/
colors.html
File metadata and controls
161 lines (150 loc) · 4.98 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!DOCTYPE html>
<html lang="en">
<!-- M A Chatterje (c) 2024 -->
<head>
<meta charset="UTF-8">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<title>Color Mixing Demo</title>
<style>
body {
font-family: Arial, sans-serif;
}
.container {
display: flex;
justify-content: space-around;
margin-top: 20px;
}
.color-box {
width: 100%;
height: 40vh;
/* border: 1px solid #000; */
}
.slider-container {
text-align: left;
}
label {
width: 15%;
}
input {
width: 50%;
left : 0;
}
.red {
color: red;
}
.blue {
color: blue;
}
.green {
color: green;
}
.cyan {
color: cyan;
}
.magenta {
color: magenta;
}
.yellow {
color: yellow
}
.cyan, .magenta, .yellow {
background-color: #bbb;
font-weight: 600;
padding : 5px;
border-radius: 4px;
}
label {
margin: 4px;
padding: 5px;
border-radius: 4px;
background-color: #bbb !important;
font-weight : 600;
font-size: 1.2em;
min-width: 5em;
}
input {
width: 50%;
}
#additiveColors, #subtractiveColors{
width: 100%;
}
.explainText {
height: 15vh;
}
</style>
</head>
<body>
<div class="container">
<h1>Color Mixing Demo</h1>
</div>
<div class="container">
<div id="additiveColors">
<h2>Additive Colors (RGB)</h2>
<div class="explainText">
Light sources (like the sun or lightbulbs) are additively mixed to create color.<br>
The primary additive colors are <span class="red">red</span>, <span class="green">green</span>, and <span class="blue">blue</span>.
</div>
<br>
<div class="color-box" id="additive-color"></div>
<br>
<div id="additive-value">rgb(0,0,0)</div>
<br>
<div class="slider-container">
<label class="red">Red: </label><input type="range" id="r-slider" min="0" max="255" value="10" oninput="updateAdditiveColor()"><br>
<label class="green">Green: </label><input type="range" id="g-slider" min="0" max="255" value="30" oninput="updateAdditiveColor()"><br>
<label class="blue">Blue: </label><input type="range" id="b-slider" min="0" max="255" value="50" oninput="updateAdditiveColor()">
</div>
</div>
<div id="subtractiveColors">
<h2>Subtractive Colors (CMY)</h2> <div class="explainText">
Light reflectors and absorbers, such as paints, are subtractively mixed to create color.<br>
The primary subtractive colors are <span class="cyan">cyan</span>, <span class="magenta">magenta</span>, and <span class="yellow">yellow</span>.
</div><br>
<div class="color-box" id="subtractive-color" style="background-color: #ffffff;"></div>
<br>
<div id="subtractive-value">rgb(255,255,255)</div>
<br>
<div class="slider-container">
<label class="cyan">Cyan: </label><input type="range" id="c-slider" min="0" max="255" value="10" oninput="updateSubtractiveColor()"><br>
<label class="magenta">Magenta: </label><input type="range" id="m-slider" min="0" max="255" value="30"
oninput="updateSubtractiveColor()"><br>
<label class="yellow">Yellow: </label><input type="range" id="y-slider" min="0" max="255" value="50"oninput="updateSubtractiveColor()">
</div>
</div>
</div>
<script>
function updateAdditiveColor() {
var r = document.getElementById("r-slider").value;
var g = document.getElementById("g-slider").value;
var b = document.getElementById("b-slider").value;
var color = "RGB("+r+","+g+","+b+")" ;
// Convert CMY to RGB
var c = 255 - r;
var m = 255 - g;
var y = 255 - b;
var display = color + " is equal to CMY("+c+","+m+","+y+")";
document.getElementById("additive-color").style.backgroundColor = color;
document.getElementById("additive-value").innerText = display;
}
function updateSubtractiveColor() {
var c = document.getElementById("c-slider").value;
var m = document.getElementById("m-slider").value;
var y = document.getElementById("y-slider").value;
// Convert CMY to RGB
var r = 255 - c;
var g = 255 - m;
var b = 255 - y;
var color = "RGB("+r+","+g+","+b+")";
var display = "CMY("+c+","+m+","+y+") is equal to " + color;
document.getElementById("subtractive-color").style.backgroundColor = color;
document.getElementById("subtractive-value").innerText = display;
}
updateAdditiveColor();
updateSubtractiveColor();
</script>
</body>
</html>