Hi @Katoch!
Looks like you’re having fun there!
It’s great that you’re already experimenting with your new JavaScript skills to build actual projects. That’s definitely a great way to learn!
As the programming courses in this academy are for future blockchain developers, we can’t really support posts about projects specific to other industries such as the one you are working on here, and so I would encourage you to ask for help and support in forums such as https://stackoverflow.com/ or a forum aimed at developers in the field of art and graphic design.
Having said that, the last thing we want to do is discourage you from developing your JavaScript skills, as the basic functionality can be used in programs for any industry, including blockchain development.
So, I have had a quick look and play with your program (I did actually get a bit distracted and started enjoying myself too much ). I think for the sort of thing you’re looking to introduce, you may want to see if generating random HSL colours for the different lines will give you what you want. I’ve come up with the following code which uses random number generation to output a different HSL colour every time it is run. What I haven’t been able to do is find where to put it in your code so that it affects different lines rather than the whole thing. At first I thought it may need to go in the inner for
loop, but that didn’t seem to work. As I have no knowledge of how the different context
methods work to draw the lines, and also no experience in this particular field, I’ll have to leave you with my contribution below and these thoughts to get you thinking further. Random number generation is something that is useful in any programming field and so it’s useful to learn about in greater depth anyway, even if you end up finding something else is more appropriate here.
let randomH = Math.floor(Math.random() * 361); //random number 0 - 360 (degrees)
let randomS = Math.floor(Math.random() * 101); //random number 0 - 100 (%)
let randomL = Math.floor(Math.random() * 101); //random number 0 - 100 (%)
context.strokeStyle = `hsl(${randomH}, ${randomS}%, ${randomL}%)`;
/* Here I've used a template literal which I think is much clearer than
string concatenation but you could use either */
// The following console.log() is just to check the HSL string(s) generated.
console.log(`hsl(${randomH}, ${randomS}%, ${randomL}%)`);
If you want to just run this code separately first, you’ll need to comment out the context.strokeStyle
variable, as it will throw an error unless it is used in the context of your program. Otherwise it runs successfully if you insert it into your program first.
If you want to learn more about the different ways to generate random numbers, or how template literals work, check out these links to MDN web docs :
Math.random
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
Template literals https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals