Canvas program related

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sharankongetira
    New Member
    • Feb 2022
    • 2

    Canvas program related

    Code:
    canvas =document.getElementById("canvas");
    ctx = canvas.getContext("2d")
    ctx.lineWidth = 6;
    ctx.strokeStyle = "#333";(here)
    ctx.beginPath();
    ctx.moveTo(100, 250);
    ctx.bezierCurveTo(150, 100, 350, 100, 400, 250);
    ctx.stroke()
    In this above program I need to use color input for the stroke style, that is, if user changes the color in
    web page, the curve with selected color should be drawn..can anyone help.
    Last edited by gits; Feb 15 '22, 01:05 PM. Reason: added code tags
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 655

    #2
    Code:
    canvas =document.getElementById("canvas");
    ctx = canvas.getContext("2d")
    ctx.lineWidth = 6;
    ctx.strokeStyle = "#333";(here)
    ctx.beginPath();
    ctx.moveTo(100, 250);
    ctx.bezierCurveTo(150, 100, 350, 100, 400, 250);
    ctx.stroke()
    In this above program I need to use color input for the stroke style, that is, if user changes the color in
    web page, the curve with selected color should be drawn..can anyone help.
    HTML
    Code:
    <input type="color" onchange="changeColor(this)">
    JS
    Code:
    function changeColor(obj) {
    	ctx.strokeStyle = obj.value;
        ctx.stroke();  
    }

    Comment

    Working...