javascript - I used a for loop to draw different curves. But how can I change every line to a different color? -
in draw function draw everything. draw white rect because can change position of every curve , otherwise see of them. not 1 new position.
function draw() { var canvaswidth = canvas.width; var canvasheight = canvas.height; ctx.fillstyle = "white"; ctx.fillrect(0, 0, canvaswidth, canvasheight); (var = 0; <= line.length; i++) { // directly under line of text stands color // curves , needs corrected guess. ctx.strokestyle = "rgb(200,200,200)"; ctx.beginpath(); ctx.moveto(500, 150); ctx.beziercurveto(line[i], 300, line[i], 300, line[i], 400 + (i * 15)); ctx.stroke(); ctx.closepath(); console.log[i]; } } the function below gets values of out html can draw correct curves
function create(){ console.log("change line"); var form = document.getelementbyid("frm1"); for(var = 0; < form.length; i++){ line[i] = form[i].value; } console.log(line); draw(); }
you can use function this:
function getrandomint(min, max) { return math.floor(math.random() * (max - min + 1)) + min; } to retrieve random number between 0 , 255 each value of r,g , b (red green , blue). i'd write code as
red = getrandomint(0,255); green = getrandomint(0,255); blue = getrandomint(0,255); ctx.strokestyle = "rgb("+red+","+green+","+blue+")"; hope helps!
Comments
Post a Comment