Skip to content

Commit

Permalink
Update documents (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 authored Apr 16, 2024
1 parent 2f31aa5 commit bb4e445
Show file tree
Hide file tree
Showing 43 changed files with 271 additions and 273 deletions.
14 changes: 7 additions & 7 deletions arcs02.rb.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ <h1>arcs02.rb</h1>

Magick::RVG.dpi = 90

PathStyles = { fill: 'none', stroke: 'red', stroke_width: 6 }
BaseEllipsesStyles = { font_size: 20, font_family: 'Verdana', fill: 'none', stroke: '#888', stroke_width: 2 }
PATH_STYLES = { fill: 'none', stroke: 'red', stroke_width: 6 }
BASE_ELLIPSES_STYLES = { font_size: 20, font_family: 'Verdana', fill: 'none', stroke: '#888', stroke_width: 2 }

rvg = Magick::RVG.new(12.cm, 5.25.cm).viewbox(0, 0, 1200, 525) do |canvas|
canvas.title = 'Example arcs02 - arc options in paths'
Expand All @@ -27,7 +27,7 @@ <h1>arcs02.rb</h1>
END_DESC
canvas.background_fill = 'white'

base_ellipses = Magick::RVG::Group.new.styles(BaseEllipsesStyles) do |base|
base_ellipses = Magick::RVG::Group.new.styles(BASE_ELLIPSES_STYLES) do |base|
base.ellipse(100, 50, 125, 125)
base.ellipse(100, 50, 225, 75)
base.text(35, 70, 'Arc start')
Expand All @@ -43,28 +43,28 @@ <h1>arcs02.rb</h1>
grp2.text(50, 210, 'large-arc-flag=0')
grp2.text(50, 250, 'sweep-flag=0')
grp2.use(base_ellipses)
grp2.path('M 125,75 a100,50 0 0,0 100,50').styles(PathStyles)
grp2.path('M 125,75 a100,50 0 0,0 100,50').styles(PATH_STYLES)
end

grp.g.translate(800, 0) do |grp2|
grp2.text(50, 210, 'large-arc-flag=0')
grp2.text(50, 250, 'sweep-flag=1')
grp2.use(base_ellipses)
grp2.path('M 125,75 a100,50 0 0,1 100,50').styles(PathStyles)
grp2.path('M 125,75 a100,50 0 0,1 100,50').styles(PATH_STYLES)
end

grp.g.translate(400, 250) do |grp2|
grp2.text(50, 210, 'large-arc-flag=1')
grp2.text(50, 250, 'sweep-flag=0')
grp2.use(base_ellipses)
grp2.path('M 125,75 a100,50 0 1,0 100,50').styles(PathStyles)
grp2.path('M 125,75 a100,50 0 1,0 100,50').styles(PATH_STYLES)
end

grp.g.translate(800, 250) do |grp2|
grp2.text(50, 210, 'large-arc-flag=1')
grp2.text(50, 250, 'sweep-flag=1')
grp2.use(base_ellipses)
grp2.path('M 125,75 a100,50 0 1,1 100,50').styles(PathStyles)
grp2.path('M 125,75 a100,50 0 1,1 100,50').styles(PATH_STYLES)
end
end
end
Expand Down
17 changes: 8 additions & 9 deletions colors.rb.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ <h1>colors.rb</h1>
<div class="bodyfloat">
<pre>
require 'rmagick'
include Magick

puts('Creating colors.miff. This may take a few seconds...')

colors = ImageList.new
colors = Magick::ImageList.new

# Add a row of "null" colors so we'll have
# room to add the title at the top.
Expand All @@ -26,7 +25,7 @@ <h1>colors.rb</h1>

# Create a 200x25 image for each named color.
# Label with the name, RGB values, and compliance type.
colors do |c|
Magick.colors do |c|
if c.name !~ /grey/ # omit SVG 'grays'
colors.new_image(200, 25) do |options|
options.background_color = c.color
Expand All @@ -45,7 +44,7 @@ <h1>colors.rb</h1>
# There will be 16 images.
montage = colors.montage do |options|
options.geometry = '200x25+10+5'
options.gravity = CenterGravity
options.gravity = Magick::CenterGravity
options.tile = '4x10'
options.background_color = 'black'
options.border_width = 1
Expand All @@ -55,22 +54,22 @@ <h1>colors.rb</h1>

# Add the title at the top, over the 'null:'
# tiles we added at the very beginning.
title = Draw.new
title = Magick::Draw.new
title.annotate(montage, 0, 0, 0, 20, 'Named Colors') do |options|
options.fill = 'white'
options.stroke = 'transparent'
options.pointsize = 32
options.font_weight = BoldWeight
options.gravity = NorthGravity
options.font_weight = Magick::BoldWeight
options.gravity = Magick::NorthGravity
end

puts("\tWriting ./colors.miff")
montage.each { |f| f.compression = ZipCompression }
montage.each { |f| f.compression = Magick::ZipCompression }
montage.write('colors.miff')

# Make a small sample of the full montage to display in the HTML file.
sample = montage[8].crop(55, 325, 495, 110)
sample.page = Rectangle.new(495, 110)
sample.page = Magick::Rectangle.new(495, 110)
sample.write('colors.gif')

exit
Expand Down
81 changes: 40 additions & 41 deletions composite.rb.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,126 +15,125 @@ <h1>composite.rb</h1>
# Based on ImageMagick's composite test.

require 'rmagick'
include Magick

ROWS = 70
COLS = 70
COLOR_A = '#999966'
COLOR_B = '#990066'

img = Image.new(COLS, ROWS)
triangle = Draw.new
img = Magick::Image.new(COLS, ROWS)
triangle = Magick::Draw.new
triangle.fill(COLOR_A)
triangle.stroke('transparent')
triangle.polygon(0, 0, COLS, 0, 0, ROWS, 0, 0)
triangle.draw(img)
image_a = img.transparent('white', alpha: TransparentAlpha)
image_a = img.transparent('white', alpha: Magick::TransparentAlpha)
image_a['Label'] = 'A'

img = Image.new(COLS, ROWS)
triangle = Draw.new
img = Magick::Image.new(COLS, ROWS)
triangle = Magick::Draw.new
triangle.fill(COLOR_B)
triangle.stroke('transparent')
triangle.polygon(0, 0, COLS, ROWS, COLS, 0, 0, 0)
triangle.draw(img)
image__b = img.transparent('white', alpha: TransparentAlpha)
image__b = img.transparent('white', alpha: Magick::TransparentAlpha)
image__b['Label'] = 'B'

list = ImageList.new
null = Image.read('xc:white') { |options| options.size = Geometry.new(COLS, ROWS) }
null = null.first.transparent('white', alpha: TransparentAlpha)
list = Magick::ImageList.new
null = Magick::Image.read('xc:white') { |options| options.size = Magick::Geometry.new(COLS, ROWS) }
null = null.first.transparent('white', alpha: Magick::TransparentAlpha)
null.border_color = 'transparent'
granite = Image.read('granite:')
granite = Magick::Image.read('granite:')

list &lt;&lt; null.copy
list &lt;&lt; image_a
list &lt;&lt; image__b
list &lt;&lt; null.copy

list &lt;&lt; image__b.composite(image_a, CenterGravity, OverCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::OverCompositeOp)
list.cur_image['Label'] = 'A over B'
list &lt;&lt; image_a.composite(image__b, CenterGravity, OverCompositeOp)
list &lt;&lt; image_a.composite(image__b, Magick::CenterGravity, Magick::OverCompositeOp)
list.cur_image['Label'] = 'B over A'

list &lt;&lt; image__b.composite(image_a, CenterGravity, InCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::InCompositeOp)
list.cur_image['Label'] = 'A in B'
list &lt;&lt; image_a.composite(image__b, CenterGravity, InCompositeOp)
list &lt;&lt; image_a.composite(image__b, Magick::CenterGravity, Magick::InCompositeOp)
list.cur_image['Label'] = 'B in A'

list &lt;&lt; image__b.composite(image_a, CenterGravity, OutCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::OutCompositeOp)
list.cur_image['Label'] = 'A out B'
list &lt;&lt; image_a.composite(image__b, CenterGravity, OutCompositeOp)
list &lt;&lt; image_a.composite(image__b, Magick::CenterGravity, Magick::OutCompositeOp)
list.cur_image['Label'] = 'B out A'

list &lt;&lt; image__b.composite(image_a, CenterGravity, AtopCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::AtopCompositeOp)
list.cur_image['Label'] = 'A atop B'
list &lt;&lt; image_a.composite(image__b, CenterGravity, AtopCompositeOp)
list &lt;&lt; image_a.composite(image__b, Magick::CenterGravity, Magick::AtopCompositeOp)
list.cur_image['Label'] = 'B atop A'

list &lt;&lt; image__b.composite(image_a, CenterGravity, XorCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::XorCompositeOp)
list.cur_image['Label'] = 'A xor B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, MultiplyCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::MultiplyCompositeOp)
list.cur_image['Label'] = 'A multiply B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, ScreenCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::ScreenCompositeOp)
list.cur_image['Label'] = 'A screen B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, DarkenCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::DarkenCompositeOp)
list.cur_image['Label'] = 'A darken B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, LightenCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::LightenCompositeOp)
list.cur_image['Label'] = 'A lighten B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, PlusCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::PlusCompositeOp)
list.cur_image['Label'] = 'A plus B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, MinusDstCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::MinusDstCompositeOp)
list.cur_image['Label'] = 'A minus B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, ModulusAddCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::ModulusAddCompositeOp)
list.cur_image['Label'] = 'A add B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, ModulusSubtractCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::ModulusSubtractCompositeOp)
list.cur_image['Label'] = 'A subtract B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, DifferenceCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::DifferenceCompositeOp)
list.cur_image['Label'] = 'A difference B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, HueCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::HueCompositeOp)
list.cur_image['Label'] = 'A hue B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, SaturateCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::SaturateCompositeOp)
list.cur_image['Label'] = 'A saturate B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, LuminizeCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::LuminizeCompositeOp)
list.cur_image['Label'] = 'A luminize B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, ColorizeCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::ColorizeCompositeOp)
list.cur_image['Label'] = 'A colorize B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, BumpmapCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::BumpmapCompositeOp)
list.cur_image['Label'] = 'A bumpmap B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, DissolveCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::DissolveCompositeOp)
list.cur_image['Label'] = 'A dissolve B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, ThresholdCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::ThresholdCompositeOp)
list.cur_image['Label'] = 'A threshold B'

list &lt;&lt; image__b.composite(image_a, CenterGravity, ModulateCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::ModulateCompositeOp)
list.cur_image['Label'] = 'A modulate B'

list &lt;&lt; image_a.composite(image__b, CenterGravity, ModulateCompositeOp)
list &lt;&lt; image_a.composite(image__b, Magick::CenterGravity, Magick::ModulateCompositeOp)
list.cur_image['Label'] = 'B modulate A'

list &lt;&lt; image__b.composite(image_a, CenterGravity, OverlayCompositeOp)
list &lt;&lt; image__b.composite(image_a, Magick::CenterGravity, Magick::OverlayCompositeOp)
list.cur_image['Label'] = 'A overlay B'

montage = list.montage do |options|
options.geometry = Geometry.new(COLS, ROWS, 3, 3)
options.geometry = Magick::Geometry.new(COLS, ROWS, 3, 3)
rows = (list.size + 3) / 4
options.tile = Geometry.new(4, rows)
options.tile = Magick::Geometry.new(4, rows)
options.texture = granite[0]
options.fill = 'white'
options.stroke = 'transparent'
Expand Down
21 changes: 10 additions & 11 deletions crop_with_gravity.rb.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,27 @@ <h1>crop_with_gravity.rb</h1>
# Demo the use of the GravityType argument to Image#crop.

require 'rmagick'
include Magick

shorts = Image.read('images/Shorts.jpg').first
shorts = Magick::Image.read('images/Shorts.jpg').first

regwidth = shorts.columns / 2
regheight = shorts.rows / 2

mask = Image.new(regwidth, regheight) { |info| info.background_color = 'white' }
mask = Magick::Image.new(regwidth, regheight) { |info| info.background_color = 'white' }
mask.alpha(Magick::ActivateAlphaChannel)
mask.quantum_operator(SetQuantumOperator, 0.50 * QuantumRange, AlphaChannel)
mask.quantum_operator(Magick::SetQuantumOperator, 0.50 * Magick::QuantumRange, Magick::AlphaChannel)

black = Image.new(shorts.columns, shorts.rows) { |info| info.background_color = 'black' }
pairs = ImageList.new
black = Magick::Image.new(shorts.columns, shorts.rows) { |info| info.background_color = 'black' }
pairs = Magick::ImageList.new

[
NorthWestGravity, NorthGravity, NorthEastGravity,
WestGravity, CenterGravity, EastGravity,
SouthWestGravity, SouthGravity, SouthEastGravity
Magick::NorthWestGravity, Magick::NorthGravity, Magick::NorthEastGravity,
Magick::WestGravity, Magick::CenterGravity, Magick::EastGravity,
Magick::SouthWestGravity, Magick::SouthGravity, Magick::SouthEastGravity
].each do |gravity|
pattern = shorts.composite(mask, gravity, OverCompositeOp)
pattern = shorts.composite(mask, gravity, Magick::OverCompositeOp)
cropped = shorts.crop(gravity, regwidth, regheight)
result = black.composite(cropped, gravity, OverCompositeOp)
result = black.composite(cropped, gravity, Magick::OverCompositeOp)
result.border_color = 'white'
pairs &lt;&lt; pattern
pairs &lt;&lt; result
Expand Down
44 changes: 22 additions & 22 deletions cubic01.rb.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ <h1>cubic01.rb</h1>

Magick::RVG.dpi = 90

Border = { fill: 'none', stroke: 'blue', stroke_width: 1 }
Connect = { fill: 'none', stroke: '#888', stroke_width: 2 }
SamplePath = { fill: 'none', stroke: 'red', stroke_width: 5 }
EndPoint = { fill: 'none', stroke: '#888', stroke_width: 2 }
CtlPoint = { fill: '#888', stroke: 'none' }
AutoCtlPoint = { fill: 'none', stroke: 'blue', stroke_width: 4 }
Label = { font_size: 22, font_family: 'Verdana', font_weight: 'normal', font_style: 'normal' }
BORDER = { fill: 'none', stroke: 'blue', stroke_width: 1 }
CONNECT = { fill: 'none', stroke: '#888', stroke_width: 2 }
SAMPLE_PATH = { fill: 'none', stroke: 'red', stroke_width: 5 }
END_POINT = { fill: 'none', stroke: '#888', stroke_width: 2 }
CTL_POINT = { fill: '#888', stroke: 'none' }
AUTO_CTL_POINT = { fill: 'none', stroke: 'blue', stroke_width: 4 }
LABEL = { font_size: 22, font_family: 'Verdana', font_weight: 'normal', font_style: 'normal' }

rvg = Magick::RVG.new(5.cm, 4.cm).viewbox(0, 0, 500, 400) do |canvas|
canvas.title = 'Example cubic01 - cubic Bezier commands in path data'
Expand All @@ -32,25 +32,25 @@ <h1>cubic01.rb</h1>
END_DESC

canvas.background_fill = 'white'
canvas.rect(496, 395, 1, 1).styles(Border)
canvas.rect(496, 395, 1, 1).styles(BORDER)

canvas.polyline(100, 200, 100, 100).styles(Connect)
canvas.polyline(250, 100, 250, 200).styles(Connect)
canvas.polyline(250, 200, 250, 300).styles(Connect)
canvas.polyline(400, 300, 400, 200).styles(Connect)
canvas.polyline(100, 200, 100, 100).styles(CONNECT)
canvas.polyline(250, 100, 250, 200).styles(CONNECT)
canvas.polyline(250, 200, 250, 300).styles(CONNECT)
canvas.polyline(400, 300, 400, 200).styles(CONNECT)

canvas.path('M100,200 C100,100 250,100 250,200 S400,300 400,200').styles(SamplePath)
canvas.path('M100,200 C100,100 250,100 250,200 S400,300 400,200').styles(SAMPLE_PATH)

canvas.circle(10, 100, 200).styles(EndPoint)
canvas.circle(10, 250, 200).styles(EndPoint)
canvas.circle(10, 400, 200).styles(EndPoint)
canvas.circle(10, 100, 100).styles(CtlPoint)
canvas.circle(10, 250, 100).styles(CtlPoint)
canvas.circle(10, 400, 300).styles(CtlPoint)
canvas.circle(9, 250, 300).styles(AutoCtlPoint)
canvas.circle(10, 100, 200).styles(END_POINT)
canvas.circle(10, 250, 200).styles(END_POINT)
canvas.circle(10, 400, 200).styles(END_POINT)
canvas.circle(10, 100, 100).styles(CTL_POINT)
canvas.circle(10, 250, 100).styles(CTL_POINT)
canvas.circle(10, 400, 300).styles(CTL_POINT)
canvas.circle(9, 250, 300).styles(AUTO_CTL_POINT)

canvas.text(25, 70, 'M100,200 C100,100 250,100 250,200').styles(Label)
canvas.text(225, 350, 'S400,300 400,200').styles(Label)
canvas.text(25, 70, 'M100,200 C100,100 250,100 250,200').styles(LABEL)
canvas.text(225, 350, 'S400,300 400,200').styles(LABEL)
end

rvg.draw.write('cubic01.gif')
Expand Down
Loading

0 comments on commit bb4e445

Please sign in to comment.