SlideShare una empresa de Scribd logo
1 de 29
#pragma once

#include "ofMain.h"
#include "ofxAccelerometer.h"
#include "ofxMultiTouch.h"
#define NUM 10

class testApp : public ofSimpleApp, public ofxMultiTouchListener {
	
public:
	
	 void setup();
	 void update();
	 void draw();
	 void exit();
	 	
	 ...(     )...
	
	 ofPoint pos[NUM];
};
#include "testApp.h"

void testApp::setup(){	
	   ofSetColor(0, 0, 255);
	   ofBackground(0, 0, 0);
	   ofSetBackgroundAuto(true);
	   ofSetFrameRate(60);
	   //
	   ofxMultiTouch.addListener(this);
	   //
	   for(int i=0; i<NUM; i++){
	   	     pos[i].x = -100;
	   	     pos[i].y = -100;
	   }
}

void testApp::update(){
}

void testApp::draw(){
	   for(int i=0; i<NUM; i++){
	   	     ofCircle(pos[i].x, pos[i].y, 40);
	   }
}
void testApp::exit() {
}

//
void testApp::mouseMoved(int x, int y){
}

void testApp::mouseDragged(int x, int y, int button){
	   printf("mouseDragged: %i, %i %in", x, y, button);
	   pos[0].x = x;
	   pos[0].y = y;
}

void testApp::mousePressed(int x, int y, int button){
	   printf("mousePressed: %i, %i %in", x, y, button);
	   pos[0].x = x;
	   pos[0].y = y;
}

void testApp::mouseReleased(){
}

void testApp::mouseReleased(int x, int y, int button){
	   printf("mouseReleased: %i, %i %in", x, y, button);
	   pos[0].x = -100;
pos[0].y = -100;
}
//
void testApp::touchDown(float x, float y, int touchId, ofxMultiTouchCustomData
*data){
	   printf("touchDown: %i, %i %in", x, y, touchId);
	   pos[touchId].x = x;
	   pos[touchId].y = y;
}
void testApp::touchMoved(float x, float y, int touchId, ofxMultiTouchCustomData
*data){
	   printf("touchMoved: %i, %i %in", x, y, touchId);
	   pos[touchId].x = x;
	   pos[touchId].y = y;
}
void testApp::touchUp(float x, float y, int touchId, ofxMultiTouchCustomData
*data){
	   printf("touchUp: %i, %i %in", x, y, touchId);
	   pos[touchId].x = -100;
	   pos[touchId].y = -100;
}
void testApp::touchDoubleTap(float x, float y, int touchId,
ofxMultiTouchCustomData *data){
}
#pragma once

#include "ofMain.h"
#include "ofxAccelerometer.h"
#include "ofxMultiTouch.h"

class testApp : public ofSimpleApp, public ofxMultiTouchListener {
	
public:
	
	 void setup();
	 void update();
	 void draw();
	 void exit();

	   ...(   )...


	 ofPoint accel;
};
#include "testApp.h"

void testApp::setup(){
	 ofBackground(0, 0, 0);
	 ofSetBackgroundAuto(true);
	 ofSetFrameRate(60);
	 //
	   ofxAccelerometer.setup();
}

void testApp::update(){
	 //x,y,z
	   accel.x = ofxAccelerometer.getForce().x;
	   accel.y = ofxAccelerometer.getForce().y;
	   accel.z = ofxAccelerometer.getForce().z;
	   //
	   printf("get force: %f, %f, %f n", accel.x, accel.y, accel.z);
}
void testApp::draw(){
	 //
	   float rectScale = 200.0;
	   ofSetColor(255, 0, 0);
	   ofRect(0, ofGetHeight()/2, ofGetWidth()/3,
	   	       accel.x * rectScale);
	   ofSetColor(0, 255, 0);
	   ofRect(ofGetWidth()/3, ofGetHeight()/2,
	   	       ofGetWidth()/3, accel.y * rectScale);
	   ofSetColor(0, 0, 255);
	   ofRect(ofGetWidth()/3*2, ofGetHeight()/2,
	   	       ofGetWidth()/3, accel.z * rectScale);
}

...(   )...
#pragma once

#include   "ofMain.h"
#include   "ofxAccelerometer.h"
#include   "ofxMultiTouch.h"
#include   "Spot.h"

