xxxxxxxxxx
27
// MultiTouch (c) 2021 kouichi.matsuda@gmail.com
let lx = 0, ly = 0, w = 0, h = 0; // 左上、幅、高さ
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
background(220);
rect(lx, ly, w, h); // 四角形の描画
}
function touchMoved() {
let x1 = touches[0].x; // 1つ目の指の座標
let y1 = touches[0].y;
let x2 = touches[1].x; // 2つ目の指の座標
let y2 = touches[1].y;
// 四角形を描画するための前処理
if (x1 < x2) { lx = x1; } // 左上のx座標
else { lx = x2; }
if (y1 < y2) { ly = y1; } // 左上のy座標
else { ly = y2; }
w = abs(x1 - x2); // 幅
h = abs(y1 - y2); // 高さ
return false;
}