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 その111

Posted at

概要

windows11に、sketchup6を入れてみた。
rubyで、3Dを書く。
練習問題やってみた。

練習問題

タートルグラフィックスを実装せよ。

写真

image.png

サンプルコード


class Kame3
	def initialize
		model = Sketchup.active_model
		@entities = model.active_entities
		@ANGLE = 0
		@LX = 10
		@LY = 10
		@pen = 1
		run()
	end
	def fmod(a, b)
		x = (a / b).floor
		return a - b * x
	end
	def up()
		@pen = 0
	end
	def down()
		@pen = 1
	end
	def turn(a)
		@ANGLE = fmod(@ANGLE + a, 360.0)
	end
	def walk(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 run()
		walk(10)
		up()
		turn(-90)
		walk(10)
		down()
		turn(-90)
		walk(10)
		turn(-90)
		walk(10)
		up()
		walk(30)
		down()
		turn(30)
		walk(10)
		turn(30)
		walk(10)
		turn(30)
		walk(10)
		turn(30)
		walk(10)
		turn(30)
		walk(10)
		turn(30)
		walk(10)
		turn(30)
		walk(10)
		turn(30)
		walk(10)
		turn(30)
		walk(10)
		turn(30)
		walk(10)
		turn(30)
		walk(10)
		turn(30)
		walk(10)
	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?