Skip to content

DTL.Shape.RandomRect (形状クラス)

sitRyo edited this page Jan 15, 2020 · 3 revisions

バージョン 0.1.0以降

namespace DTL.Shape {
    public class RandomRect
}

概要

RandomRectとは "Matrixの描画範囲にランダムで描画値を配置する" 機能を持つクラスである。

インターフェース

IDrawer<int>

コンストラクタ

// (1)
RandomRect()
// (2)
RandomRect(int drawValue)
// (3)
Random(int drawValue, double probabilityValue)
// (4)
RandomRect(DTL.Base.Coordinate2DimensionalAndLength2Dimensional matrixRange)
// (5)
RandomRect(DTL.Base.Coordinate2DimensionalAndLength2Dimensional matrixRange, int drawValue)
// (6)
RandomRect(DTL.Base.Coordinate2DimensionalAndLength2Dimensional matrixRange, int drawValue, double probabilityValue)
// (7)
RandomRect(uint endX, uint endY, uint width, uint height)
// (8)
RandomRect(uint endX, uint endY, uint width, uint height, int drawValue)
// (9)
RandomRect(uint endX, uint endY, uint width, uint height, int drawValue, double probabilityValue)
説明
(1) 空のRandomRectのインスタンスを生成する。
(2) 描画値を指定したRandomRectのインスタンスを生成する。
(3) 描画値と描画値を生成する確率を指定したRandomRectのインスタンスを生成する。
(4), (7) 描画範囲を指定したRandomRectのインスタンスを生成する。
(5), (8) 描画範囲と描画値を指定したRandomRectのインスタンスを生成する。
(6), (9) 描画範囲と描画値, 描画値を生成する確率を指定したRandomRectのインスタンスを生成する。

プロパティ

Name Accessibility Descriptions Version
uint startX public get, protected set 描画の開始点X v0.1.0
uint startY public get, protected set 描画の開始点Y v0.1.0
uint width public get, protected set 描画横幅W v0.1.0
uint height public get, protected set 描画縦幅H v0.1.0
int drawValue public get, protected set 描画値 v0.1.0

メソッド

描画範囲取得/描画値取得

Name Descriptions Version
Create(int[,], Func<int, bool>) 関数がtrueを返す場合にMatrixに描画値を描画してMatrixを返す v0.1.0

インターフェースの実装

Name Descriptions Version
Draw(int[,]) Matrixに描画する v0.1.0
Create(int[,]) Matrixに描画してMatrixを返す v0.1.0

Examples (C#)

using DTL.Console;
using UnityEngine;
using DTL.Shape;

public class GenerateRandomRect : MonoBehaviour {
    public int width = 16;
    public int height = 20;
    public double probability = 0.5;
    public int drawValue = 1;

	void Start () {
        var matrix = new int[height, width];
        RandomRect randomRect = new RandomRect(drawValue, probability);
        randomRect.Draw(matrix);

        new OutputConsole().Draw(matrix);
        new OutputConsole(x => x < 1, "//", "##").Draw(matrix);
    }
}

Output

RandomRect1

RandomRect2

Clone this wiki locally