0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

windows11で、sketchup6 その113

Posted at

概要

windows11に、sketchup6を入れてみた。
rubyで、3Dを書く。
タートルグラフィックスを見つけたのでやってみた。

参考にしたページ

写真

image.png

サンプルコード

class Kame5
	def initialize
		model = Sketchup.active_model
		@entities = model.active_entities
		@ANGLE = 0
		@LX = 10
		@LY = 10
		@pen = 0
		run()
	end
	def fmod(a, b)
		x = (a / b).floor
		return a - b * x
	end
	def penup()
		@pen = 0
	end
	def down()
		@pen = 1
	end
	def turn(a)
		@ANGLE = fmod(@ANGLE + a, 360.0)
	end
	def move(l)
		p = []
		rd = Math::PI / 180.0
		x = l * Math::cos(rd * @ANGLE)
		y = -l * Math::sin(rd * @ANGLE)
		px = @LX
		py = @LY
		p << [px, py, 0]
		@LX += x
		@LY += y
		p << [@LX, @LY, 0]
		if @pen == 1
			@entities.add_curve(p)
		end
	end
	def goto(x, y)
		p = []
		px = @LX
		py = @LY
		p << [px, py, 0]
		@LX = x
		@LY = y
		p << [@LX, @LY, 0]
		if @pen == 1
			@entities.add_curve(p)
		end
	end
	def circle(r)
		if @pen == 1
			@entities.add_circle([@LX, @LY + r, 0], Z_AXIS, r, 24)
		end
	end
	def circle2(r, d)
		if @pen == 1
			center = [@LX, @LY + r, 0]
			vector = Geom::Vector3d.new 0, 0, 1
			normal = vector.normalize!
			@entities.add_arc center, X_AXIS, normal, r / 2, (@ANGLE).degrees, (@ANGLE + d).degrees
		end
	end
	def dot(r)
		r = r / 2
		face = @entities.add_circle([@LX, @LY, 0], Z_AXIS, r, 24)
		circle = @entities.add_face face
	end
	def setheading(h)
		@ANGLE = h + 90
	end
	def setx(x)
		@LX = x
	end
	# まるかいてちょん
	def maru_chon(i)
		penup()
		goto(50 * i, 100)
		down()
		circle(50)
		penup()
		goto(30 * i, 140)
		dot(20)
	end
	# お豆に芽が出てて―
	def omame()
		penup()
		goto(0, 80)
		down()
		circle(20)
		goto(0, 50)
	end
	# お空に三日月のぼってた
	def osora_mikaduki()
		penup()
		goto(-40, 50)
		down()
		goto(40, 50)
		penup()
		goto(0, -30)
		down()
		setheading(90)
		circle2(80, 180)
		setheading(90)
	end
	# 植木鉢1
	def uekibachi_1()
		penup()
		goto(90, -40)
		down()
		setheading(180)
		circle2(100, 180)
		setx(-90)
		setheading(0)
		circle2(100, 180)
	end
	# 植木鉢2
	def uekibachi_2()
		penup()
		goto(0, -200)
		down()
		setheading(0)
		circle2(370, 160)
		setheading(200)
		circle2(370, 160)
		penup()
		goto(-67, 0)
		down()
		goto(67, 0)
	end
	# ひげを付けたら
	def hige(i)
		penup()
		goto(90 * i, 80)
		down()
		goto(130 * i, 90)
		penup()
		goto(90 * i, 60)
		down()
		goto(130 * i, 60)
		penup()
		goto(90 * i, 40)
		down()
		goto(130 * i, 30)
	end
	def run()
		maru_chon(-1)
		maru_chon(1)
		omame()
		osora_mikaduki()
		uekibachi_1()
		uekibachi_2()
		hige(-1)
		hige(1)
	end
end

以上。

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?