SVG <elips>


SVG Ellipse - <elips>

Elemen <ellipse> digunakan untuk membuat elips.

Elips erat kaitannya dengan lingkaran. Perbedaannya adalah bahwa elips memiliki jari-jari x dan ay yang berbeda satu sama lain, sedangkan lingkaran memiliki jari-jari x dan y yang sama:


Contoh 1

Contoh berikut membuat elips:

Sorry, your browser does not support inline SVG.

Berikut adalah kode SVG:

Contoh

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

Penjelasan kode:

  • Atribut cx mendefinisikan koordinat x dari pusat elips
  • Atribut cy mendefinisikan koordinat y dari pusat elips
  • Atribut rx mendefinisikan radius horizontal
  • Atribut ry mendefinisikan radius vertikal


Contoh 2

Contoh berikut membuat tiga elips di atas satu sama lain:

Sorry, your browser does not support inline SVG.

Berikut adalah kode SVG:

Contoh

<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>

Contoh 3

Contoh berikut menggabungkan dua elips (satu kuning dan satu putih):

Sorry, your browser does not support inline SVG.

Berikut adalah kode SVG:

Contoh

<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>