Facebook Twitter Instagram
    DeepCrazyWorld
    Facebook Twitter Instagram Pinterest YouTube
    • FLUTTER
      • FLUTTER APP
        • QRCode
        • Quiz App
        • Chat GPT
        • PDF App
        • News App
        • Fitness App
        • Weather App
        • BMI Calculator
        • GAME APP
        • Ecommerce App
        • wallpaper App
        • Finance app
        • Chat App
        • Wallet App
        • Taxi App
        • Quran app
        • Music player app
      • FLUTTER UI
        • Splash Screen
        • Onboarding Screen
        • Login Screen
        • Card Design
        • Drawer
    • PROJECT
      • Android Projects
      • College Projects
      • FLUTTER APP
      • Project Ideas
      • PHP Projects
      • Python Projects
    • SOURCE CODE
    • ANDROID
      • ANDROID APP
      • GAME APP
      • ANDROID STUDIO
    • MCQ
      • AKTU MCQ
        • RPA MCQ
        • COA MCQ
        • HPC MCQ
        • SPM MCQ
        • Renewable Energy All MCQ
        • Data Compression MCQ
        • Data Structure MCQ
        • Digital Image Processing MCQ
        • Software Engineering MCQ
        • Machine Learning MCQ
        • Artificial Intelligence MCQ
      • D PHARMA MCQ
        • Pharmaceutics – I MCQ
        • Pharmacognosy MCQ
        • Pharmaceutical Chemistry MCQ
        • Biochemistry and Clinical Pathology MCQ
        • Human Anatomy and Physiology MCQ
        • Heath Education and Community Pharmacy MCQ
    • INTERVIEW QUESTIONS
      • Flutter Interview Questions
      • INTERVIEW QUESTIONS
      • Python Interview Questions
      • Coding ninjas solution
    • MORE
      • WORDPRESS
        • SEO
        • TOP 10 WORDPRESS THEME
      • PRODUCTIVITY
      • Program
      • QUOTES
    DeepCrazyWorld
    Home»ANDROID»Design Paint In html with CSS and JS – source code Free
    design paint in html
    ANDROID

    Design Paint In html with CSS and JS – source code Free

    DeepikaBy DeepikaFebruary 23, 2020Updated:April 17, 2023No Comments3 Mins Read

    How to make and design Paint In html with CSS and JS – source code Free, design paint project in css and java script file .

    <img decoding=

    Table of Contents

    Toggle
      • Attach CSS File in Html , For Attach CSS file in <head> tag
      • Add (JS) Java Script File in html , JS file attache in <body> tag
    • Design paint with Html JS & CSS
    • Index.Html
    • CSS File for Design paint
    • JS File For Design paint
    • YouTube Video
    • READ MORE.
        • Sharing is Caring…

    Attach CSS File in Html , For Attach CSS file in <head> tag

    <link rel=¨stylesheet¨ type=¨text/css¨ href=¨..\[folder_name]\[file_name].css¨>

    <link rel=¨stylesheet¨ type=¨text/css¨ href=¨[file_name].css¨>

    Add (JS) Java Script File in html , JS file attache in <body> tag

    <script src=”..\[folder_name]\[file_name].js”></script>

    <script src=”[file_name].js”></script>

    <script src=”[url_of_the_js_library]”></script>

    Design paint with Html JS & CSS

    Index.Html

    <html>
    <body>
    <div id=’colors’>
    <button id=’black’ onclick=’changeColor(“black”)’ ontouchstart=’changeColor(“black”)’></button>
    <button id=’red’

    onclick=’changeColor(“red”)’ ontouchstart=’changeColor(“red”)’></button>
    <button id=’green’ onclick=’changeColor(“green”)’ ontouchstart=’changeColor(“green”)’></button>
    <button id=’blue’ onclick=’changeColor(“blue”)’ ontouchstart=’changeColor(“blue”)’></button>
    <button id=’orange’ onclick=’changeColor(“orange”)’ ontouchstart=’changeColor(“orange”)’></button>
    <button id=’teal’ onclick=’changeColor(“teal”)’ ontouchstart=’changeColor(“teal”)’></button>
    <button id=’wheat’ onclick=’changeColor(“wheat”)’ ontouchstart=’changeColor(“wheat”)’></button

    <button id=’pink’ onclick=’changeColor(“pink”)’ ontouchstart=’changeColor(“pink”)’></button>
    <button id=’gold’ onclick=’changeColor(“gold”)’ ontouchstart=’changeColor(“gold”)’></button>
    <button id=’lime’ onclick=’changeColor(“lime”)’ ontouchstart=’changeColor(“lime”)’></button>
    <button id=’coral’ onclick=’changeColor(“coral”)’ ontouchstart=’changeColor(“coral”)’></button>
    <button id=’navy’ onclick=’changeColor(“navy”)’ ontouchstart=’changeColor(“navy”)’></button>
    <button id=’violet’ onclick=’changeColor(“violet”)’ ontouchstart=’changeColor(“violet”)’></button

    <button id=’aqua’ onclick=’changeColor(“aqua”)’ ontouchstart=’changeColor(“aqua”)’></button>
    <button id=’olive’ onclick=’changeColor(“olive”)’ ontouchstart=’changeColor(“olive”)’></button>

    </div>
    <canvas id=’canvas’ width=’300′ height=’200′></canvas>
    <div>
    <button onclick=’clearCanvas()’>Clear</button>
    </div>
    </body>
    </html>

    CSS File for Design paint

    <img loading=

    #canvas
    {
    border: 1px solid black;
    margin: 10px 0 10px 0;
    cursor: pointer;
    }
    #colors button
    {
    width: 40px;
    height: 40px;
    border-radius: 100%;
    margin-top: 0px;
    }
    #black
    {
    background: black;
    }
    #pink
    {
    background: pink;
    }

    #wheat
    {
    background: wheat;
    }

    #teal
    {
    background: teal;
    }

    #red
    {
    background: red;
    }
    #green
    {
    background: green;
    }
    #blue
    {
    background: blue;
    }
    #orange
    {
    background: orange;
    }

    #gold
    {
    background: gold;
    }

    #lime
    {
    background: lime;
    }

    #coral
    {
    background: coral;
    }
    #navy
    {
    background: navy;
    }
    #aqua
    {
    background: aqua;
    }

    #olive
    {
    background: olive;
    }
    #violet
    {
    background: violet;
    }

    JS File For Design paint

    var arr_touches = [];
    var canvas;
    var ctx;
    var down = false; //mouse is pressed
    var color = ‘black’; //default drawing color
    var width = 5; // drawing width

    //calling window.onload to make sure the HTML is loaded
    window.onload = function() {
    canvas = document.getElementById(‘canvas’);
    ctx = canvas.getContext(‘2d’);
    ctx.lineWidth = width;

    //handling mouse click and move events
    canvas.addEventListener(‘mousemove’, handleMove);
    canvas.addEventListener(‘mousedown’, handleDown);
    canvas.addEventListener(‘mouseup’, handleUp);

    //handling mobile touch events
    canvas.addEventListener(“touchstart”, handleStart, false);
    canvas.addEventListener(“touchend”, handleEnd, false);
    canvas.addEventListener(“touchcancel”, handleCancel, false);
    canvas.addEventListener(“touchleave”, handleEnd, false);
    canvas.addEventListener(“touchmove”, handleTouchMove, false);
    };
    function handleMove(e)
    {
    xPos = e.clientX-canvas.offsetLeft;
    yPos = e.clientY-canvas.offsetTop;
    if(down == true)
    {
    ctx.lineTo(xPos,yPos); //create a line from old point to new one
    ctx.strokeStyle = color;
    ctx.stroke();
    }
    }
    function handleDown()
    {
    down = true;
    ctx.beginPath();
    ctx.moveTo(xPos, yPos);
    }
    function handleUp()
    {
    down = false;
    }
    function handleStart(evt)
    {
    var touches = evt.changedTouches;
    for(var i = 0; i < touches.length; i++)
    {
    if(isValidTouch(touches[i]))
    {
    evt.preventDefault();
    arr_touches.push(copyTouch(touches[i]));
    ctx.beginPath();
    ctx.fillStyle = color;
    ctx.fill();
    }
    }
    }
    function handleTouchMove(evt)
    {
    var touches = evt.changedTouches;
    var offset = findPos(canvas);
    for (var i = 0; i < touches.length; i++)
    {
    if(isValidTouch(touches[i]))
    {
    evt.preventDefault();
    var idx = ongoingTouchIndexById(touches[i].identifier);
    if (idx >= 0)
    {
    ctx.beginPath();
    ctx.moveTo(arr_touches[idx].clientX-offset.x, arr_touches[idx].clientY-offset.y);
    ctx.lineTo(touches[i].clientX-offset.x, touches[i].clientY-offset.y);
    ctx.strokeStyle = color;
    ctx.stroke();

    arr_touches.splice(idx, 1, copyTouch(touches[i]));
    }
    }
    }
    }
    function handleEnd(evt)
    {
    var touches = evt.changedTouches;
    var offset = findPos(canvas);
    for (var i = 0; i < touches.length; i++)
    {
    if(isValidTouch(touches[i]))
    {
    evt.preventDefault();
    var idx = ongoingTouchIndexById(touches[i].identifier);
    if (idx >= 0)
    {
    ctx.lineWidth = 4;
    ctx.fillStyle = color;
    ctx.beginPath();
    ctx.moveTo(arr_touches[idx].clientX-offset.x, arr_touches[idx].clientY-offset.y);
    ctx.lineTo(touches[i].clientX-offset.x, touches[i].clientY-offset.y);
    arr_touches.splice(i, 1);
    }
    }
    }
    }
    function handleCancel(evt)
    {
    evt.preventDefault();
    var touches = evt.changedTouches;

    for (var i = 0; i < touches.length; i++) {
    arr_touches.splice(i, 1);
    }
    }
    function copyTouch(touch)
    {
    return {identifier: touch.identifier,clientX: touch.clientX,clientY: touch.clientY};
    }
    function ongoingTouchIndexById(idToFind)
    {
    for (var i = 0; i < arr_touches.length; i++) {
    var id = arr_touches[i].identifier;
    if (id == idToFind) {
    return i;
    }
    }
    return -1;
    }
    function changeColor(new_color)
    {
    color = new_color;
    }
    function clearCanvas()
    {
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    }
    function isValidTouch(touch)
    {
    var curleft = 0, curtop = 0;
    var offset = 0;

    if (canvas.offsetParent) {
    do {
    curleft += canvas.offsetLeft;
    curtop += canvas.offsetTop;
    } while (touch == canvas.offsetParent);

    offset = { x: curleft-document.body.scrollLeft, y: curtop-document.body.scrollTop };
    }

    if(touch.clientX-offset.x > 0 &&
    touch.clientX-offset.x < parseFloat(canvas.width) &&
    touch.clientY-offset.y >0 &&
    touch.clientY-offset.y < parseFloat(canvas.height)) {
    return true;
    }
    else
    {
    return false;
    }
    }
    function findPos(obj)
    {
    var curleft = 0, curtop = 0;
    if (obj.offsetParent)
    {
    do {
    curleft += obj.offsetLeft;
    curtop += obj.offsetTop;
    } while (obj == obj.offsetParent);

    return { x: curleft-document.body.scrollLeft, y: curtop-document.body.scrollTop };
    }
    }

    YouTube Video

    READ MORE.

    Sharing is Caring…

    Share. Facebook Twitter LinkedIn WhatsApp Telegram Pinterest Reddit Email
    Previous ArticleInterview Questions and Answers – Interview Tips & Tricks
    Next Article Factorial Number with Html CSS and JS – HTML Project

    Related Posts

    How to Make Car Racing Game App with Android Studio

    ANDROID 2 Mins Read

    Google play console All basic details Step by step 2023

    Android App Development 9 Mins Read

    How to Update Rejected app from Google play console 2023

    Android App Development 4 Mins Read

    How to Market Your Mobile App On a Budget 2023

    Android App Development 8 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • Implementing a Dynamic FAQ Screen UI in Flutter Using ExpansionTile March 29, 2025
    • Creating an Instruction UI Screen in Flutter Application March 29, 2025
    • Animated Backgrounds in Flutter: A Complete Guide March 15, 2025
    • How to make Diary App using flutter stepwise using getx August 31, 2024
    • How to Create Music Player UI screen with fully functional in flutter August 30, 2024
    • How to make ListView Builder Ui in flutter with Source Code August 29, 2024
    • Create a TabBar View in flutter with fully functional stepwise August 28, 2024
    • How to create TabBar view in flutter with source code step wise August 27, 2024
    • How to make Heart rate measure app with Flutter stepwise August 26, 2024
    • How to make ChatGpt App in flutter with source code Stepwise August 25, 2024
    Facebook Twitter Instagram Pinterest YouTube
    • About
    • Contact
    • Disclaimer
    • Privacy Policy
    Copyright by DeepCrazyWorld © 2025

    Type above and press Enter to search. Press Esc to cancel.