#!/usr/bin/ruby # coding: utf-8 require "mini_magick" # 画像の幅 width = 300 # 画像の高さ height = 300 # 画像用配列を用意して白で初期化する pix = Array.new(height) { Array.new(width) { Array.new(3, 255) } } # 円の中心 x0 = width / 2 y0 = height / 2 # 円の半径 r = 100 # 円の描画 (0..359).each do |i| # 角度からラジアンに変換 phi = i * Math::PI / 180 # (x,y)座標の計算 x = (r * Math.cos(phi)).round + x0 y = (r * Math.sin(phi)).round + y0 # 座標のピクセルを塗る pix[y][x] = [0, 0, 0] end # 配列から画像にする image = MiniMagick::Image.get_image_from_pixels(pix, [width, height], "rgb", 8, "png") # 画像ファイルの書き込み image.write("output.png")