<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ひろぽっぽれす &#187; Java</title>
	<atom:link href="http://hiropo.co.uk/archives/category/java/feed" rel="self" type="application/rss+xml" />
	<link>http://hiropo.co.uk</link>
	<description>Web系エンジニアの適当なブログです。どうでも酔いものばかり作ってます。</description>
	<lastBuildDate>Mon, 12 Mar 2012 06:10:01 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Processing.js 8&#215;8 ドットマトリックスLEDっぽいのつくってみた canvas</title>
		<link>http://hiropo.co.uk/archives/882</link>
		<comments>http://hiropo.co.uk/archives/882#comments</comments>
		<pubDate>Mon, 06 Feb 2012 05:07:52 +0000</pubDate>
		<dc:creator>hirohi</dc:creator>
				<category><![CDATA[canvas]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Processing]]></category>

		<guid isPermaLink="false">http://hiropo.co.uk/?p=882</guid>
		<description><![CDATA[canvasで使うライブラリはすっかりProcessing.jsに馴染んでしまった僕です、こんにちは。 Arduinoを使った8&#215;8ドットマトリックスLEDの点滅をやりたいなと思い、そのシミュレーションとしてj &#8230; <a href="http://hiropo.co.uk/archives/882">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>canvasで使うライブラリはすっかりProcessing.jsに馴染んでしまった僕です、こんにちは。</p>
<p>Arduinoを使った8&#215;8ドットマトリックスLEDの点滅をやりたいなと思い、そのシミュレーションとしてjsdoitでまずはcanvasに描画してみようと思いたちProcessing.jsで書いてみました。</p>
<p><script type="application/processing">
int[][] p = {
  {0,0,1,0,0,0,0,0},
  {0,1,1,1,1,1,0,0},
  {0,0,1,0,0,0,0,0},
  {0,0,1,1,1,1,0,0},
  {0,1,1,0,1,0,1,0},
  {1,0,1,1,0,0,1,0},
  {0,1,1,0,0,1,0,0},
  {0,0,0,0,0,0,0,0}
};
void setup(){
  size(81, 81);
  frameRate(30);
}
void draw(){
  background(0);
  stroke(0);
  for(int y = 0; y < p.length; y++){
  for(int x = 0; x < p[y].length; x++){
    if(p[y][x] == 0){
      fill(96, 96, 96);
    }
    else if(p[y][x] == 1){
      fill(255, 0, 0);
    }
    ellipseMode(CORNER);
    ellipse(x*10, y*10, 10, 10);
  }}
}
</script></p>
<pre>
int[][] p = {
  {0,0,1,0,0,0,0,0},
  {0,1,1,1,1,1,0,0},
  {0,0,1,0,0,0,0,0},
  {0,0,1,1,1,1,0,0},
  {0,1,1,0,1,0,1,0},
  {1,0,1,1,0,0,1,0},
  {0,1,1,0,0,1,0,0},
  {0,0,0,0,0,0,0,0}
};
void setup(){
  size(81, 81);
  frameRate(30);
}
void draw(){
  background(0);
  stroke(0);
  for(int y = 0; y < p.length; y++){
  for(int x = 0; x < p[y].length; x++){
    if(p[y][x] == 0){
      fill(96, 96, 96);
    }
    else if(p[y][x] == 1){
      fill(255, 0, 0);
    }
    ellipseMode(CORNER);
    ellipse(x*10, y*10, 10, 10);
  }}
}
</pre>
<p>jsdoitにも投稿してあります。<br />
<a href="http://jsdo.it/funnythingz/uhNO" target="_blank">Processing.js 8x8 ドットマトリックスLEDっぽいのつくってみた</a><br />
<script type="text/javascript" src="http://jsdo.it/blogparts/uhNO/js?view=design"></script>
<p class="ttlBpJsdoit" style="width: 465px; margin: 0; text-align: right; font-size: 11px;"><a href="http://jsdo.it/funnythingz/uhNO" title="Processing.js 8x8 ドットマトリックスLEDっぽいのつくってみた">Processing.js 8x8 ドットマトリックスLEDっぽいのつくってみた - jsdo.it - share JavaScript, HTML5 and CSS</a></p>
<p>描画するだけだったら簡単だけど、x軸に対して1ドットずつ横に流してアニメーションさせたいなーと。<br />
アニメーションできたらまたうｐしますん。</p>
]]></content:encoded>
			<wfw:commentRss>http://hiropo.co.uk/archives/882/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wordpressにProcessingを埋め込むプラグインを導入してみた</title>
		<link>http://hiropo.co.uk/archives/557</link>
		<comments>http://hiropo.co.uk/archives/557#comments</comments>
		<pubDate>Tue, 02 Nov 2010 02:36:34 +0000</pubDate>
		<dc:creator>hirohi</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Processing]]></category>

		<guid isPermaLink="false">http://hiropo.co.uk/?p=557</guid>
		<description><![CDATA[最近インタラクティブ・メディアアートという言葉が流行ってますね。流行り物大好きです！ その流行り物のベースとなっている言語であるProcessingを埋め込むためのプラグインをつっこんでみました。 Processingと &#8230; <a href="http://hiropo.co.uk/archives/557">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>最近インタラクティブ・メディアアートという言葉が流行ってますね。流行り物大好きです！<br />
その流行り物のベースとなっている言語であるProcessingを埋め込むためのプラグインをつっこんでみました。</p>
<p>Processingとは、Javaを単純化し、グラフィック機能に特化した言語です。(Wikipedia 談)<br />
Javaというとオブジェクト指向でとても難しい言語だというイメージがあるかもですが、Processingはかなり単純化されているので、<br />
オブジェクト指向を気にしなくても気軽にJavaでメディアアートができます。</p>
<blockquote>
<ul>
<li>Processing本家（英語）<br />
<a href="http://processing.org/" target="_blank">http://processing.org/</a>
</li>
<li>Processing.js JavaScript Framework<br />
<a href="http://processingjs.org/" target="_blank">http://processingjs.org/</a>
</li>
</ul>
</blockquote>
<p>もちろん、インタラクティブにゴリッゴリの凄いやつをつくろう！ってなるとクラスを定義したりなどオブジェクト指向が必要になりますが、それでもネイティブなJavaよりProcessingは簡単にそれを実現できます。</p>
<p>最近はHTML5でゴリッゴリに動くメディアアートなどもありますが、jQueryの開発者でもある、ジョンがProcessing.js というJavaScriptでProcessingを描けるステキライブラリを開発してくれたので、Processingを覚えちゃえば誰でも割と簡単にインタラクティブ・メディアアートができます。まさに夢の言語です！</p>
<p>Processingの実際の書き方などはここでは割愛しちゃいますが、<br />
とりあえず、このブログにてProcessingでつくられた作品を公開できるようにしてみました。</p>
<p>ProcessingはJavaベースなので、書き出す際には、Javaアプレットとして書き出します。<br />
そして、書き出したjarファイルを下記の場所におきます。</p>
<blockquote><p>
例：threeballsclass.jar の場合<br />
/wp-content/plugins/wp-proc-embed/threeballsclass/applet/threeballsclass.jar
</p></blockquote>
<p>次に記事投稿画面で、HTMLモードで下記のように記述します。</p>
<blockquote><p>
processing=threeballsclass 200 200<br />
※実際は &#8220;[]&#8221; で囲ってください。
</p></blockquote>
<p>これで埋め込みができるはずです。</p>
<p>下記が実際にProcessingで組まれた作品です。<br />
<div id="processing">
                           <!--[if !IE]> -->
                                <object classid="java:threeballsclass.class" 
                                type="application/x-java-applet"
                                archive="/wp-content/plugins/wp-proc-embed/threeballsclass/applet/threeballsclass.jar"
                                width="200" height="200"
                                standby="Loading Processing software..." >
                                        <param name="archive" value="/wp-content/plugins/wp-proc-embed/threeballsclass/applet/threeballsclass.jar" />
                                        <param name="mayscript" value="true" />
                                        <param name="scriptable" value="true" />
                                        <param name="image" value="loading.gif" />
                                        <param name="boxmessage" value="Loading Processing software..." />
                                        <param name="boxbgcolor" value="#FFFFFF" />
                                        <param name="test_string" value="outer" />
                        <!--<![endif]-->
                                
                                <object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" 
                                                codebase="http://java.sun.com/update/1.4.2/jinstall-1_4_2_12-windows-i586.cab"
                                                width="200" height="200"
                                                standby="Loading Processing software..."  >
                                        <param name="code" value="threeballsclass" />
                                        <param name="archive" value="/wp-content/plugins/wp-proc-embed/threeballsclass/applet/threeballsclass.jar" />
                                        <param name="mayscript" value="true" />
                                        <param name="scriptable" value="true" />
                                        <param name="image" value="loading.gif" />
                                        <param name="boxmessage" value="Loading Processing software..." />
                                        <param name="boxbgcolor" value="#FFFFFF" />
                                        <param name="test_string" value="inner" />
                                        <p>
                                                        This browser does not have a Java Plug-in.
                                                        <br />
                                                        <a href="http://java.sun.com/products/plugin/downloads/index.html" title="Download Java Plug-in">


	 
                                                                Get the latest Java Plug-in here.
                                                        </a>
                                        </p>
                                </object>
                        <!--[if !IE]> -->
                                </object>
                        <!--<![endif]-->
                        </div></p>
<p>実際のProcessing内でのソースはこちら</p>
<pre>
int dim = 200;
Ball ball1, ball2, ball3, ball4;

void setup(){
  size(dim,dim);
  noStroke();
  frameRate(30);
  smooth();
  ellipseMode(CENTER);
  ball1 = new Ball();
  ball2 = new Ball();
  ball3 = new Ball();
  ball4 = new Ball();
}

void draw(){
  background(255,255,255);
  ball1.move();
  ball2.move();
  ball3.move();
  ball4.move();

  ball1.display();
  ball2.display();
  ball3.display();
  ball4.display();
}

class Ball{
  int xvel;
  int yvel;
  int xpos;
  int ypos;
  int c1, c2, c3;

  Ball(){
    xpos = int(random(11,(dim-11)));
    ypos = int(random(11,(dim-11)));
    xvel = 3;
    yvel = 3;
  }

  void move(){
    xpos = xpos+xvel;
    ypos = ypos+yvel;

    if ( xpos < 10 || xpos > (dim-10) ){
      xvel = -1 * xvel;
      c1 = int(random(0,255));
      c2 = int(random(0,255));
      c3 = int(random(0,255));
    }

    if ( ypos < 10 || ypos > (dim-10) ){
      yvel = -1 * yvel;
      c1 = int(random(0,255));
      c2 = int(random(0,255));
      c3 = int(random(0,255));
    }
  }

  void display(){
    fill(c1,c2,c3);
    ellipse(xpos,ypos,20,20);
  }

}
</pre>
<p>こんな感じで興味があればぜひぜひどうぞー！</p>
<p>アプレット、たのしいよ、アプレット。</p>
]]></content:encoded>
			<wfw:commentRss>http://hiropo.co.uk/archives/557/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing でオブジェクト指向っぽくネズミさんを描いてみた</title>
		<link>http://hiropo.co.uk/archives/537</link>
		<comments>http://hiropo.co.uk/archives/537#comments</comments>
		<pubDate>Wed, 06 Oct 2010 10:17:02 +0000</pubDate>
		<dc:creator>hirohi</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Processing]]></category>

		<guid isPermaLink="false">http://hiropo.co.uk/?p=537</guid>
		<description><![CDATA[前回のブログ記事からまた時間が経ってしまいました。すっかりサボりぐせがついてしまってます。 前回はellipse() を使って図形を描いてみましたが、今回はもうちょっとオブジェクト指向っぽく描いてみました。 とりま、某有 &#8230; <a href="http://hiropo.co.uk/archives/537">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>前回の<a href="http://hiropo.co.uk/archives/521">ブログ記事</a>からまた時間が経ってしまいました。すっかりサボりぐせがついてしまってます。<br />
前回はellipse() を使って図形を描いてみましたが、今回はもうちょっとオブジェクト指向っぽく描いてみました。</p>
<p>とりま、某有名なネズミさんに似た形をellipse()使って描いてみました。<br />
<a href="http://hiropo.co.uk/wp-content/uploads/2010/10/mickey1.jpg"><img src="http://hiropo.co.uk/wp-content/uploads/2010/10/mickey1.jpg" alt="" title="mickey1" width="406" height="432" class="alignnone size-full wp-image-538" /></a></p>
<pre>
float positionX = 125;
float positionY = 125;

void setup(){
  size(400,400);
  background(255);
  smooth();
  noStroke();

  fill(0);
  ellipseMode(CORNER);
  ellipse( 0 + positionX, 0 + positionY, 50, 50 );
  ellipse( 100 + positionX, 0 + positionY, 50, 50 );
  ellipse( 25 + positionX, 25 + positionY, 100, 100 );
}
void draw(){
}
</pre>
<p>割とキレイに描けてるんじゃないかなとｗｗ<br />
ただ、毎回こいつを繰り返し処理させるのはいかがなものかと思うので、クラスオブジェクトにまとめてみました。</p>
<pre>
class Mouse{

  //プロパティ
  float x,y;  //positionX, positionY
  float face; //face
  int[] bg;

  //コンストラクタ
  Mouse( float xpos, float ypos, int[] cpos )
  {
    //set
    this.x = xpos;
    this.y = ypos;
    this.bg = cpos;

    //conf
    fill( this.bg[0], this.bg[1], this.bg[2] );
    ellipseMode(CORNER);

    //耳
    ellipse( 0 + this.x, 0 + this.y, 50, 50 );
    ellipse( 100 + this.x, 0 + this.y, 50, 50 );
    //顔
    ellipse( 25 + this.x, 25 + this.y, 100, 100 );
  }
}
</pre>
<p>実際にこのMouseクラスを使ってテキトーに並べてみました。<br />
<a href="http://hiropo.co.uk/wp-content/uploads/2010/10/mickey3.jpg"><img src="http://hiropo.co.uk/wp-content/uploads/2010/10/mickey3.jpg" alt="" title="mickey3" width="406" height="432" class="alignnone size-full wp-image-545" /></a></p>
<pre>
float positionX = 125;
float positionY = 125;

void setup(){
  size(400,400);
  background(255);
  smooth();
  noStroke();

  int[][] bg = {
    {255,191,194},
    {204,191,255},
    {191,250,255},
    {255,255,206},
    {228,238,191}
  };
  new Mouse( positionX, positionY, bg[0] );
  new Mouse( positionX*2, positionY*2, bg[1] );
  new Mouse( positionX*0, positionY*0, bg[2] );
  new Mouse( positionX*2, positionY*0, bg[3] );
  new Mouse( positionX*0, positionY*2, bg[4] );
}
void draw(){
}

class Mouse{

  //プロパティ
  float x,y;  //positionX, positionY
  float face; //face
  int[] bg;

  //コンストラクタ
  Mouse( float xpos, float ypos, int[] cpos )
  {
    //set
    this.x = xpos;
    this.y = ypos;
    this.bg = cpos;

    //conf
    fill( this.bg[0], this.bg[1], this.bg[2] );
    ellipseMode(CORNER);

    //耳
    ellipse( 0 + this.x, 0 + this.y, 50, 50 );
    ellipse( 100 + this.x, 0 + this.y, 50, 50 );
    //顔
    ellipse( 25 + this.x, 25 + this.y, 100, 100 );
  }
}
</pre>
<p>市松模様を描くクラスとかにさらにまとめれば市松模様描けちゃう！<br />
なんだか楽しくなってきた！</p>
<p>とりあえずここまで。</p>
]]></content:encoded>
			<wfw:commentRss>http://hiropo.co.uk/archives/537/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java始めました。</title>
		<link>http://hiropo.co.uk/archives/51</link>
		<comments>http://hiropo.co.uk/archives/51#comments</comments>
		<pubDate>Tue, 07 Oct 2008 07:30:14 +0000</pubDate>
		<dc:creator>hirohi</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://hiropo.co.uk/archives/51</guid>
		<description><![CDATA[クラスベースのオブジェクト指向を勉強したかったので、なんとなくJavaを始めました。 最初につくった &#8220;hello world&#8221; 的なもの。↓ class a { public static vo &#8230; <a href="http://hiropo.co.uk/archives/51">続きを読む <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>クラスベースのオブジェクト指向を勉強したかったので、なんとなくJavaを始めました。</p>
<p>最初につくった &#8220;hello world&#8221; 的なもの。↓</p>
<pre>
class a {
	public static void main(String[] args) {
		System.out.print("引数の数は¥"" + args.length + "¥"やね。" + "¥n" );
		for( int i = 0; i < args.length; i++ ) {
			System.out.print("引数[" + i + "]の値は¥"" + args[i] + "¥"やね。" + "¥n" );
		}
		if(args.length != 0) {
			System.out.print("¥n" + "せやな。引数あって良かったわな。" + "¥n");
		}else{
			System.out.print("¥n" + "引数ないとかありえへん。" + "¥n");
		}
	}
}
</pre>
<p>ぼちぼち頑張ってゆきまする。</p>
]]></content:encoded>
			<wfw:commentRss>http://hiropo.co.uk/archives/51/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

