0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

LibreOffice Calc VBAでasciiart

Posted at

手順

新しいLibreOffice Calcファイルを用意します。
名前はtest.odsとします。

Alt+F11キーでBasicマクロダイアログが現れます。
(ツール → マクロ → マクロの管理 → Basic)

マクロの記録先からtest.odsを選択し、新規作成ボタンをクリックすると新しいモジュールダイアログが現れます。
名前はModule1とします。

LibreOffice Basicウィンドウが現れるので以下のソースをコピペします。

' asciiart LibreOffice Calc VBA
Option VBASupport 1

Sub Main
	Range(Columns(1), Columns(80)).ColumnWidth = 1
	For r = 1 To 25
		For c = 1 To 79
			Cells(r, c).Value = mandel(c - 40, r - 13)
		Next
	Next
	Cells.Font.Name = "Courier New"
End Sub

Function mandel(x, y)
	ca = x * 0.0458
	cb = y * 0.08333
	a = ca
	b = cb
	s = " "
	For i = 0 To 15
		t = a * a - b * b + ca
		b = 2 * a * b + cb
		a = t
		If (a * a + b * b) > 4 Then
			s = Hex(i)
			Exit For
		End If
	Next
	mandel = s
End Function

Sub Mainにカーソルを移動し実行(F5キー)します。
vba.png
セルに以下の関数を入力して利用することもできます。

=mandel(cell("col") - 40, cell("row") - 13)
0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?