Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTML color picker, update p5.js #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h2>Drawing Tools</h2>
<option value="3">Plane</option>
</select>
<input id="b1-slider" tabindex="-1" type="range" min="1" max="100" value="10">
<input onclick="openColorSelector(1)" tabindex="-1" id="b1-color" type="button" value="" class="colorButton">
<input tabindex="-1" id="b1-color" type="color" value="" class="colorButton" onchange="marker1Color = this.value;">
</div>
<div id="brush-2" class="brush">
<input id="b2-select" tabindex="-1" type="checkbox" checked>
Expand All @@ -53,7 +53,7 @@ <h2>Drawing Tools</h2>
<option value="3">Plane</option>
</select>
<input id="b2-slider" tabindex="-1" type="range" min="1" max="100" value="20">
<input onclick="openColorSelector(2)" tabindex="-1" id="b2-color" type="button" value="" class="colorButton">
<input tabindex="-1" id="b2-color" type="color" value="" class="colorButton" onchange="marker2Color = this.value;">
</div>
<div id="brush-3" class="brush">
<input id="b3-select" tabindex="-1" type="checkbox" checked>
Expand All @@ -63,7 +63,7 @@ <h2>Drawing Tools</h2>
<option value="3">Plane</option>
</select>
<input id="b3-slider" tabindex="-1" type="range" min="1" max="100" value="30">
<input onclick="openColorSelector(3)" tabindex="-1" id="b3-color" type="button" value="" class="colorButton">
<input tabindex="-1" id="b3-color" type="color" value="" class="colorButton" onchange="marker3Color = this.value;">
</div>
<div id="brush-4" class="brush">
<input id="b4-select" tabindex="-1" type="checkbox" checked>
Expand All @@ -73,7 +73,7 @@ <h2>Drawing Tools</h2>
<option value="3">Plane</option>
</select>
<input id="b4-slider" tabindex="-1" type="range" min="1" max="100" value="40">
<input onclick="openColorSelector(4)" tabindex="-1" id="b4-color" type="button" value="" class="colorButton">
<input tabindex="-1" id="b4-color" type="color" value="" class="colorButton" onchange="marker4Color = this.value;">
</div>
<div id="brush-5" class="brush">
<input id="b5-select" tabindex="-1" type="checkbox" checked>
Expand All @@ -83,7 +83,7 @@ <h2>Drawing Tools</h2>
<option value="3">Plane</option>
</select>
<input id="b5-slider" tabindex="-1" type="range" min="1" max="100" value="50">
<input onclick="openColorSelector(5)" tabindex="-1" id="b5-color" type="button" value="" class="colorButton">
<input tabindex="-1" id="b5-color" type="color" value="" class="colorButton" onchange="marker5Color = this.value;">
</div>
</div>
<div id="tool-modifiers">
Expand Down Expand Up @@ -112,7 +112,7 @@ <h2>Options</h2>
<div id="background-buttons" class="setting">
<input id="background-check" tabindex="-1" onclick="backgroundToggle()" checked type="checkbox">
<label for="background-check" id="background-label" class="setting-label">Background</label>
<input onclick="openColorSelector(0)" tabindex="-1" id="background-color-button" type="button" value="" class="colorButton">
<input tabindex="-1" id="background-color-button" type="color" value="" class="colorButton" onchange="backgroundColor = this.value;">
</div>
<br />
<div id="speed-slider" class="setting">
Expand Down Expand Up @@ -194,10 +194,6 @@ <h2>Export</h2>
</div>
</div>
</footer>
<div id="color-selector">
<div id="colors">
</div>
</div>
</div>
<script src="vendor/p5.min.js"></script>
<script src="vendor/gif.js"></script>
Expand Down
13 changes: 6 additions & 7 deletions src/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const sketchContainer = document.querySelector('#sketch-container');
const animationDummy = document.querySelector('#animation-dummy');
const speedSlider = document.querySelector('#speed');

const colorSelector = document.querySelector('#color-selector');
const backgroundColorSelector = document.querySelector('#background-color-selector');
const backgroundColorButton = document.querySelector('#background-color-button');

