メソッドのオーバーロード

クラスを使っていると、メソッド名が同じにもかかわらず、引数の数や引数の型が異なるメソッドがあります。これをメソッドのオーバーロードと言います。
例)

MessageBox.Show("hello world!");
MessageBox.Show("hello world!", "HelloDialog");

メソッドのオーバーロードは簡単です。また、引数の数が同じで、引数の型が異なるメソッドをオーバーロードすることもできます。
オーバーロード機能があることで、クラスを使う側も作る側も楽ができます。

using System;

namespace Sample {
	class Program {
		static void Main(string[] args){
			DateUtility du = new DateUtility ();
			// IsEndOfMonth(DateTime date)を呼び出す
			DateTime date = new DateTime(2011, 5, 30);
			bool eom1 = du.IsEndOfMonth (date);
			Console.WriteLine (eom1 == true ?
					"月末です" :
				"月末ではありません");
			// IsEndOfMonth(int year, int month, int day)を呼び出す
			bool eom2 = du.IsEndOfMonth(2011,2,28);
			Console.WriteLine (eom2 == true ?
				"月末です" :
				"月末ではありません");
			Console.ReadLine ();
		}
	}

	class DateUtility {
		public bool IsEndOfMonth(DateTime date){
			Console.WriteLine ("Call IsEndOfMonth(DateTime date)");
			return date.AddDays(1).Day == 1;
		}

		public bool IsEndOfMonth(int year, int month, int day){
			Console.WriteLine ("Call IsEndOfMonth(int year, int month, int day)");
			DateTime date = new DateTime (year, month, day);
			return IsEndOfMonth (date);

		}
	}
}

書籍を扱うクラス

規模が大きなプログラムを作るには、クラスの理解が必須。
とのことで、C#でのクラスを見てみましょう。

using System;

namespace ConsoleApplication1 {
	class Program {
		static void Main(string[] args){
			Book[] books = new Book[2];
			books[0] = new Book {
			title = "伊豆の踊り子",
			author = "川端康成",
			price = 380,
			publisher = "新潮社"
			};
			books [1] = new Book {
				title = "坊ちゃん",
				author = "夏目漱石",
				price = 378,
				publisher = "岩波書店"
			};
			foreach (Book book in books)
				Console.WriteLine ("{0} {1} {2} {3}",
					book.title, book.author,
					book.price, book.publisher);
			Console.ReadLine();
		}
	}

	class Book {
		public string title;
		public string author;
		public int price;
		public string publisher;
	}
}

アセンブラツール

よく使われる代表的なもの

1.MASA
Microsoft Macro Assemblerの略ともいわれ、当初は、Macro Assembler。MicrosoftのOS(DOSやWindows)上で実行するプログラムのために開発されたアセンブラです。

; hello.asm

	include ¥masm32¥include¥masm32rt.inc

	.code

start:

	print "Hello, Assembly Language!",13,10
	exit

end start

2.NASM
NASM(Netwide Assembler)はGNUのLGPLで公開されているフリーソフトウェアのアセンブラです。このアセンブラはIntel x86ファミリーをターゲットとしており、様々な形式で出力することができます。

; ha.asm
	bits 16
	org 0x100

	mov ah, 2 ;文字出力を指定
	mov dl,[msg]	;msgの先頭'H'
	int 21h
	mov dl,[msg+7] ; msgの8番目'a'
	int 21h
	mov ax,4C00h ;プログラム終了
	int 21h

msg db "Hello, assembler$"

3.GNU Assembler(GAS)
UNIX系の各種アーキテクチャ(x86, 680×0, SPARC, VAX)向けのアセンブラファミリーです。AT&T表記と呼ばれる構文を使っています。もともと、gcc(GNU C, C++コンパイラ)との親和性が高く、UNIX系OSでC/C++とリンクするアセンブリ言語プログラムを記述するためによく使われます。

# hello.S
.text
	.global _start

	_start:

	movl $len,%edx
	movl $msg,%ecx
	movl $1,%ebx
	movl $4,%eax
	int $0x80

	# exit

	movl $0, %ebx
	movl $1, %eax
	int $0x80

	.data

	msg:
		.ascii "Hello, world!¥n"
		len = . - msg

