Skip to content

Instantly share code, notes, and snippets.

@swfz
Last active January 27, 2024 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swfz/8e5069ddcb400192b3d24b9e28fcea4e to your computer and use it in GitHub Desktop.
Save swfz/8e5069ddcb400192b3d24b9e28fcea4e to your computer and use it in GitHub Desktop.
GoogleSlideで漫画風強調表示をサクッと作るためのGASコード
function onInstall(e) {
onOpen();
}
function onOpen(e) {
SlidesApp.getUi().createAddonMenu()
.addItem('Cartoonish Emphasis', 'createCircularLayout')
.addToUi();
}
function getTargetPageNumber(title) {
const ui = SlidesApp.getUi()
const res = ui.prompt(title,"Please Input Target Page Number?", ui.ButtonSet.OK_CANCEL)
if (res.getSelectedButton() === ui.Button.OK){
return parseInt(res.getResponseText())
}
else {
Logger.log('Failed.')
}
}
function createCircularLayout() {
const presentation = SlidesApp.getActivePresentation();
const slides = presentation.getSlides()
const slide = slides[getTargetPageNumber('Cartoonish Emphasis') - 1]
// 円の中心点と半径を定義
const centerX = presentation.getPageWidth() / 2;
const centerY = presentation.getPageHeight() / 2;
const radius = 220;
// 配置する図形の数を定義
const numberOfShapes = 16;
// 三角形のサイズ、底辺、高さ、確度
const triangles = [
{x: 2, y: 230, step: 0},
{x: 4, y: 260, step: 5},
{x: 10, y: 220, step: 13},
{x: 7, y: 250, step: 20},
];
// 各図形の間の角度を計算
const angleStep = 360 / numberOfShapes;
for (let i = 0; i < triangles.length; i++) {
// 各図形の位置を計算して配置
for (let j = 0; j < numberOfShapes; j++) {
const angle = angleStep * j + triangles[i].step;
// 極座標を直交座標に変換
const x = centerX - (triangles[i].x/2) + radius * Math.cos(angle * Math.PI / 180);
const y = centerY - (triangles[i].y/2) + radius * Math.sin(angle * Math.PI / 180);
// 三角形の作成と配置
const triangle = slide.insertShape(SlidesApp.ShapeType.TRIANGLE, x, y, triangles[i].x, triangles[i].y);
// 図形の回転(必要に応じて)
triangle.setRotation(angle - 90);
// 三角形の塗りつぶし色を黒に設定
triangle.getFill().setSolidFill('#000000');
// 三角形の線の色を黒に設定
triangle.getBorder().getLineFill().setSolidFill('#000000');
// 円の周りに図形を配置してから傾きによって長さを変えることで画面の幅をカバーしている
const rotation = triangle.getRotation();
const rate = rotation < 30 || rotation >= 330 ? 0.6
: rotation >= 150 && rotation < 210 ? 0.6
: rotation >= 30 && rotation < 40 ? 0.7
: rotation >= 40 && rotation < 50 ? 0.9
: rotation >= 50 && rotation < 80 ? 1.3
: rotation >= 80 && rotation < 110 ? 1.2
: rotation >= 110 && rotation < 130 ? 1.3
: rotation >= 130 && rotation < 140 ? 0.9
: rotation >= 140 && rotation < 150 ? 0.7
: rotation >= 210 && rotation < 220 ? 0.7
: rotation >= 220 && rotation < 230 ? 0.9
: rotation >= 230 && rotation < 260 ? 1.3
: rotation >= 260 && rotation < 280 ? 1.2
: rotation >= 280 && rotation < 310 ? 1.3
: rotation >= 310 && rotation < 320 ? 0.9
: rotation >= 320 && rotation < 330 ? 0.7
: 1
triangle.setHeight(triangles[i].y * rate);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment