Method: PDF::Writer::Graphics#star

Defined in:
lib/pdf/writer/graphics.rb

#star(cx, cy, length, rays = 5) ⇒ Object

Draws a star centered on (x, y) with rays portions of length from the centre. Stars with an odd number of rays should have the top ray pointing toward the top of the document. This will not create a “star” with fewer than four points.

New Point

(cx, cy)

Subpath

New



416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
# File 'lib/pdf/writer/graphics.rb', line 416

def star(cx, cy, length, rays = 5)
  rays = 4 if rays < 4
  points = []
  part = Math::PI / rays.to_f

  0.step((rays * 4), 2) do |ray|
    if ((ray / 2) % 2 == 0)
      dist = length / 2.0
    else
      dist = length
    end

    x = cx + Math.cos((1.5 + ray / 2.0) * part) * dist
    y = cy + Math.sin((1.5 + ray / 2.0) * part) * dist
    points << [ x, y ]
  end

  polygon(points)
  move_to(cx, cy)
  self
end