class testApp : public ofSimpleApp, public ofxMultiTouchListener {
	
public:
	
	   void setup();
	   void update();
	   void draw();
	   void exit();
	
	   ...(   )...


private:
	   Spot** sp; //Spot             sp               (**)
	    int numSpot; //       Spot
};
#include "testApp.h"
#include "Spot.h"

#define NUM_POINT 5

void testApp::setup(){	
	   ofBackground(0, 0, 0);
	   ofSetBackgroundAuto(true);
	   ofSetFrameRate(60);
	   //                         //
	   ofEnableAlphaBlending();
	   //
	   ofSetBackgroundAuto(false);
	   //
	   ofxAccelerometer.setup();
	   //
	   ofxMultiTouch.addListener(this);
	   //
	   numSpot = 400;
	   //
	   sp = new Spot*[numSpot];
	   for(int i = 0; i < numSpot; i++){
	   	     ofPoint _pos, _velocity;
	   	     _pos.x = ofRandom(0, ofGetWidth());
	   	     _pos.y = ofRandom(0, ofGetHeight());
_velocity.x = 0;
	   	     _velocity.y = 0;
	   	     float _diameter = ofRandom(1, 10);
	   	     //                  	
	   	     sp[i] = new Spot(_pos, _velocity, _diameter);
	   	     //
	   	     sp[i]->gravity = 0.05;
	   	     //
	   	     sp[i]->friction = 0.99;
	   }
}

void testApp::update(){
	   ofSetColor(0, 0, 0, 31);
	   ofRect(0, 0, ofGetWidth(), ofGetHeight());
	   for(int i = 0; i < numSpot; i++){
	   	     sp[i]->update();
	   }
}

void testApp::draw(){
	   for(int i = 0; i < numSpot; i++){
	   	     sp[i]->display();
	   }
}
void testApp::exit() {
}

void testApp::mouseMoved(int x, int y){
}

void testApp::mouseDragged(int x, int y, int button){
	   for(int i=0; i<numSpot; i++){
	   	     if(i % NUM_POINT == 0){
	   	     	    sp[i]->touched = true;
	   	     	    sp[i]->moveTo(x, y);
	   	     }
	   }
}

void testApp::mousePressed(int x, int y, int button){
	   for(int i=0; i<numSpot; i++){
	   	     if(i % NUM_POINT == 0){
	   	     	    sp[i]->touched = true;
	   	     	    sp[i]->moveTo(x, y);
	   	     }
	   }
}

void testApp::mouseReleased(){
}
void testApp::mouseReleased(int x, int y, int button){
	   for(int i=0; i<numSpot; i++){
	   	     if(i % NUM_POINT == 0){
	   	     	    sp[i]->touched = false;
	   	     }
	   }
}

void testApp::touchDown(float x, float y, int touchId, ofxMultiTouchCustomData *data){
	   for(int i=0; i<numSpot; i++){
	   	     if(i % NUM_POINT == touchId){
	   	     	    sp[i]->touched = true;
	   	     	    sp[i]->moveTo(x, y);
	   	     }
	   }
}

void testApp::touchMoved(float x, float y, int touchId, ofxMultiTouchCustomData *data)
{
	   for(int i=0; i<numSpot; i++){
	   	     if(i % NUM_POINT == touchId){
	   	     	    sp[i]->touched = true;
	   	     	    sp[i]->moveTo(x, y);	
	   	     }
	   }
}
void testApp::touchUp(float x, float y, int touchId, ofxMultiTouchCustomData *data){
	   for(int i=0; i<numSpot; i++){
	   	     if(i % NUM_POINT == touchId){
	   	     	    sp[i]->touched = false;
	   	     }
	   }
}
#ifndef _OF_SPOT
#define _OF_SPOT

#include "ofMain.h"
#include "ofxMultiTouch.h"
#include "ofxAccelerometer.h"

class Spot {
public:
	   Spot(ofPoint pos, ofPoint velocity, float diameter);
	   void update();
	   void display();
	   void moveTo(float x, float y);
	   ofPoint pos;
	   ofPoint velocity;
	   float diameter;
	   float gravity;
	   float friction;
	   bool touched;
};

