#pragma once

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

class testApp :...
#include "testApp.h"

void testApp::setup(){	
	   ofSetColor(0, 0, 255);
	   ofBackground(0, 0, 0);
	   ofSetBackgroundAut...
void testApp::exit() {
}

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

void testApp::mouseDragged(int x, int y, int butto...
pos[0].y = -100;
}
//
void testApp::touchDown(float x, float y, int touchId, ofxMultiTouchCustomData
*data){
	   printf("t...
#pragma once

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

class testApp : public ofSimpl...
#include "testApp.h"

void testApp::setup(){
	 ofBackground(0, 0, 0);
	 ofSetBackgroundAuto(true);
	 ofSetFrameRate(60);
	...
void testApp::draw(){
	 //
	   float rectScale = 200.0;
	   ofSetColor(255, 0, 0);
	   ofRect(0, ofGetHeight()/2, ofGetWid...
#pragma once

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

clas...
#include "testApp.h"
#include "Spot.h"

#define NUM_POINT 5

void testApp::setup(){	
	   ofBackground(0, 0, 0);
	   ofSetB...
_velocity.x = 0;
	   	     _velocity.y = 0;
	   	     float _diameter = ofRandom(1, 10);
	   	     //                  	
	...
void testApp::exit() {
}

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

void testApp::mouseDragged(int x, int y, int button){...
void testApp::mouseReleased(int x, int y, int button){
	   for(int i=0; i<numSpot; i++){
	   	     if(i % NUM_POINT == 0){...
void testApp::touchUp(float x, float y, int touchId, ofxMultiTouchCustomData *data){
	   for(int i=0; i<numSpot; i++){
	  ...
#ifndef _OF_SPOT
#define _OF_SPOT

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

class Spo...
#include "Spot.h"

Spot::Spot(ofPoint _pos, ofPoint _velocity, float _diameter)
{
	   pos = _pos;
	   velocity = _velocity...
if(pos.y < diameter){
	   	     	    velocity.y *= -1;
	   	     	    pos.y = diameter;
	   	     }
	   	     if(pos.y > o...
Sbaw090630
Sbaw090630
Sbaw090630
Sbaw090630
Sbaw090630
Sbaw090630
Sbaw090630
Sbaw090630
Sbaw090630
Sbaw090630
Sbaw090630
Sbaw090630
Sbaw090630
Upcoming SlideShare
Loading in …5
×

Sbaw090630

1,704 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,704
On SlideShare
0
From Embeds
0
Number of Embeds
461
Actions
Shares
0
Downloads
20
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Sbaw090630

  1. 1. #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]; };
  2. 2. #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); } }
  3. 3. 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;
  4. 4. 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){ }
  5. 5. #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; };
  6. 6. #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); }
  7. 7. 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); } ...( )...
  8. 8. #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 };
  9. 9. #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());
  10. 10. _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(); } }
  11. 11. 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(){ }
  12. 12. 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); } } }
  13. 13. 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; } } }
  14. 14. #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
  15. 15. #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; }
  16. 16. 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); }

×