iOS位置情報 API

ポケモンGOやってますか?
ボールが直ぐなくなってしまいますが、なんとかならないでしょうか?

さて、ポケモンGoにも出てくる位置情報ですが、どんな仕組みが気になりませんか?
AppleのDeveloper向けのサイトで、”Location and Maps Programming Guide“があります。
数時間で読めると思いますので、是非ご参照ください。
その中で、
Core Location framework, which defines Objective-C interfaces for obtaining information about the user’s location and heading
Maps app(Map Kit framework)
と記述があり、Core LocationというFrameworkがあることがわかります。
Core Locationはこちら
bullseye_view_2x

スマホVR人気アプリ

昔、日テレで、「THE夜もヒッパレ」という番組をよく見ていました。
まだ、ネットに出会う前です。
三宅裕司、中山秀征、赤坂泰彦が司会進行。毎週、MAXが踊って、モト冬樹さんがボケてたのを覚えてます。
今振り返ると、無性に懐かしいものですが、あの頃はテレビがギラギラしてて面白かった。
download

すっかり嗜好も変わり、音楽を殆ど聞かなくなりましたが、人間、いつの時代もランキングをつけたがるという行為自体は変わりませんね。ここで、今回は本日時点でのスマホVR人気アプリランキングを発表したいと思います。じゃらじゃらじゃら〜、ど〜ん!

スマホVRゲーム人気ランキングトップ3

1位:VRミュージアム(iOS/Android)
出演キャラの女の子たちの日常生活とパンツが覗けるアプリ
download-1
“ひょんなことから幽体離脱してしまった あなたはとある場所に迷い込んでしまう。
そこは個性豊かな美少女たちが 暮らすアパート「古来館」だった!
幽体であるあなたは彼女たちの 生活を覗き見し放題!?
もちろん上からも下からも!?
男子諸君の欲望が生み出した 禁断のテクノロジーをご体感あれ!”

2位:ポケカノVR(Android)
熱い視線を彼女に送りまくれ!男子歓喜のシミューレーションゲーム
download-2
“※本アプリを体験するにはCardBoardが必要です。
☆☆TripleYStudio初のVRデモアプリ☆☆
【あなただけの触りたくなる彼女がここにいます!】
★ふたりだけの秘密の世界にご招待!
 あなたのアツイ眼差しで彼女をほっこりさせましょう”

3位:VR Zombie Hunter 3D(iOS/Android)
廃病院で無限に湧き出るゾンビを撃ちまくるVRゲーム
download-3
“Open your eyes. You are in sleep for a long time and you will find yourself inside in a abandoned hospital when you wake up. You need to kill all the zombies to survive. Or, you will be one of them. Let’s start the zombie hunt!
The application is totally free.”

如何ですか?テクノロジーは飛躍的に進化しましたが、なんてくだらないでしょう。

ちなみに、こちらは懐かしのファミコンソフト累計売上ランキングです。
1位:スーパーマリオブラザーズ
2位:スーパーマリオブラザーズ3
3位:ドラゴンクエストⅢ そして伝説へ…

VRのランキングも、格闘、RPG、野球などに変わっていくかもしれません。野球がVRで出来たらリアルですね。
私は、麻雀オンライン対戦をVRでやりたいですね。麻雀格闘倶楽部のVR版。
VRのゴーグルの位置情報によって、対戦相手である上家、対面、下家の目線が動けば、心理戦にもなって、絶対面白いでしょ。

PHPでカレンダーを作ろう

プログラミングの初歩とも言える、簡単なカレンダーを作ります。
ここでは、変数、配列、繰り返し文、if文などを使っています。
コードは以下の通り。

