sketchupでruby その11

# 概要

sketchupでrubyやってみた。
練習問題やってみた。

# 練習問題

SGIのロゴを作れ。

# 写真

![sgi.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/e3bbb659-f72c-bedd-b23f-071255c2b2f1.png)


# サンプルコード

```
class Sgi
  def initialize
    @model = Sketchup.active_model
    @entities = @model.active_entities
    @x = 0
    @y = 0
    @z = 0
    @v = "-z"
  end
  def enjin(move, vec)
    x1, y1, z1 = 0, 0, 0
    p1 = Geom::Point3d.new(@x, @y, @z)
    case @v + String(vec)
    when "x0"
      y1 = move
      @v = "y"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, Y_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, Y_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, X_AXIS, Z_AXIS, 0.4, 0, -Math::PI / 2, 24
    when "x1"
      z1 = move
      @v = "z"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, Z_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, Z_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, X_AXIS, Y_AXIS, 0.4, Math::PI, -Math::PI / 2, 24
    when "x2"
      y1 = -move
      @v = "-y"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, Y_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, Y_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, X_AXIS, Z_AXIS, 0.4, 0, Math::PI / 2, 24
    when "x3"
      z1 = -move
      @v = "-z"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, Z_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, Z_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, X_AXIS, Y_AXIS, 0.4, 0, -Math::PI / 2, 24
    when "-x0"
      y1 = -move
      @v = "-y"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, Y_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, Y_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, X_AXIS, Z_AXIS, 0.4, Math::PI, Math::PI * 0.5, 24
    when "-x1"
      z1 = -move
      @v = "-z"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, Z_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, Z_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, X_AXIS, Y_AXIS, 0.4, Math::PI / 2, -Math::PI, 24
    when "-x2"
      y1 = move
      @v = "y"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, Y_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, Y_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, X_AXIS, Z_AXIS, 0.4, 0, -Math::PI / 2, 24
    when "-x3"
      z1 = move
      @v = "z"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, Z_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, Z_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, X_AXIS, Y_AXIS, 0.4, 0, -Math::PI / 2, 24
    when "y1"
      z1 = move
      @v = "z"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, Z_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, Z_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, Y_AXIS, X_AXIS, 0.4, 0, -Math::PI / 2, 24
    when "y2"
      x1 = move
      @v = "x"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, X_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, X_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, Y_AXIS, Z_AXIS, 0.4, 0, -Math::PI / 2, 24
    when "y3"
      z1 = -move
      @v = "-z"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, Z_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, Z_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, Y_AXIS, X_AXIS, 0.4, 0, -Math::PI / 2, 24
    when "y0"
      x1 = -move
      @v = "-x"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, X_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, X_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, Y_AXIS, Z_AXIS, 0.4, 0, -Math::PI / 2, 24
    when "-y1"
      z1 = -move
      @v = "-z"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, Z_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, Z_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, Y_AXIS, X_AXIS, 0.4, Math::PI, Math::PI * 0.5, 24
    when "-y2"
      x1 = -move
      @v = "-x"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, X_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, X_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, Y_AXIS, Z_AXIS, 0.4, 0, -Math::PI / 2, 24
    when "-y3"
      z1 = move
      @v = "z"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, Z_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, Z_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, Y_AXIS, X_AXIS, 0.4, 0, -Math::PI / 2, 24
    when "-y0"
      x1 = move
      @v = "x"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, X_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, X_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, Y_AXIS, Z_AXIS, 0.4, Math::PI / 2, Math::PI, 24
    when "z1"
      x1 = move
      @v = "x"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, X_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, X_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, Z_AXIS, Y_AXIS, 0.4, 0, -Math::PI / 2, 24
    when "z2"
      y1 = move
      @v = "y"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, Y_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, Y_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, Z_AXIS, X_AXIS, 0.4, 0, -Math::PI / 2, 24
    when "z3"
      x1 = -move
      @v = "-x"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, X_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, X_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, Z_AXIS, Y_AXIS, 0.4, 0, Math::PI / 2, 24
    when "z0"
      y1 = -move
      @v = "-y"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, Y_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, Y_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, Z_AXIS, X_AXIS, 0.4, 0, -Math::PI / 2, 24
    when "-z1"
      x1 = -move
      @v = "-x"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, X_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, X_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, Z_AXIS, Y_AXIS, 0.4, 0, -Math::PI / 2, 24
    when "-z2"
      y1 = -move
      @v = "-y"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, Y_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, Y_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, Z_AXIS, X_AXIS, 0.4, 0, -Math::PI / 2, 24
    when "-z3"
      x1 = move
      @v = "x"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, X_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, X_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, Z_AXIS, Y_AXIS, 0.4, Math::PI, Math::PI * 1.5, 24
    when "-z0"
      y1 = move
      @v = "y"
      p2 = Geom::Point3d.new(@x + x1, @y + y1, @z + z1)
      circleBase1 = @entities.add_circle(p1, Y_AXIS, 0.4, 24)
      circleBase2 = @entities.add_circle(p2, Y_AXIS, 0.4, 24)
      curve = @entities.add_arc p1, Z_AXIS, X_AXIS, 0.4, Math::PI / 2, Math::PI, 24
    end
    base = @entities.add_face(circleBase1)
    base1 = @entities.add_face(circleBase2)
    status = base.followme(curve)
    line1 = @entities.add_line(p1, p2)
    status = base1.followme(line1)
    @x, @y, @z = @x + x1, @y + y1, @z + z1
  end
  def draw
    enjin(9, 0)
    enjin(8, 1)
    enjin(8, 0)
    enjin(9, 0)
    enjin(9, 0)
    enjin(8, 0)
    enjin(8, 1)
    enjin(9, 3)
    enjin(7, 1)
    enjin(9, 0)
    enjin(8, 1)
    enjin(8, 0)
    enjin(9, 0)
    enjin(9, 0)
    enjin(8, 0)
    enjin(8, 1)
    enjin(9, 3)
    enjin(7, 1)
  end
end

```

以上。