#!/usr/local/bin/ruby
#
#
# ./Arcs.rb

require "ClibPDF"

radius= 2.2
rbump = 0.1
xorig = 2.5
yorig = 2.5
greenblue = 1.0


pdf = ClibPDF::PDF.open(0)
pdf.enableCompression(ClibPDF::YES)
pdf.init
pdf.pageInit(1, ClibPDF::PORTRAIT, ClibPDF::LETTER, ClibPDF::LETTER)

pdf.setgrayStroke(0.0)
pdf.comments("\n%% one circle.\n")
pdf.circle(xorig, yorig, radius)
pdf.stroke

pdf.setrgbcolorStroke(0.0, 0.0, 1.0)
pdf.comments("\n%% Arcs from 30 to various angles in 30 deg steps.\n")

i = 11
while i >= 0
  radius -= rbump
  eangle = (i+1) * 30.0
  sangle = 0.0
  pdf.arc(xorig, yorig, radius, sangle, eangle, 1)
  pdf.stroke
  i -= 1
end

yorig = 7.5
radius= 2.2
pdf.setgrayStroke(0.0)
pdf.comments("\n%% one circle again.\n")
pdf.circle(xorig, yorig, radius)
pdf.stroke

pdf.setrgbcolorStroke(0.7, 0.7, 0.0)
pdf.comments("\n%% Pie-shapes from 30 to various angles in 30 deg steps.\n")

i = 11
while i >= 0
  radius -= rbump
  greenblue = i.to_f / 12.0
  pdf.setrgbcolorFill(1.0, greenblue, greenblue)
  eangle = (i+1) * 30.0
  sangle = 0.0
  pdf.moveto(xorig, yorig)
  pdf.arc(xorig, yorig, radius, sangle, eangle, 0)
  pdf.closepath
  pdf.fillAndStroke
  i -= 1
end

xorig = 6.0
yorig = 2.5
pdf.setgrayStroke(0.0)
pdf.setrgbcolorFill(0.6, 0.6, 1.0)
pdf.arc(xorig, yorig, 0.5, 0.0, 360.0, 1)
pdf.arc(xorig, yorig, 1.0, 0.0, 360.0, 1)
pdf.fillAndStroke
pdf.setgrayFill(0.0)
pdf.pointer(xorig+0.5, yorig, ClibPDF::PTR_UP, 8.0)
pdf.pointer(xorig-0.5, yorig, ClibPDF::PTR_DOWN, 8.0)
pdf.pointer(xorig+1.0, yorig, ClibPDF::PTR_UP, 8.0)
pdf.pointer(xorig-1.0, yorig, ClibPDF::PTR_DOWN, 8.0)

xorig = 6.0
yorig = 7.5
pdf.setrgbcolorFill(0.6, 0.6, 1.0)
pdf.arc(xorig, yorig, 0.5, 360.0, 0.0, 1); pdf.closepath
pdf.arc(xorig, yorig, 1.0, 0.0, 360.0, 1); pdf.closepath
pdf.fillAndStroke
pdf.setgrayFill(0.0)
pdf.pointer(xorig+0.5, yorig, ClibPDF::PTR_DOWN, 8.0)
pdf.pointer(xorig-0.5, yorig, ClibPDF::PTR_UP, 8.0)
pdf.pointer(xorig+1.0, yorig, ClibPDF::PTR_UP, 8.0)
pdf.pointer(xorig-1.0, yorig, ClibPDF::PTR_DOWN, 8.0)

pdf.beginText(0)
pdf.setFont("Times-Italic", "MacRomanEncoding", 16.0)
pdf.text(1.6, 2.0, 0.0, "Test of arcs and circles")
pdf.text(1.6, 7.0, 0.0, "Color filled pie shapes")
pdf.text(4.7, 5.0, 0.0, "Non-zero winding rule for fill")
pdf.endText

pdf.finalizeAll
pdf.savePDFmemoryStreamToFile("Arcs.pdf")

pdf.close()
#pdf.launchPreview
