LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Saturday, January 26, 2019

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

スプレッドシートA列にある複数のテキストをスライドに追加したい(Google Apps Script)

今回Google Apps Scriptでやりたいこと GoogleスプレッドシートA列にある複数の値を取得して Googleスライドに渡して 図形オブジェクトのテキストとして追加したい ① スプレッドシートのA列に値を入れておく ② Code.gsのinsertNewShape...