-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubtractive.html
135 lines (133 loc) · 5.31 KB
/
subtractive.html
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
<!DOCTYPE html>
<html lang="en">
<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;
}
#colorMixing {
margin-top: 20px;
width: 100%;
}
#additiveMixHeading {
text-align: center;
}
.container {
display: flex;
justify-content: space-around;
margin-top: 20px;
}
.color-box {
width: 30%;
height: 30vh;
text-align: center;
}
.slider-container {
text-align: left;
width: 30%;
}
label {
margin: 4px;
padding: 5px;
border-radius: 4px;
background-color: #bbb !important;
font-weight: 600;
font-size: 1em;
min-width: 6em;
}
input {
width: 45%;
}
.explainText {
padding: 10px;
text-align: center;
font-size: 1rem;
}
.cyan {
color: cyan;
}
.magenta {
color: magenta;
}
.yellow {
color: yellow;
}
</style>
</head>
<body>
<div class="container">
<div id="colorMixing">
<h2 id="additiveMixHeading">Subtractive Color Mixing (CMY)</h2>
<div class="explainText">
Select two different colors using CMY sliders and see how they mix subtractively.
</div>
<div style="display: flex; justify-content: space-around; width: 100%;">
<div class="color-box">
<h3>Color 1</h3>
<div id="color1" style="width:100%;height:100%;"></div>
</div>
<div class="color-box">
<h3>Mixed Color</h3>
<div id="mixed-color" style="width:100%;height:100%;"></div>
</div>
<div class="color-box">
<h3>Color 2</h3>
<div id="color2" style="width:100%;height:100%;"></div>
</div>
</div>
<br><br>
<div style="display: flex; justify-content: space-around; width: 100%; margin-top: 10px;">
<div class="slider-container">
<label class="cyan">Cyan 1</label>
<input type="range" id="c1-slider" min="0" max="255" value="50" oninput="updateMixedColor()">
<label class="magenta">Magenta 1</label>
<input type="range" id="m1-slider" min="0" max="255" value="115" oninput="updateMixedColor()">
<label class="yellow">Yellow 1</label>
<input type="range" id="y1-slider" min="0" max="255" value="220" oninput="updateMixedColor()">
</div>
<div class="slider-container"></div>
<div class="slider-container">
<label class="cyan">Cyan 2</label>
<input type="range" id="c2-slider" min="0" max="255" value="220" oninput="updateMixedColor()">
<label class="magenta">Magenta 2</label>
<input type="range" id="m2-slider" min="0" max="255" value="160" oninput="updateMixedColor()">
<label class="yellow">Yellow 2</label>
<input type="range" id="y2-slider" min="0" max="255" value="70" oninput="updateMixedColor()">
</div>
</div>
</div>
</div>
<script>
function updateMixedColor() {
var c1 = parseInt(document.getElementById("c1-slider").value);
var m1 = parseInt(document.getElementById("m1-slider").value);
var y1 = parseInt(document.getElementById("y1-slider").value);
var c2 = parseInt(document.getElementById("c2-slider").value);
var m2 = parseInt(document.getElementById("m2-slider").value);
var y2 = parseInt(document.getElementById("y2-slider").value);
// Convert CMY to RGB for CSS display
var r1 = 255 - c1;
var g1 = 255 - m1;
var b1 = 255 - y1;
var r2 = 255 - c2;
var g2 = 255 - m2;
var b2 = 255 - y2;
// Calculate mixed RGB from inverse CMY values
var mixedR = Math.max(0, r1 * r2 / 255);
var mixedG = Math.max(0, g1 * g2 / 255);
var mixedB = Math.max(0, b1 * b2 / 255);
document.getElementById("color1").style.backgroundColor = `rgb(${r1},${g1},${b1})`;
document.getElementById("color2").style.backgroundColor = `rgb(${r2},${g2},${b2})`;
document.getElementById("mixed-color").style.backgroundColor = `rgb(${mixedR},${mixedG},${mixedB})`;
}
updateMixedColor(); // Initialize colors on page load
</script>
</body>
</html>