SVG <楕円>


SVG楕円-<楕円>

<ellipse>要素は、楕円を作成するために使用されます。

楕円は円と密接に関連しています。違いは、楕円のx半径とay半径が互いに異なるのに対し、円のx半径とy半径は等しいことです。


例1

次の例では、楕円を作成します。

Sorry, your browser does not support inline SVG.

SVGコードは次のとおりです。

<svg height="140" width="500">
  <ellipse cx="200" cy="80" rx="100" ry="50"
  style="fill:yellow;stroke:purple;stroke-width:2" />
</svg>

コードの説明:

  • cx属性は、楕円の中心のx座標を定義します
  • cy属性は、楕円の中心のy座標を定義します
  • rx属性は、水平半径を定義します
  • ry属性は、垂直半径を定義します


例2

次の例では、3つの楕円を重ねて作成します。

Sorry, your browser does not support inline SVG.

SVGコードは次のとおりです。

<svg height="150" width="500">
  <ellipse cx="240" cy="100" rx="220" ry="30" style="fill:purple" />
  <ellipse cx="220" cy="70" rx="190" ry="20" style="fill:lime" />
  <ellipse cx="210" cy="45" rx="170" ry="15" style="fill:yellow" />
</svg>

例3

次の例では、2つの楕円(1つは黄色、もう1つは白)を組み合わせています。

Sorry, your browser does not support inline SVG.

SVGコードは次のとおりです。

<svg height="100" width="500">
  <ellipse cx="240" cy="50" rx="220" ry="30" style="fill:yellow" />
  <ellipse cx="220" cy="50" rx="190" ry="20" style="fill:white" />
</svg>