LoginSignup
13
13

More than 5 years have passed since last update.

東京五輪エンブレム for Ruby

Last updated at Posted at 2015-08-07

乗るしかない このビッグウェーブに

これでみんないつでも描けるね! 東京五輪エンブレムのコードがオープンソースに - ねとらぼ
東京五輪エンブレム for iOS
東京五輪エンブレム for Android

東京五輪エンブレムをRubyで描画しました。描画ライブラリにはcairo(rcairo)を使用しています。

インストール

$ gem install cairo

コード

tokyo_olympic_logo.rb
require 'cairo'

format = Cairo::FORMAT_ARGB32
width = height = 480

surface = Cairo::ImageSurface.new(format, width, height)
context = Cairo::Context.new(surface)

a = 160
context.set_source_rgb(1, 1, 1) # white
context.rectangle(0, 0, width, height)
context.fill

context.set_source_rgb(0.7, 0.57, 0.27) # yellow
context.rectangle(0, 0, a, a)
context.fill

context.set_source_rgb(0.7, 0.7, 0.7) # gray
context.rectangle(a * 2, a * 2, a, a)
context.fill

# r = Math.sqrt(1.5 * 1.5 + 0.5 * 0.5) * a
r = Math.hypot(1.5, 0.5) * a # こうとも書ける
context.set_source_rgb(1, 1, 1) # white
context.arc(1.5 * a, 1.5 * a, r, 0, 2 * Math::PI)
context.fill

context.set_source_rgb(0, 0, 0) # black
context.rectangle(a, 0, a, a * 3)
context.fill

context.set_source_rgb(0.9, 0, 0.08) # red
context.arc(2.5 * a, 0.5 * a, 0.5 * a, 0, 2 * Math::PI)
context.fill

surface.write_to_png("tol.png")


実行結果

tol.png

cairo初めて使いましたがすごく便利です

13
13
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
13