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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML

              
                <html>
<head>
  <title>お絵かきツール</title>
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<meta charset="UTF-8">
</head><body onload="sizing();changeColor(); changeWidth();">
<div id="wrapper">
<canvas id ="main" 
onMouseDown="startDraw(event)" onMouseMove="draw(event)"
onMouseUp="endDraw(event)"
></canvas>


<div id="haiti">
<div class="pallet">

基本色:
<button type="button"class="red"
onclick="setColor(255,0,0)"></button>
<button type="button"class="yellow"
onclick="setColor(255,255,0)"></button>
<button type="button"class="green"
onclick="setColor(0,255,0)"></button>
<button type="button"class="cyan"
onclick="setColor(0,255,255)"></button>
<button type="button"class="blue"
onclick="setColor(255,0,255)"></button>
<button type="button"class="white"
onclick="setColor(255,255,255)"></button>
<button type="button"class="black"
onclick="setColor(0,0,0)"></button>


</div>
<div class="pallet">
<canvas id="canvasWidth" width="20" height="20"></canvas>
ペンの太さ:
<input type="range" id="penW" value="10" min="1"
max="20" onInput="changeWidth()" />
</div>
<div id="buttons">

<input type="button" value="らくがきを消す"
onClick="clearCanvas()" />

<input type="button" value="表示/非表示" onClick="hyouji()" />
</div>
</div>
</div>
</body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                // JavaScript Document<script>
//マウスボタンが押されているかどうかを調べる変数を宣言
var mouseDown= false;

//ペンの設定
var penX=0;
var penY=0;
var penColor="rgba(0,0,0,1)";
var penWidth=10;

//描画の開始
function startDraw(event){
	
	//マウスが押された
	mouseDown=true;
	
	//ペンの座標をセット
	penX=event.clientX;
	penY=event.clientY;
	
	
	}
//描画
function draw(event){
	
/*マウスボタンが押されていれば描画*/	
if(mouseDown){
	//キャンパスの取得
	var canvas =document.getElementById("main");
	
	//コンテキストの取得 
	var context = canvas.getContext("2d");
		
	//ペンのセット	
	context.strokeStyle=penColor;
	context.lineWidth=penWidth;
	context.lineCap="round";
	
	//マウスカーソルの座標を取得
	var x=event.clientX
	var y=event.clientY
	
	//パスの開始
	context.beginPath();
	//座標の移動
	context.moveTo(penX,penY);
	//線の描画
	context.lineTo(x,y);
	//パスの描画
	context.stroke();
	
	//ペン座標の切り替え
	penX=x;
	penY=y;
	
		}
	}
//描画の終了
function endDraw(event){
	//マウスボタンが離された
	mouseDown=false;
	
}
function changeColor(){
	//スライダーの値を取得
	var penR=document.getElementById("penR").value;
	var penG=document.getElementById("penG").value;
	var penB=document.getElementById("penB").value;
	var penA=document.getElementById("penA").value;
	
	//ペンの色をセット
	penColor="rgba("+penR+","+penG+","+penB+","+penA+")";
	//ペン色用のキャンパスの取得
	var canvasColor=document.getElementById("canvasColor");
	//コンテキストの取得
	var contextColor=canvasColor.getContext("2d");
	
	//ペンの色を塗りつぶしの四角形で表示
	contextColor.clearRect(0,0,20,20);
	contextColor.fillStyle=penColor;
	contextColor.fillRect(0,0,20,20);
	
	//ペンの色をテキストで表示
	var textColor=document.getElementById("textColor");
	textColor.innerHTML=
	"R:"+penR+",G:"+penG+",B:"+penB+",A:"+penA;
	}
	function setColor(r,g,b){
		//スライダーに値をセット
		document.getElementById("penR").value=r;
		document.getElementById("penG").value=g;
		document.getElementById("penB").value=b;
		//ペンの色を変更
		changeColor();
		}

function changeWidth(){
		//スライダーの値を取得
		penWidth=document.getElementById("penW")
.value;	

		//ペンの太さ用キャンパスの取得
			var canvasWidth=document.getElementById("canvasWidth");
		//コンテキストの取得
		var contextWidth=canvasWidth.getContext("2d");
		//ペンの太さを塗りつぶしの円で表示
		contextWidth.clearRect(0,0,20,20);
		contextWidth.beginPath();
		contextWidth.arc(10,10,penWidth/2,0,2*Math.PI,false);
		contextWidth.fill();
}


//キャンパスをクリア
function clearCanvas(){
	//キャンパスの取得
	var canvas=document.getElementById("main");
	//コンテキストの取得
	var context =canvas.getContext("2d");
	//キャンバスをクリア
	context.clearRect(0,0, canvas.width,canvas.height);
	
}
//らくがきを別ウィンドウで表示


//パレットの表示/非表示
function hyouji(){
	 
var a = $(".pallet").css("display"); 

if ( a == "block"){ 
	
	document.getElementsByClassName("pallet").item(0).style.display="none";
	document.getElementsByClassName("pallet").item(1).style.display="none";
}else{ 

document.getElementsByClassName("pallet").item(0).style.display="block"; 
document.getElementsByClassName("pallet").item(1).style.display="block";	 
}}
$(function () {
	sizing();
	$(window).resize(function() {
		sizing();
	});
});

function sizing(){
	$("#main").attr({height:$("#wrapper").height()});
	$("#main").attr({width:$("#wrapper").width()});
}
              
            
!
999px

Console