3
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.

HSPでシダを描画する

Last updated at Posted at 2015-08-11

少し流行に乗り遅れた感がありますが,HSPでシダを描画したので載せます.

sida.png

元ネタ

「プログラムでシダを描画する」一覧

ソースコード

tytyさんによる「再帰モジュール」が別途必要です.
ダウンロードし,m_rec.hspファイルを同じディレクトリに配置してください.

Nの値を調節すると,いい具合の時間で終わります.

sida.hsp

#include "hsp3dish.as"
#include "m_rec.hsp"

rec_init 100000

#module

#defcfunc W1x double px, double py
return 0.836 * px + 0.044 * py

#defcfunc W1y double px, double py
return -0.044 * px + 0.836 * py + 0.169

#defcfunc W2x double px, double py
return -0.141 * px + 0.302 * py

#defcfunc W2y double px, double py
return 0.302 * px + 0.141 * py + 0.127

#defcfunc W3x double px, double py
return 0.141 * px - 0.302 * py

#defcfunc W3y double px, double py
return 0.302 * px + 0.141 * py + 0.169

#defcfunc W4x double px, double py
return 0.0

#defcfunc W4y double px, double py
return 0.175337 * py

#global

#const N 20

	screen 0, 640, 480

*main

	// 画面の書き換えを止める
	redraw 0

	color 255, 255, 255
	boxf
	
	pos 10, 10
	color 0, 0, 0
	mes "Drawing..."
	
	k = N
	x = 0.0
	y = 0.0

	rec_begin k, x, y
	
		if (0 < k) {
			rec_call k-1, W1x(x, y), W1y(x, y)
			
			if (rnd(3) == 0) :rec_call k-1, W2x(x, y), W2y(x, y)
			if (rnd(3) == 0) :rec_call k-1, W3x(x, y), W3y(x, y)
			if (rnd(3) == 0) :rec_call k-1, W4x(x, y), W4y(x, y)
		} else {
			color 0, 255, 0
			dx = int(x*ginfo_winx) + ginfo_winx/2
			dy = ginfo_winy - int(y*ginfo_winy)
			boxf dx, dy, dx+1, dy+1
		}
	rec_end

	color 255, 255, 255
	boxf 0, 0, 100, 100
	pos 10, 10
	color 0, 0, 0: mes "Finished"

	// 画面の書き換えを反映
	redraw 1

3
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
3
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?