Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <canvas id="myCanvas"></canvas>
            
          
!

CSS

            
              
            
          
!

JS

            
              let canvas = document.getElementById("myCanvas");
let ctx = canvas.getContext("2d");


let mouse = {
    x : 0,
    y : 0,
}

window.addEventListener('mousemove',(event) => {
  mouse.x = event.pageX;
  mouse.y = event.pageY;
})

//一個繪製的function
const draw = () =>{
    //把視窗大小重新設定給canvas
    canvas.height = window.innerHeight;
    canvas.width = window.innerWidth;
    
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    
    //設定背景顏色
    let green = 180-(mouse.y*(180/window.innerHeight));
    let blue = 255-(mouse.y*(180/window.innerHeight));
    ctx.fillStyle = `rgb(0, ${green}, ${blue})`;
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    
    //之後繪製太陽
    ctx.beginPath();
    ctx.arc(mouse.x,mouse.y,30,0,Math.PI*2);
    ctx.strokeStyle="#FF5511";
    ctx.stroke();
    ctx.fillStyle="#FFFF00";
    ctx.fill();
    
    //繪製光芒線條
    lightLine();
}

//繪製光芒線條的function
const lightLine = () =>{
    //設定線條顏色
    ctx.strokeStyle="#FF5511";
    
    //分別是起始點和終點需要增加的距離
    let moveLength = 40
    let lineLength = 60
    
    //第一次迴圈加上距離,第二次減掉距離
    for(let i=-1;i<=1;i+=2){
        //橫線
        ctx.beginPath();
        ctx.moveTo(mouse.x+(moveLength*i),mouse.y);
        ctx.lineTo(mouse.x+(lineLength*i),mouse.y);
        ctx.stroke();
        //縱線
        ctx.beginPath();
        ctx.moveTo(mouse.x,mouse.y+(moveLength*i));
        ctx.lineTo(mouse.x,mouse.y+(lineLength*i));
        ctx.stroke();
    }
    
    //下右斜線
    ctx.beginPath();
    ctx.moveTo(mouse.x+30,mouse.y+30);
    ctx.lineTo(mouse.x+(30+15),mouse.y+(30+15));
    ctx.stroke();
    
    //下左斜線
    ctx.beginPath();
    ctx.moveTo(mouse.x-30,mouse.y+30);
    ctx.lineTo(mouse.x-(30+15),mouse.y+(30+15));
    ctx.stroke();
    
    //上右斜線
    ctx.beginPath();
    ctx.moveTo(mouse.x+30,mouse.y-30);
    ctx.lineTo(mouse.x+(30+15),mouse.y-(30+15));
    ctx.stroke();
    
    //上左斜線
    ctx.beginPath();
    ctx.moveTo(mouse.x-30,mouse.y-30);
    ctx.lineTo(mouse.x-(30+15),mouse.y-(30+15));
    ctx.stroke();
}

setInterval('draw()',50)
            
          
!
999px

Console