Expand Down Expand Up @@ -151,14 +150,14 @@ const animationSketch = new p5(function (sketch) {
marker4Color = web216[sketch.int(sketch.random(web216.length))];
marker5Color = web216[sketch.int(sketch.random(web216.length))];

marker1ColorButton.style.backgroundColor = marker1Color;
marker2ColorButton.style.backgroundColor = marker2Color;
marker3ColorButton.style.backgroundColor = marker3Color;
marker4ColorButton.style.backgroundColor = marker4Color;
marker5ColorButton.style.backgroundColor = marker5Color;
marker1ColorButton.value = marker1Color;
marker2ColorButton.value = marker2Color;
marker3ColorButton.value = marker3Color;
marker4ColorButton.value = marker4Color;
marker5ColorButton.value = marker5Color;

backgroundColor = web216[sketch.int(sketch.random(web216.length))]; //"#000000"; //
backgroundColorButton.style.backgroundColor = backgroundColor;
backgroundColorButton.value = backgroundColor;

sketch.pixelDensity(1);

Expand Down
35 changes: 29 additions & 6 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,37 @@ hr {
}

.colorButton {
width: 24px;
border-radius: 50%;
height: 24px;
color: white;
padding: 2px 2px 2px 2px;
width: 24px;
border: none;
outline: 1px solid #FFFFFF;
padding: 0px;
display: inline-block;
border-radius: 50%;
border: 1px solid #FFFFFF;
-webkit-appearance: none;
-moz-appearance: none;
cursor: pointer;
border-radius: 50&;
-o-border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
-moz-outline-radius: 50%;
}

.colorButton::-webkit-color-swatch-wrapper {
padding: 0;
border: none;
border-radius: 50%;
}

.colorButton::-webkit-color-swatch {
border: none;
border-radius: 50%;
}

.colorButton::-moz-color-swatch {
border: none;
border-radius: 50%;
}

.play {
Expand Down Expand Up @@ -330,7 +353,7 @@ select option {
line-height: 32px; /*40*/
padding-left: 6px;
padding-right: 11px;
padding-bottom: 2px;
padding-bottom: 4px;
}

.brush input, .brush select, .setting input, .setting .setting-label, .setting label {
Expand Down
45 changes: 0 additions & 45 deletions src/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,6 @@ function backgroundToggle() {
displayFrame(animationSketch);
}

function openColorSelector (n) {
document.body.classList.add('noscroll');
colorSelector.classList.add('active');
currentColorSelection = n;
}

function closeColorSelector (e) {
currentColor = e.target.dataset.color

if (currentColorSelection === 0) {
backgroundColor = currentColor;
displayFrame(animationSketch);
backgroundColorButton.style.backgroundColor = currentColor;
} else if (currentColorSelection === 1) {
marker1Color = currentColor;
marker1ColorButton.style.backgroundColor = marker1Color;
} else if (currentColorSelection === 2) {
marker2Color = currentColor;
marker2ColorButton.style.backgroundColor = marker2Color;
} else if (currentColorSelection === 3) {
marker3Color = currentColor;
marker3ColorButton.style.backgroundColor = marker3Color;
} else if (currentColorSelection === 4) {
marker4Color = currentColor;
marker4ColorButton.style.backgroundColor = marker4Color;
} else if (currentColorSelection === 5) {
marker5Color = currentColor;
marker5ColorButton.style.backgroundColor = marker5Color;
}
colorSelector.classList.remove('active');
document.body.classList.remove('noscroll');
}

function clickPlay() {
pause = !pause;
if (pause) {
Expand Down Expand Up @@ -335,18 +302,6 @@ const web216 = [
'#FFFFCC'
];

// Populate color picker with buttons.

const colors = document.querySelector('#colors');

web216.forEach((c) => {
let btn = document.createElement('button');
btn.onclick = closeColorSelector;
btn.dataset.color = c;
btn.style.backgroundColor = c;
colors.append(btn)
});

// Resolution links

document.querySelectorAll('a.res').forEach((el) => {
Expand Down
Loading