<?php
    class Print_calendar extends Today_Calendar {
        function space_cell($count){
            if ($count!=0){
                for($i=0;$i<$count;$i++){
                    print "<td></td>";
                }
            }
        }
    }
    class Today_Calendar {
        function today($day){
            if (date("Y/m/d")==date("Y/m/d",mktime(0,0,0, date("n"),$day,date(Y)))){
                return "<b>".$day."</b>";
            } else {
                return $day;
            }
        }
    }
    print "<h1>".date("F")."</h1>";
    print "today:".date("Y/m/d");
    print "<br>";
    $arrayweek=array("sun","mon","tue","wed","thu","fri","sat");
    print "<table border=1><tr>";
    foreach($arrayweek as $value){
        print "<th>".$value. "</th>";
    }
    print "</tr><tr>";
    for($i=0;$i<date("t");$i++){
        $week_number = date("w", mktime(0, 0, 0, date("n"), $i+1, date("Y")));
        if ($i==0){
            print "<tr>";
            Print_Calendar::space_cell($week_number);
        } elseif ($week_number == 0){
            print "<tr>";
        }
        print "<td>".($i+1)."</td>";
        if($i+1==date("t")){
            Print_Calendar::space_cell(6-$week_number);
            print "</tr>";
        }elseif ($week_number == 6){
            print "</tr>";
        }
    }
    print "</table>";
?>

さて、出来上がりです。以下のスクリーンショットのようになってるでしょうか?CSSがないと寂しいですが、そこはご愛嬌で。
a

サーバーの構築やHTMLなどは別途ご確認ください。

VR関連企業

本稿では、VR関連企業を紹介したい。

Oculus Rift
www.oculus
総評:B
oculus-rift-vr-headset-1200x698
・Facebook傘下
・Oculus Riftは$599、国内価格94,600円
・Xbox Oneコントローラー トラッキングカメラOculus Remote同梱
・画像解析度:有機EL 1080×1200 2枚
・リフレッシュレート90Hz
・視野角110度
・3Dヘッドホン一体型
・赤外線カメラ付属
・ハンドトラッキング:Oculus Touch
・メインマシン:Oculus Ready PC
・プラットフォーム:Oculus Store Steam
・求人情報:Career

PS VR
PS VR
総評:A-
%e3%83%80%e3%82%a6%e3%83%b3%e3%83%ad%e3%83%bc%e3%83%89
・44,980円
・イヤホン同梱
・画像解析度:有機EL 1920×RGB×1080
・リフレッシュレート:120Hz, 90Hz
・視野角100度
・ポジショントラッキング:PlayStation Camera
・ハンドトラッキング:PS Move コントローラー
・メインマシン:PlayStation 4
・プラットフォーム:PS Store

HTC Vive
HTC Vive
総評:C+
14-vive-parts-edit-developed-fixed2_w_600
・111,999円
・Steam VRコントローラー、ベースステーション同梱
・画像解析度:有機EL 1080×1200 2枚
・リフレッシュレート:90Hz
・視野角:110度
・イヤホンのみ
・ポジショントラッキング:Lighthouse付属 最大、対角線5mまで
・ハンドトラッキング:SteamVR コントローラー
・メインマシン:SteamVR Ready PC
・プラットフォーム:Steam

お手頃感では、PS VRが一歩リードか。

VRとはなにか

話題のVR(Virtual Reality)とAR(Augmented Reality)。その違いや特徴について書きたい。

VRとは
VRとは、仮想現実の事を言います。CGなどを使って、実際には存在しない空間を作り出す技術で、ユーザーは、まるで本物の世界のように行動、体験することができます。

