Module: Windraw

Defined in:
lib/windraw.rb,
lib/windraw/color.rb,
lib/windraw/surface.rb,
lib/windraw/version.rb,
ext/windraw/windraw.cpp

Overview

windraw — headless 2D drawing for Windows using Direct2D + DirectWrite + WIC.

Windraw.surface(800, 600) do |c|
  c.clear("#1e1e2e")
  c.rectangle(50, 50, 200, 120, fill: "#89b4fa")
  c.ellipse(400, 300, 80, 50, fill: "#a6e3a1")
  c.text("Hello, Direct2D!", 60, 200, font: "Segoe UI", size: 32, color: "#cdd6f4")
end.save("out.png")

Defined Under Namespace

Modules: Color Classes: Surface

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.surface(width, height) ⇒ Object

Create a drawing surface of the given pixel size. With a block, yields the surface, finishes drawing when the block returns, and returns the surface (so you can chain #save / #to_png). Without a block, returns an open surface.

width/height are whole pixels; a Float is truncated toward zero (NUM2INT).



22
23
24
25
26
27
28
29
# File 'lib/windraw.rb', line 22

def self.surface(width, height)
  surface = Surface.new(width, height)
  if block_given?
    yield surface
    surface.finish
  end
  surface
end