prime number in triangle

πで綺麗に絵を書いているのを見て、素数をちょっと使ってみようと、ちょっとばかし時間があったからやってみた。ウラムの螺旋とかサックスの螺旋とか以外にも色々あるけど、ここでは三角形の配列を使ってみる。

line:1                 1
line:2               2  3
line:3            4   5   6
line:4       7    8    9   10
line:5   11 12 13 14 15
………

こんな感じの3角形の配列を用意して、素数の所だけ塗りつぶす。このノリはウラムの螺旋とかと一緒ね。

line:1                   1
line:2                2   3
line:3            4    5   6
line:4         7    8   9   10
line:5     11 12 13 14 15
………

こんな感じで素数の所だけ塗りつぶしていく。他はグレーにしているけど、素数じゃない所は何も塗りつぶさない。あとline:1は1だから無しで。そんでプログラム的な流れは、一番左の1,2,4,7,11,16…は (n*n -n +2)/2だから、行番号(n)を上げていってその横幅(行数と同じ個数)にある素数を特定したら、その箇所を塗りつぶす、って感じで。

結果はこんな感じ。oFでサクッと描いた。

primenumber

生成される時の動画はこんな感じ。

あんまり規則性が見えなかったかも…スケールを変えると微妙に縦や斜めに線が見え始めるけど、うーん…って感じ。微妙に濃淡があるけど、これはキャプチャの限界で、スケールを変えるとちゃんと全部同じ濃さ&サイズになる。色をつけてみたら何か感触かわるかなぁ。まぁ、けど、何か面白かった。

一応環境としては、メインマシンのMacbook Air 11-ich, Mid 2011, Core i5 1.6GHz, Mem : 4Gbyte, OS X 10.8.5, openFrameworks 8.1を使って、22,685個の素数をポイントしている。

RabbitMQ with AMQP PHP

RabbitMQ AMQP-PHP library build on Ubuntu 13.10 memo.

# environment
# cat /etc/lsb-release
# DISTRIB_ID=Ubuntu
# DISTRIB_RELEASE=13.10
# DISTRIB_CODENAME=saucy
# DISTRIB_DESCRIPTION=”Ubuntu 13.10″

# build rabbitmq-c
git clone https://github.com/alanxz/rabbitmq-c.git
cd rabbitmq-c/
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/rabbitmq-c/ ..
cmake –build .
make install

# build AMQP PHP
wget http://pecl.php.net/get/amqp-1.4.0.tgz
tar -zxvf amqp-1.4.0.tgz
cd amqp-1.4.0/
phpize
./configure –with-librabbitmq-dir=/usr/local/rabbitmq-c –with-amqp

# modify Makefile
AMQP_SHARED_LIBADD = -Wl,-rpath,/usr/local/rabbitmq-c/lib -L/usr/local/rabbitmq-c/lib -lrabbitmq /usr/local/rabbitmq-c/lib/x86_64-linux-gnu/
to
AMQP_SHARED_LIBADD = -Wl,-rpath,/usr/local/rabbitmq-c/lib -L/usr/local/rabbitmq-c/lib -lrabbitmq -L/usr/local/rabbitmq-c/lib/x86_64-linux-gnu/

make
make install
cat <<EOF > /etc/ld.so.conf.d/rabbitmq-c.conf
/usr/local/rabbitmq-c/lib/x86_64-linux-gnu/
EOF
ldconfig

# add apache, php.ini
cat <<EOF > /etc/php5/mods-available/amqp.ini
extension=amqp.so
EOF
ln -s /etc/php5/mods-available/amqp.ini /etc/php5/apache2/conf.d/20-amqp.ini
service apache2 restart

sender.php

<?php
$cnn = new AMQPConnection();
$cnn->connect();
$ch = new AMQPChannel($cnn);

// Declare a new exchange
$ex = new AMQPExchange($ch);
$ex->setName('exchange-test');
$ex->setType(AMQP_EX_TYPE_FANOUT);
$ex->declareExchange();

// Create a new queue
$q = new AMQPQueue($ch);
$q->setName('queue-test');
$q->setFlags(AMQP_NOPARAM);
$q->declareQueue();
$q->bind($ex->getName());

for ($i = 0; $i < 10000; $i++) {
    $data = array('id' => $i, 'time' => time());
    $ex->publish(serialize($data));
}
$cnn->disconnect();

?>

reciever.php

<?php

ini_set('amqp.auto_ack', false);

$cnn = new AMQPConnection();
$cnn->connect();
$ch = new AMQPChannel($cnn);
$ch->setPrefetchCount(1);

// Declare a new exchange
$ex = new AMQPExchange($ch);
$ex->setName('exchange-test');
$ex->setType(AMQP_EX_TYPE_FANOUT);
$ex->declareExchange();

// Create a new queue
$q = new AMQPQueue($ch);
$q->setName('queue-test');
$q->setFlags(AMQP_NOPARAM);
$q->declareQueue();
$q->bind($ex->getName());

$q->consume(
    function (AMQPEnvelope $msg, AMQPQueue $queue) use ($ex) {
        echo $msg->getBody(), PHP_EOL;
        return $queue->ack($msg->getDeliveryTag());
});
?>

rabbitmqctl list_queues
Listing queues …
queue-test 10764
…done.

Creative Senze3D – Intel Interactive Gesture Camera Teardown

Intel RealSense SDK camera – Creative Senze3D Gesture Camera Teardown, and compare to DepthSense DS325.