#endif
#include "Spot.h"

Spot::Spot(ofPoint _pos, ofPoint _velocity, float _diameter)
{
	   pos = _pos;
	   velocity = _velocity;
	   diameter = _diameter;
	   touched = false;
}

void Spot::update()
{
	   if(!touched){
	   	     velocity *= friction;
	   	     velocity.x += gravity * ofxAccelerometer.getForce().x;
	   	     velocity.y -= gravity * ofxAccelerometer.getForce().y;
	   	     pos.x += velocity.x * diameter;
	   	     pos.y += velocity.y * diameter;
	   	     if(pos.x < diameter){
	   	     	    velocity.x *= -1;
	   	     	    pos.x = diameter;
	   	     }
	   	     if(pos.x > ofGetWidth() - diameter){
	   	     	    velocity.x *= -1;
	   	     	    pos.x = ofGetWidth() - diameter;
	   	     }
if(pos.y < diameter){
	   	     	    velocity.y *= -1;
	   	     	    pos.y = diameter;
	   	     }
	   	     if(pos.y > ofGetHeight()-diameter){
	   	     	    velocity.y *= -1;
	   	     	    pos.y = ofGetHeight()-diameter;
	   	     }	
	   }
}

void Spot::display()
{
	   ofSetColor(0, 127, 255, 200);
	   ofCircle(pos.x, pos.y, diameter);
}

void Spot::moveTo(float x, float y)
{
	   pos.x = x;
	   pos.y = y;
	   velocity.x = ofRandom(-1, 1);
	   velocity.y = ofRandom(-1, 1);
}
Sbaw090630

Más contenido relacionado

La actualidad más candente

openFrameworks 外部ファイルを利用する - 画像、動画 - 多摩美メディアアートII
openFrameworks 外部ファイルを利用する - 画像、動画 - 多摩美メディアアートIIopenFrameworks 外部ファイルを利用する - 画像、動画 - 多摩美メディアアートII
openFrameworks 外部ファイルを利用する - 画像、動画 - 多摩美メディアアートII
Atsushi Tadokoro
 
openFrameworks、プログラムの制御構造の基本 - 多摩美メディアアートII
openFrameworks、プログラムの制御構造の基本 - 多摩美メディアアートIIopenFrameworks、プログラムの制御構造の基本 - 多摩美メディアアートII
openFrameworks、プログラムの制御構造の基本 - 多摩美メディアアートII
Atsushi Tadokoro
 
openFrameworks基礎 - 新規プロジェクトの作成、図形を描く 芸大グラフィクスプログラミングB
openFrameworks基礎 - 新規プロジェクトの作成、図形を描く 芸大グラフィクスプログラミングBopenFrameworks基礎 - 新規プロジェクトの作成、図形を描く 芸大グラフィクスプログラミングB
openFrameworks基礎 - 新規プロジェクトの作成、図形を描く 芸大グラフィクスプログラミングB
Atsushi Tadokoro
 
openFrameworks addonを利用する ofxControlPanel ofxOpenCv - 多摩美メディアアートII
openFrameworks addonを利用する ofxControlPanel ofxOpenCv - 多摩美メディアアートIIopenFrameworks addonを利用する ofxControlPanel ofxOpenCv - 多摩美メディアアートII
openFrameworks addonを利用する ofxControlPanel ofxOpenCv - 多摩美メディアアートII
Atsushi Tadokoro
 
openFrameworks入門 - 多摩美メディアアートII
openFrameworks入門 - 多摩美メディアアートIIopenFrameworks入門 - 多摩美メディアアートII
openFrameworks入門 - 多摩美メディアアートII
Atsushi Tadokoro
 
Infitopost notepad
Infitopost   notepadInfitopost   notepad
Infitopost notepad
Anand Kumar
 

La actualidad más candente (19)

Hace una calculadora en jeank
Hace una calculadora en jeankHace una calculadora en jeank
Hace una calculadora en jeank
 
openFrameworks 外部ファイルを利用する - 画像、動画 - 多摩美メディアアートII
openFrameworks 外部ファイルを利用する - 画像、動画 - 多摩美メディアアートIIopenFrameworks 外部ファイルを利用する - 画像、動画 - 多摩美メディアアートII
openFrameworks 外部ファイルを利用する - 画像、動画 - 多摩美メディアアートII
 