VRの特徴

  • 映像、音響による3次元空間への没入間
  • ユーザの動作に応じた対話性
  • HMD(Head Mount Display)などゴーグル型のデバイス、ヘッドフォン、スピーカー
  • 人工的な空間に、現実の光景・音声をコンピュータに取り込む
  • 傾視など健康リスクが伴う
  • 以下、wikipediaの引用です。
    /*
    Virtual reality (VR) typically refers to computer technologies that use software to generate realistic images, sounds and other sensations that replicate a real environment (or create an imaginary setting), and simulate a user’s physical presence in this environment, by enabling the user to interact with this space and any objects depicted therein using specialized display screens or projectors and other devices. VR has been defined as “…a realistic and immersive simulation of a three-dimensional environment, created using interactive software and hardware, and experienced or controlled by movement of the body” or as an “immersive, interactive experience generated by a computer”
    */

    Virtural Realityが期待される分野
    VRの市場は2020年までに218億円と言われています。ゲーム市場が先行していますが、以下の分野が期待されています。

    1位 ポルノ
    2位 オンラインショッピング
    3位 セラピー
    4位 事件・事故の検証
    5位 スポーツ
    6位 映画・動画
    7位 旅行
    8位 軍事
    9位 手術(医療)
    10位 宇宙開発 Nasaで実験

    タートルグラフィックス

    <?php
        // タートルグラフィック用ライブラリ
        
        // キャンバス(GD)の初期化
        function initCanvas($w, $h){
            global $img, $black;
            global $angle, $nx, $ny, $pen_color;
            // GD イメージの初期化
            $img = imagecreatetruecolor($w, $h);
            $black = rgb(0, 0, 0);
            imagefilledrectangle($img, 0, 0, $w, $h, rgb(255,255,255));
            imagerectangle($img, 0, 0, $w-1, $h-1, $black);
            // タートルのパラメーターを初期化
            $angle = $nx = $ny = 0;
            $pen_color = $black;
            return $img;
        }
        // GD用の色番号の取得
        function rgb($r, $g, $b){
            global $img;
            return imagecolorallocate($img, $r, $g, $b);
        }
        
        // 位置の移動
        function move($x, $y){
            global $nx, $ny;
            $nx = $x; $ny = $y;
        }
        // 進む
        function forward($dist, $isPenDown=true, $color=null){
            global $nx, $ny, $angle;
            global $img, $pen_color;
            $x = cos(deg2rad($angle)) * $dist;
            $y = sin(deg2rad($angle)) * $dist;
            $dx = $nx + $x;
            $dy = $ny + $y;
            if ($isPenDown){
                if ($color == null) $color = $pen_color;
                imageline($img, $nx, $ny, $dx, $dy, $color);
            }
            $nx = $dx;
            $ny = $dy;
        }
        // 向きを変える
        function turn($d, $absolute = FALSE){
            global $angle;
            if ($absolute){
                $angle = $d; return;
            }
            $angle = ($angle + $d) % 360;
            if ($angle < 0) $angle += 360;
        }
        function drawCanvas($w, $h, $file, $callback){
            $img = initCanvas($w, $h);
            $callbck($w, $h);
            imagepng($img, $file);
            echo "<img src='$file'>";
        }
        // ペンの色を変更する
        function setPenColor($color){
            global $pen_color;
            $pen_color = $color;
        }
        function forward_red($dist){
            forward($dist, true, rgb(255,0,0));
        }
    

    パイチャート

    円グラフを描画し、ブラウザーで確認

    <?php
        require_once 'vendor/davefx/phplot/phplot.php';
    
    // サンプルデータ定義
    $data = &#91;
        &#91;'ビール', 30&#93;,
        &#91;'ワイン', 20&#93;,
        &#91;'日本酒', 15&#93;,
        &#91;'焼酎', 8&#93;,
        &#91;'マッコリ', 4&#93;,
        &#93;;
    // 凡例はラベルの一次元配列なのでデータから生成する
        $legend = &#91;&#93;;
        foreach($data as $d){
            $legend&#91;&#93; = $d&#91;0&#93;;
        }
    
    // PHPlotのオブジェクトを生成
        $plot = new PHPlot(400,400);
        $plot->SetTTFPath(dirname(__FILE__).'/font');
        $plot->SetDefaultTTFont('ipagp.ttf');
    
    // グラフの種類を指定
        $plot->SetPlotType('pie');
        $plot->SetDataType('text-data-single');
        $plot->SetShading(0);
        $plot->SetImageBorderType('plain);
    
    // データを指定して描画
                                  $plot->SetDataValues($data);
                                  $plot->SetLegend($legend);
                                  $plot->DrawGraph();