Anonymous user
Constrained random points on a circle: Difference between revisions
Constrained random points on a circle (view source)
Revision as of 15:42, 15 November 2011
, 12 years ago→{{header|Ruby}}: add image
m (→{{header|Ruby}}: add image) |
|||
Line 1,460:
=={{header|Ruby}}==
Create the image with [[Raster graphics operations/Ruby]]
<lang Ruby>points = (1...100).map {
# choose a random radius and angle
Line 1,471:
(-15..15).each do |row|
puts((-15..15).map { |col| points.include?([row, col]) ? "X" : " " }.join)
end
load 'raster_graphics.rb'
pixmap = Pixmap.new(321,321)
pixmap.draw_circle(Pixel.new(160,160),90,RGBColour::BLACK)
pixmap.draw_circle(Pixel.new(160,160),160,RGBColour::BLACK)
points.each {|(x,y)| pixmap[10*(x+16),10*(y+16)] = RGBColour::BLACK}
pngfile = __FILE__
pngfile[/\.rb/] = ".png"
pixmap.save_as_png(pngfile)</lang>
outputs:
[[File:constrainedrandompointsonacircle.png|thumg|right|Sample output from Ruby program]]
<pre> X X
X XX
X XXX
XX X X X X X
XXXXX
XX XX
X X X
X X
X X
X X XXX
X
XX X X
X X
X X
XXX X
XX X
XXX X X
XX X X X
XX X X
X X
X
XX X X
X X X
X X X
X
X X X
X X X
X X</pre>
=={{header|SystemVerilog}}==
|