openFrameworks、プログラムの制御構造の基本 - 多摩美メディアアートII
openFrameworks、プログラムの制御構造の基本 - 多摩美メディアアートIIopenFrameworks、プログラムの制御構造の基本 - 多摩美メディアアートII
openFrameworks、プログラムの制御構造の基本 - 多摩美メディアアートII
 
Prueba de montecarlo
Prueba de montecarloPrueba de montecarlo
Prueba de montecarlo
 
Most Common JavaScript Mistakes
Most Common JavaScript MistakesMost Common JavaScript Mistakes
Most Common JavaScript Mistakes
 
openFrameworks基礎 - 新規プロジェクトの作成、図形を描く 芸大グラフィクスプログラミングB
openFrameworks基礎 - 新規プロジェクトの作成、図形を描く 芸大グラフィクスプログラミングBopenFrameworks基礎 - 新規プロジェクトの作成、図形を描く 芸大グラフィクスプログラミングB
openFrameworks基礎 - 新規プロジェクトの作成、図形を描く 芸大グラフィクスプログラミングB
 
Trabajo de programacion
Trabajo de programacionTrabajo de programacion
Trabajo de programacion
 
Bifurcaciones (Ejemplo)
Bifurcaciones (Ejemplo)Bifurcaciones (Ejemplo)
Bifurcaciones (Ejemplo)
 
openFrameworks addonを利用する ofxControlPanel ofxOpenCv - 多摩美メディアアートII
openFrameworks addonを利用する ofxControlPanel ofxOpenCv - 多摩美メディアアートIIopenFrameworks addonを利用する ofxControlPanel ofxOpenCv - 多摩美メディアアートII
openFrameworks addonを利用する ofxControlPanel ofxOpenCv - 多摩美メディアアートII
 
openFrameworks入門 - 多摩美メディアアートII
openFrameworks入門 - 多摩美メディアアートIIopenFrameworks入門 - 多摩美メディアアートII
openFrameworks入門 - 多摩美メディアアートII
 
Infitopost notepad
Infitopost   notepadInfitopost   notepad
Infitopost notepad
 
An introduction to functional programming with Go [redux]
An introduction to functional programming with Go [redux]An introduction to functional programming with Go [redux]
An introduction to functional programming with Go [redux]
 
Metodos Numericos
Metodos NumericosMetodos Numericos
Metodos Numericos
 
Ngon ngu lap trinh
Ngon ngu lap trinhNgon ngu lap trinh
Ngon ngu lap trinh
 
Dapan
DapanDapan
Dapan
 
Clinica
ClinicaClinica
Clinica
 
Javascript i wydajność - czy to się spina?
Javascript i wydajność - czy to się spina?Javascript i wydajność - czy to się spina?
Javascript i wydajność - czy to się spina?
 
Ejercicios resueltos Practica 4 informatica II
Ejercicios resueltos Practica 4 informatica IIEjercicios resueltos Practica 4 informatica II
Ejercicios resueltos Practica 4 informatica II
 
Sbaw090526
Sbaw090526Sbaw090526
Sbaw090526
 

Más de Atsushi Tadokoro

「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
Atsushi Tadokoro
 
プログラム初級講座 - メディア芸術をはじめよう
プログラム初級講座 - メディア芸術をはじめようプログラム初級講座 - メディア芸術をはじめよう
プログラム初級講座 - メディア芸術をはじめよう
Atsushi Tadokoro
 
Interactive Music II ProcessingとSuperColliderの連携 -2
Interactive Music II ProcessingとSuperColliderの連携 -2Interactive Music II ProcessingとSuperColliderの連携 -2
Interactive Music II ProcessingとSuperColliderの連携 -2
Atsushi Tadokoro
 
coma Creators session vol.2
coma Creators session vol.2coma Creators session vol.2
coma Creators session vol.2
Atsushi Tadokoro
 
Interactive Music II ProcessingとSuperColliderの連携1
Interactive Music II ProcessingとSuperColliderの連携1Interactive Music II ProcessingとSuperColliderの連携1
Interactive Music II ProcessingとSuperColliderの連携1
Atsushi Tadokoro
 
