I have a task to develop for college but I have some problems.
First let me try to explain what to do:
I need to simulate a strobe light based on some colors in an HTML selector. The user must choose the range (I have not done the range yet, I do not know how it is). Then the user needs to choose which color he wants to be part of Strobe. When you click on Add Color this chosen color should be listed below the "Color Order". When you click on Dance Party the chosen colors should begin to flash on the canvas according to the chosen range.
So far I've been able to develop this:
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Strobe Light</title>
<script src="a6.js" type="text/javascript" defer></script>
</head>
<body onload="setUp()">
<h1>Strobe Light</h1>
<p>How fast should it flash? Enter a number between 1-15000 ms <input type="text" name="" id="strobeSpeed" value=""></p>
<p>What colours should flash?
<select id="colorSelector">
<option value="white">White</option>
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
<option value="pink">Pink</option>
<option value="purple">Purple</option>
<option value="black">Black</option>
<option value="orange">Orange</option>
</select>
<button type="button" id="addColour" name="button">Add Colour</button>
<button type="button" id="clearColour" name="button">Clear Colour</button>
</p>
<p>Colour Order</p>
<ul id="colourOrder"></ul>
<button type="button" id="danceParty" name="button">Dance Party!!!!!</button>
<br>
<br>
<canvas id="myCanvas" height="300" width="300" style="border: 1px solid black"></canvas>
</body>
</html>
JS:
let canvas;
let ctx;
function setUp(){
canvas = document.getElementById("myCanvas");
ctx = canvas.getContext("2d");
let showColour = document.getElementById("colourOrder");
document.getElementById('addColour').onclick = function(){
ctx.fillStyle = document.getElementById('colorSelector').value;
ctx.fillRect(0, 0, canvas.width, canvas.height);
};
document.getElementById('clearColour').onclick = function(){
ctx.fillStyle = "white";
ctx.fillRect(0, 0, canvas.width, canvas.height);
};
document.getElementById('danceParty').onclick = function(){
};
}