1. open the attachment, take the screw.
IMG_2548

IMG_2549

2. open the rubber stopper, take the screws.
IMG_2550

3. open the back cover.
IMG_2551

IMG_2552

4. Unscrew the hexagon bolt, open the 1st board. This board is printed “SOFTKINETIC KOREA DS325V2_M”.

IMG_2553

5. Take the screws and hexagon bolt from next board.
IMG_2556

IMG_2557

6. DepthSense DS325 and Creative Senze3D.

IMG_2558

IMG_2559

both boards is printed “SOFTKINETIC KOREA DS325V2_M”.

Creative Senze3D all parts.

IMG_2561

openFrameworks 8.1 and OpenNI 2.2 on Android tutorial

This tutorial is “How to use oF 8.1 with OpenNI 2.2 on Android”, using Xtion. If want to use Kinect, use OpenNI 1.x and Sensor Kinect driver. And my build envrionment, I use Mac OS 10.8.5, Android 4.2.2 (device is MK 802 IV HDMI dongle type Android, root user needed) on this tutorial. May be other Android devices OpenNI 2.2 works well(OpenNI ran on Nexus7 in my test).

1. Built OpenNI 2.2
# Download Android NDK
cd $HOME
mkdir work
cd work
wget http://dl.google.com/android/ndk/android-ndk-r8e-darwin-x86_64.tar.bz2
tar -jxvf android-ndk-r8e-darwin-x86_64.tar.bz2

# Download OpenNI 2.2 from git
cd $HOME/work
git clone https://github.com/OpenNI/OpenNI2.git
cd OpenNI2
# change PS1080.ini file path
vi ./Source/Drivers/PS1080/Sensor/XnSensor.cpp
#define XN_GLOBAL_CONFIG_FILE_NAME “PS1080.ini”
to
#define XN_GLOBAL_CONFIG_FILE_NAME “/system/lib/PS1080.ini”

# change OpenNI.ini file path
vi ./Source/Core/OniContext.cpp
static const char* ONI_CONFIGURATION_FILE = “OpenNI.ini”;
to
static const char* ONI_CONFIGURATION_FILE = “/system/lib/OpenNI.ini”;

static const char* ONI_DEFAULT_DRIVERS_REPOSITORY = “OpenNI2” XN_FILE_DIR_SEP “Drivers”;
to
static const char* ONI_DEFAULT_DRIVERS_REPOSITORY = “/system/lib/”;

# build OpenNI 2.2
cd Packaging
python ReleaseVersion.py android
cd Final
tar -xvf OpenNI-android-2.2.tar
cd OpenNI-android-2.2
ls
EventBasedRead OpenNI.ini SimpleRead libOpenNI2.so libPSLink.so
MultipleStreamRead PS1080.ini libOniFile.so libPS1080.so libusb.so

# copy shard library and ini file to Android
adb push OpenNI.ini /system/lib/
adb push PS1080.ini /system/lib/
adb push libOpenNI2.so /system/lib/
adb push libPS1080.so /system/lib/
adb push libusb.so /system/lib/
adb push libOniFile.so /system/lib/
adb push libPSLink.so /system/lib/
adb push SimpleRead /system/lib/

# check OpenNI running.
adb shell
cd /system/lib/
SimpleRead
./SimpleRead
[00000000] 585
[00033369] 585
[00066738] 584
[00100107] 584
[00133477] 584
[00166846] 584
[00200215] 584
[00233584] 583
[00266954] 583
……

2. oepnFrameworks 8.1 for Android
Download openFrameworks 8.1 for Android from official site, of course Android SDK, Eclipse, JDK is needed. openFrameworks for Android tutorials is here.

# download Android NDK
cd $HOME/work
wget http://dl.google.com/android/ndk/android-ndk-r9d-darwin-x86_64.tar.bz2
tar -jxvf android-ndk-r8d-darwin-x86_64.tar.bz2

# set paths.make. following is my example.
vi libs/openFrameworksCompiled/project/android/paths.make
SDK_ROOT=$HOME/work/android-sdk-macosx
NDK_ROOT=$HOME/work/android-sdk-macosx/android-ndk-r9d

# set OpenNI include files, shard library file oF make file.
“libs/openFrameworksCompiled/project/android/config.android.default.mk” changes diff is following.

36c36
< ABIS_TO_COMPILE_RELEASE = armv5 armv7 neon — > ABIS_TO_COMPILE_RELEASE = armv5 armv7 neon x86
193c193
< PLATFORM_LDFLAGS += –sysroot=$(SYSROOT) -nostdlib -L”$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/$(GCC_VERSION)/libs/$(ABI_PATH)” -L$HOME/work/OpenNI2/Packaging/Final/OpenNI-android-2.2 — > PLATFORM_LDFLAGS += –sysroot=$(SYSROOT) -nostdlib -L”$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/$(GCC_VERSION)/libs/$(ABI_PATH)”
311d310
< PLATFORM_HEADER_SEARCH_PATHS += “$HOME/work/OpenNI2/Include”
343,345d341
< PLATFORM_LIBRARIES += OpenNI2
< PLATFORM_LIBRARIES += OniFile
< PLATFORM_LIBRARIES += PS1080

3. Sample android application
Eclipse project androidOpenNIExample.tar.gz.
APK androidOpenNIExample.apk

MK 802 IV is HDMI dongle type android device(just like a Chromecast by google), easy to use with LED TV. About 60,000 point cloud is drawing in 30fps in this application.