Interactive Music II Processingによるアニメーション
Interactive Music II ProcessingによるアニメーションInteractive Music II Processingによるアニメーション
Interactive Music II Processingによるアニメーション
Atsushi Tadokoro
 
Interactive Music II Processing基本
Interactive Music II Processing基本Interactive Music II Processing基本
Interactive Music II Processing基本
Atsushi Tadokoro
 
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
Atsushi Tadokoro
 
Media Art II openFrameworks アプリ間の通信とタンジブルなインターフェイス
Media Art II openFrameworks  アプリ間の通信とタンジブルなインターフェイス Media Art II openFrameworks  アプリ間の通信とタンジブルなインターフェイス
Media Art II openFrameworks アプリ間の通信とタンジブルなインターフェイス
Atsushi Tadokoro
 
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
Atsushi Tadokoro
 
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描くiTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
Atsushi Tadokoro
 
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリメディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
Atsushi Tadokoro
 
芸術情報演習デザイン(Web) 第8回: CSSフレームワークを使う
芸術情報演習デザイン(Web)  第8回: CSSフレームワークを使う芸術情報演習デザイン(Web)  第8回: CSSフレームワークを使う
芸術情報演習デザイン(Web) 第8回: CSSフレームワークを使う
Atsushi Tadokoro
 
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
Atsushi Tadokoro
 
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
Atsushi Tadokoro
 
Webデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
Webデザイン 第10回:HTML5実践 Three.jsで3DプログラミングWebデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
Webデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
Atsushi Tadokoro
 
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
Atsushi Tadokoro
 
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画するiTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
Atsushi Tadokoro
 
Media Art II openFrameworks 複数のシーンの管理・切替え
Media Art II openFrameworks 複数のシーンの管理・切替えMedia Art II openFrameworks 複数のシーンの管理・切替え
Media Art II openFrameworks 複数のシーンの管理・切替え
Atsushi Tadokoro
 

Más de Atsushi Tadokoro (20)

「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
 
プログラム初級講座 - メディア芸術をはじめよう
プログラム初級講座 - メディア芸術をはじめようプログラム初級講座 - メディア芸術をはじめよう
プログラム初級講座 - メディア芸術をはじめよう
 
Interactive Music II ProcessingとSuperColliderの連携 -2
Interactive Music II ProcessingとSuperColliderの連携 -2Interactive Music II ProcessingとSuperColliderの連携 -2
Interactive Music II ProcessingとSuperColliderの連携 -2
 
coma Creators session vol.2
coma Creators session vol.2coma Creators session vol.2
coma Creators session vol.2
 
Interactive Music II ProcessingとSuperColliderの連携1
Interactive Music II ProcessingとSuperColliderの連携1Interactive Music II ProcessingとSuperColliderの連携1
Interactive Music II ProcessingとSuperColliderの連携1
 
Interactive Music II Processingによるアニメーション
Interactive Music II ProcessingによるアニメーションInteractive Music II Processingによるアニメーション
Interactive Music II Processingによるアニメーション
 
Interactive Music II Processing基本
Interactive Music II Processing基本Interactive Music II Processing基本
Interactive Music II Processing基本
 
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
 
Media Art II openFrameworks アプリ間の通信とタンジブルなインターフェイス
Media Art II openFrameworks  アプリ間の通信とタンジブルなインターフェイス Media Art II openFrameworks  アプリ間の通信とタンジブルなインターフェイス
Media Art II openFrameworks アプリ間の通信とタンジブルなインターフェイス
 
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
 
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描くiTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
 
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリメディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
 
芸術情報演習デザイン(Web) 第8回: CSSフレームワークを使う
芸術情報演習デザイン(Web)  第8回: CSSフレームワークを使う芸術情報演習デザイン(Web)  第8回: CSSフレームワークを使う
芸術情報演習デザイン(Web) 第8回: CSSフレームワークを使う
 
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
 
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
 
Tamabi media131118
Tamabi media131118Tamabi media131118
Tamabi media131118
 
Webデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
Webデザイン 第10回:HTML5実践 Three.jsで3DプログラミングWebデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
Webデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
 
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
 
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画するiTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
 
