Chang Tsuiling
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- tags: HTML5 --- # <i class="fa fa-book"></i> TS Canvas Notes > [學習HTML5 Canvas參考文件](http://www.runoob.com/w3cnote/html5-canvas-intro.html) > ## <i class="fa fa-pencil-square"></i> canvas 簡介 > <canvas>是HTML5新增的標籤,呈現一個畫布,接著可以使用 JavaScript 在畫布中繪製圖像的HTML元素。它可以用來製作照片集或者製作簡單(也不是那麼簡單)的動畫,甚至可以進行實時視頻處理和渲染。 > ## <i class="fa fa-pencil-square"></i> Canvas 基本使用 ```htmlmixed= <canvas id="TScanvas" width="1500" height="500"> 寬度預設1500px, 高度預設500px 這裡打算呈現...圖像及...功能, 而您的瀏覽器不支持這個功能, 請升級您的瀏覽器, 或是下載使用 Chrome 瀏覽器。 </canvas> ``` ## <i class="fa fa-pencil-square"></i> 使用 JavaScript 控制 Canvas 畫布 <a href="http://tsweb44.com/TS_EX/canvas/test001.html"> <i class="fa fa-eye"></i> </a> ```javascript= //設定變數c代表畫布, 變數ctext記錄傳回畫布上繪圖的環境 var c = document.getElementById('TScanvas'); var ctext = c.getContext('2d'); //畫線==================== ctext.beginPath(); //建立一個path路徑線 ctext.moveTo( 50,50 ); //將畫筆移動到指定座標 ctext.lineTo( 300,100 ); //自目前座標位置繪製一條路徑線到指定的座標 ctext.stroke(); //送出繪製出路徑線 //畫三角型==================== ctext.moveTo( 50,200 ); //將畫筆移動到指定座標(x,y) ctext.lineTo( 300,250 ); //自目前座標位置繪製一條路徑線到指定的座標 ctext.lineTo( 300,200 ); //自目前座標位置繪製一條路徑線到指定的座標 ctext.closePath(); //結束關閉path ctext.fill(); //封閉的形狀填滿顏色, 預色為黑色 ctext.stroke(); //送出繪製出路徑線 //畫實心矩型==================== ctext.fillStyle = 'rgba(200, 0, 200, 0.5)'; //設定接下來繪製形狀填滿的顏色 ctext.fillRect( 400, 30, 200, 100 ); //繪出填滿顏色的矩形(x,y,width,height) ctext.clearRect( 450, 50, 50, 50 ); //清除矩形範圍 //畫空心矩型==================== ctext.strokeStyle = 'rgb(255, 0, 0)'; //設定接下來繪製畫筆的顏色 ctext.lineWidth = 5; //設定接下來繪製畫筆的寬度(粗細) ctext.strokeRect( 400, 200, 200, 100 ); //送出繪製出矩形邊框 //畫曲線==================== ctext.strokeStyle = 'rgb(120, 150, 255)'; //設定接下來繪製畫筆的顏色 ctext.lineWidth = 10; //設定接下來繪製畫筆的寬度(粗細) //畫圓==================== ctext.beginPath(); //建立一個path路徑線 ctext.arc(800,100,50,0,2*Math.PI); //透過arc()繪製曲線或圓形 //arc(圓心x,圓心y,半徑,起始角以弧度計,結束角以弧度計,true=逆時針/false=順時針) ctext.stroke(); //送出繪製出路徑線 //畫3/4弧線==================== ctext.beginPath(); //建立一個path路徑線 ctext.arc(1000,100,50,0,1.5*Math.PI); //x座標1000, y座標100, 半徑50, 弧度起始0, 弧度結束1.5PI表示3/4弧度 ctext.stroke(); //送出繪製出路徑線 //畫實心半圓==================== ctext.fillStyle = 'rgb(120, 150, 255)'; //設定接下來繪製形狀填滿的顏色 ctext.beginPath(); //建立一個path路徑線 ctext.arc(1200,100,50,0,Math.PI,false); //x座標1200, y座標100, 半徑50, 弧度起始0, 弧度結束1PI表示1/2弧度, 以順時針方向畫 ctext.fill(); //送出繪製出路徑線 //畫線(端點樣式的變化) ==================== var lineCaps = [ "butt", "round", "square" ]; for ( var i = 0; i < 3; i ++ ) { ctext.beginPath(); ctext.moveTo( 800 + 60 * i , 200 ); ctext.lineTo( 800 + 60 * i , 400 ); ctext.lineWidth = 20; ctext.lineCap = lineCaps [ i ]; //設定線條端點樣式, butt平端點, round圓端點, square方端點 ctext.stroke(); } //畫紅線方便觀察 ctext.beginPath(); ctext.moveTo( 750 , 200 ); ctext.lineTo( 1000 , 200 ); ctext.moveTo( 750 , 400 ); ctext.lineTo( 1000 , 400 ) ctext.strokeStyle = "red"; ctext.lineWidth = 1; ctext.stroke(); ``` ### [<i class="fa fa-bookmark"></i> 範例:刮刮卡](https://tsweb.com.tw/TS_EX/canvas/test002.html) > [參考文件:HTML5 <canvas> 参考手册 @runoob [簡中]](http://www.runoob.com/tags/ref-canvas.html) > [參考文件:HTML5 <canvas> 参考手册 @w3school [簡中]](http://www.w3school.com.cn/tags/html_ref_canvas.asp) > [參考文件:HTML5 <canvas> 参考手册 @w3schools [英文]](https://www.w3schools.com/tags/ref_canvas.asp) >

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully