S
shawn bright
Hello all, i am back with this one.
my problem is that i am trying to draw a line on a circle that will
indicate a certain angle.
kinda like the hands on a clock. I have a line image that i rotate
around and then superimpose upon the circle image that i draw.
The problem is that when the line image is rotated, it is shorter than
the circle.
here is the code.
#!/usr/bin/ruby
require 'RMagick'
def gps_image(r)
# fetches the image file
gps_image = Magick::Image.read('line_stop.png').first
gps_image.background_color = 'none'
angle = 45
gps_image.rotate!(angle)
factor = (r.to_i * 2)
gps_image.crop_resized!(factor, factor, Magick::CenterGravity)
gps_image.write("site.site_name.png")
return gps_image
end
def circle_image
r = 45
#start with a bare canvas (square 2 times the radius of circle) the
extra two pixels is to not cut any of the border
canvas = Magick::Image.new((2 * r) +2, (2*r) +2,
Magick::HatchFill.new('transparent', 'transparent'))
# draw the circle
gc = Magick:raw.new
gc.stroke('red')
gc.stroke_width(1)
# fill in the inside
color = 'blue'
gc.fill(color)
gc.fill_opacity(0.3)
gc.circle(r, r, 0, r)
# put our circle on the canvas
image = gc.draw(canvas)
# place the line for gps circles
gps_image = gps_image(r)
canvas.composite!(gps_image, 0, 0, Magick::OverCompositeOp)
# write the image out as a file
canvas.write("circle.png")
end
circle_image()
Everything is ok if the image is 90, 180, 270, or 0 degrees, but the
more i stray toward 45 degrees or so, the smaller the line comes out
on the image.
the image used here ( line_stop.png) is just a transparent image with
a line drawn on it in the middle. ( my clock hand )
thanks for any tips.
shawn
my problem is that i am trying to draw a line on a circle that will
indicate a certain angle.
kinda like the hands on a clock. I have a line image that i rotate
around and then superimpose upon the circle image that i draw.
The problem is that when the line image is rotated, it is shorter than
the circle.
here is the code.
#!/usr/bin/ruby
require 'RMagick'
def gps_image(r)
# fetches the image file
gps_image = Magick::Image.read('line_stop.png').first
gps_image.background_color = 'none'
angle = 45
gps_image.rotate!(angle)
factor = (r.to_i * 2)
gps_image.crop_resized!(factor, factor, Magick::CenterGravity)
gps_image.write("site.site_name.png")
return gps_image
end
def circle_image
r = 45
#start with a bare canvas (square 2 times the radius of circle) the
extra two pixels is to not cut any of the border
canvas = Magick::Image.new((2 * r) +2, (2*r) +2,
Magick::HatchFill.new('transparent', 'transparent'))
# draw the circle
gc = Magick:raw.new
gc.stroke('red')
gc.stroke_width(1)
# fill in the inside
color = 'blue'
gc.fill(color)
gc.fill_opacity(0.3)
gc.circle(r, r, 0, r)
# put our circle on the canvas
image = gc.draw(canvas)
# place the line for gps circles
gps_image = gps_image(r)
canvas.composite!(gps_image, 0, 0, Magick::OverCompositeOp)
# write the image out as a file
canvas.write("circle.png")
end
circle_image()
Everything is ok if the image is 90, 180, 270, or 0 degrees, but the
more i stray toward 45 degrees or so, the smaller the line comes out
on the image.
the image used here ( line_stop.png) is just a transparent image with
a line drawn on it in the middle. ( my clock hand )
thanks for any tips.
shawn