Media Art II openFrameworks 複数のシーンの管理・切替え
Media Art II openFrameworks 複数のシーンの管理・切替えMedia Art II openFrameworks 複数のシーンの管理・切替え
Media Art II openFrameworks 複数のシーンの管理・切替え
 

Sbaw090630

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. #pragma once #include "ofMain.h" #include "ofxAccelerometer.h" #include "ofxMultiTouch.h" #define NUM 10 class testApp : public ofSimpleApp, public ofxMultiTouchListener { public: void setup(); void update(); void draw(); void exit(); ...( )... ofPoint pos[NUM]; };
  • 9. #include "testApp.h" void testApp::setup(){ ofSetColor(0, 0, 255); ofBackground(0, 0, 0); ofSetBackgroundAuto(true); ofSetFrameRate(60); // ofxMultiTouch.addListener(this); // for(int i=0; i<NUM; i++){ pos[i].x = -100; pos[i].y = -100; } } void testApp::update(){ } void testApp::draw(){ for(int i=0; i<NUM; i++){ ofCircle(pos[i].x, pos[i].y, 40); } }
  • 10. void testApp::exit() { } // void testApp::mouseMoved(int x, int y){ } void testApp::mouseDragged(int x, int y, int button){ printf("mouseDragged: %i, %i %in", x, y, button); pos[0].x = x; pos[0].y = y; } void testApp::mousePressed(int x, int y, int button){ printf("mousePressed: %i, %i %in", x, y, button); pos[0].x = x; pos[0].y = y; } void testApp::mouseReleased(){ } void testApp::mouseReleased(int x, int y, int button){ printf("mouseReleased: %i, %i %in", x, y, button); pos[0].x = -100;
  • 11. pos[0].y = -100; } // void testApp::touchDown(float x, float y, int touchId, ofxMultiTouchCustomData *data){ printf("touchDown: %i, %i %in", x, y, touchId); pos[touchId].x = x; pos[touchId].y = y; } void testApp::touchMoved(float x, float y, int touchId, ofxMultiTouchCustomData *data){ printf("touchMoved: %i, %i %in", x, y, touchId); pos[touchId].x = x; pos[touchId].y = y; } void testApp::touchUp(float x, float y, int touchId, ofxMultiTouchCustomData *data){ printf("touchUp: %i, %i %in", x, y, touchId); pos[touchId].x = -100; pos[touchId].y = -100; } void testApp::touchDoubleTap(float x, float y, int touchId, ofxMultiTouchCustomData *data){ }
  • 12.
  • 13.
  • 14.
  • 15. #pragma once #include "ofMain.h" #include "ofxAccelerometer.h" #include "ofxMultiTouch.h" class testApp : public ofSimpleApp, public ofxMultiTouchListener { public: void setup(); void update(); void draw(); void exit(); ...( )... ofPoint accel; };
  • 16. #include "testApp.h" void testApp::setup(){ ofBackground(0, 0, 0); ofSetBackgroundAuto(true); ofSetFrameRate(60); // ofxAccelerometer.setup(); } void testApp::update(){ //x,y,z accel.x = ofxAccelerometer.getForce().x; accel.y = ofxAccelerometer.getForce().y; accel.z = ofxAccelerometer.getForce().z; // printf("get force: %f, %f, %f n", accel.x, accel.y, accel.z); }
  • 17. void testApp::draw(){ // float rectScale = 200.0; ofSetColor(255, 0, 0); ofRect(0, ofGetHeight()/2, ofGetWidth()/3, accel.x * rectScale); ofSetColor(0, 255, 0); ofRect(ofGetWidth()/3, ofGetHeight()/2, ofGetWidth()/3, accel.y * rectScale); ofSetColor(0, 0, 255); ofRect(ofGetWidth()/3*2, ofGetHeight()/2, ofGetWidth()/3, accel.z * rectScale); } ...( )...
  • 18.
  • 19.
  • 20. #pragma once #include "ofMain.h" #include "ofxAccelerometer.h" #include "ofxMultiTouch.h" #include "Spot.h" class testApp : public ofSimpleApp, public ofxMultiTouchListener { public: void setup(); void update(); void draw(); void exit(); ...( )... private: Spot** sp; //Spot sp (**) int numSpot; // Spot };
  • 21. #include "testApp.h" #include "Spot.h" #define NUM_POINT 5 void testApp::setup(){ ofBackground(0, 0, 0); ofSetBackgroundAuto(true); ofSetFrameRate(60); // // ofEnableAlphaBlending(); // ofSetBackgroundAuto(false); // ofxAccelerometer.setup(); // ofxMultiTouch.addListener(this); // numSpot = 400; // sp = new Spot*[numSpot]; for(int i = 0; i < numSpot; i++){ ofPoint _pos, _velocity; _pos.x = ofRandom(0, ofGetWidth()); _pos.y = ofRandom(0, ofGetHeight());
  • 22. _velocity.x = 0; _velocity.y = 0; float _diameter = ofRandom(1, 10); // sp[i] = new Spot(_pos, _velocity, _diameter); // sp[i]->gravity = 0.05; // sp[i]->friction = 0.99; } } void testApp::update(){ ofSetColor(0, 0, 0, 31); ofRect(0, 0, ofGetWidth(), ofGetHeight()); for(int i = 0; i < numSpot; i++){ sp[i]->update(); } } void testApp::draw(){ for(int i = 0; i < numSpot; i++){ sp[i]->display(); } }
  • 23. void testApp::exit() { } void testApp::mouseMoved(int x, int y){ } void testApp::mouseDragged(int x, int y, int button){ for(int i=0; i<numSpot; i++){ if(i % NUM_POINT == 0){ sp[i]->touched = true; sp[i]->moveTo(x, y); } } } void testApp::mousePressed(int x, int y, int button){ for(int i=0; i<numSpot; i++){ if(i % NUM_POINT == 0){ sp[i]->touched = true; sp[i]->moveTo(x, y); } } } void testApp::mouseReleased(){ }
  • 24. void testApp::mouseReleased(int x, int y, int button){ for(int i=0; i<numSpot; i++){ if(i % NUM_POINT == 0){ sp[i]->touched = false; } } } void testApp::touchDown(float x, float y, int touchId, ofxMultiTouchCustomData *data){ for(int i=0; i<numSpot; i++){ if(i % NUM_POINT == touchId){ sp[i]->touched = true; sp[i]->moveTo(x, y); } } } void testApp::touchMoved(float x, float y, int touchId, ofxMultiTouchCustomData *data) { for(int i=0; i<numSpot; i++){ if(i % NUM_POINT == touchId){ sp[i]->touched = true; sp[i]->moveTo(x, y); } } }
  • 25. void testApp::touchUp(float x, float y, int touchId, ofxMultiTouchCustomData *data){ for(int i=0; i<numSpot; i++){ if(i % NUM_POINT == touchId){ sp[i]->touched = false; } } }
  • 26. #ifndef _OF_SPOT #define _OF_SPOT #include "ofMain.h" #include "ofxMultiTouch.h" #include "ofxAccelerometer.h" class Spot { public: Spot(ofPoint pos, ofPoint velocity, float diameter); void update(); void display(); void moveTo(float x, float y); ofPoint pos; ofPoint velocity; float diameter; float gravity; float friction; bool touched; }; #endif
  • 27. #include "Spot.h" Spot::Spot(ofPoint _pos, ofPoint _velocity, float _diameter) { pos = _pos; velocity = _velocity; diameter = _diameter; touched = false; } void Spot::update() { if(!touched){ velocity *= friction; velocity.x += gravity * ofxAccelerometer.getForce().x; velocity.y -= gravity * ofxAccelerometer.getForce().y; pos.x += velocity.x * diameter; pos.y += velocity.y * diameter; if(pos.x < diameter){ velocity.x *= -1; pos.x = diameter; } if(pos.x > ofGetWidth() - diameter){ velocity.x *= -1; pos.x = ofGetWidth() - diameter; }
  • 28. if(pos.y < diameter){ velocity.y *= -1; pos.y = diameter; } if(pos.y > ofGetHeight()-diameter){ velocity.y *= -1; pos.y = ofGetHeight()-diameter; } } } void Spot::display() { ofSetColor(0, 127, 255, 200); ofCircle(pos.x, pos.y, diameter); } void Spot::moveTo(float x, float y) { pos.x = x; pos.y = y; velocity.x = ofRandom(-1, 1); velocity.y = ofRandom(-1, 1); }