結構複雑な絵をPowerPointで描いていて、コードで書けたら楽だなと思って試してみました。

楕円オブジェクトでサインカーブ

https://www.youtube.com/watch?v=wQZKjgiVYBI

<?php
$scalex = 1.0;
$scaley = 1.0;
$freq = 3;
$N = 100;

$deltax = $freq / $N;
$shape_type = 9;

$pp = new COM('PowerPoint.Application');
$pp->Visible = true;
$slides = $pp->Presentations->add;
$width = $slides->pageSetup->slideWidth;
$height = $slides->pageSetup->slideHeight;

$slide = $slides->Slides->Add(1, 11);

for($i = 0; $i <= $N; $i++){
  $y = sin(2 * pi() * $i * $deltax);
  $x = $i * $width / 100;
  $y = $y * $height / 2 + $height / 2;
  $x = $x * $scalex;
  $y = $y * $scaley;
  $shape = $slide->Shapes->AddShape($shape_type, $x, $y, 10, 10);
  $shape->Fill->ForeColor->RGB = 0x0000FF;
  $shape->Line->ForeColor->RGB = 0x0000FF;
}
?>

フリーフォームでサインカーブ

https://www.youtube.com/watch?v=lCL7lktVaYM

<?php

$scalex = 1.0;
$scaley = 1.0;

$shape_type = 9;

$pp = new COM('PowerPoint.Application');
$pp->Visible = true;
$slides = $pp->Presentations->add;
$width = $slides->pageSetup->slideWidth;
$height = $slides->pageSetup->slideHeight;
$ppc = $width / 25.4;

$slide = $slides->Slides->Add(1, 11);

$startx = 1;
$starty = $height / 2;
$freq = 3;
$deltax = $freq / 100;


$x = $startx;
$y = $height / 2;
$x = $x * $scalex;
$y = $y * $scaley;

$shape = $slide->Shapes->BuildFreeForm(0, $x, $y);

for($i = 1; $i <= 100; $i++){
  $y = sin(2 * pi() * $i * $deltax);
  echo($y . "\n");
  $x = $startx + $i * $width / 100;
  $y = $y * $height / 2 + $height / 2;
  $x = $x * $scalex;
  $y = $y * $scaley;
//  $slide->Shapes->ForeColor->RGB = 0xFF0000;
  $shape->AddNodes(1, 0, $x, $y);
}
$shape->ConvertToShape()

?>

  添付編集
Last-modified: 2017-10-03 (火) 19:31:35 (352d)