Apps Scriptリファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary

2019年1月26日土曜日

canvasに直線を描く


こういう青い直線を描くコード




コード.gs
function doGet() {
  return HtmlService.createHtmlOutputFromFile("index");
}
意訳
この機能がやること
指定したHTMLファイルを表示する




index.html
<!DOCTYPE html>
<html>
  <style>
  #canvas1 {
    width: 30vw;
    height: 30vh;
    border: solid 1px lightgray;
  }
</style>
  <body>
    <canvas id="canvas1"></canvas>
    <script>

var color = "royalblue";
var width = 10;

var canvas = document.getElementById('canvas1');
var context = canvas.getContext('2d');
var canvasWidth = canvas.width;
var canvasHeight = canvas.height;

context.strokeStyle = color;
context.lineWidth = width;

function draw() {
  var TopX = 0;
  var TopY = 0;
  var BottomX = 0;
  var height = canvasHeight;
  context.beginPath();
  context.moveTo(TopX, TopY);//線の出発点(X座標の出発点とY座標の出発点)
  context.lineTo(BottomX, height);//線の終点(X座標の終点, Y座標の終点)
  context.closePath();
  context.stroke();
};

draw();

</script>
  </body>
</html>


Latest post

Google Formsで記述式の質問に字数制限を設定したい

記述式の質問には「回答の検証」を設定することができます フォームの編集画面 右下の︙メニューで「回答の検証」を選択します 検証方法には「数値」「テキスト」「長さ」「正規表現」という種類があります 今回は字数制限したいので「長さ」を選びます 長さには「最大文字数」か「最小文字数」を...