Ejemplo n.º 1
0
ofPoint	 TimeLine::getPositionForTime( float _time){
	
	// are we recording?
	if ( !isFinish() ){
		return ofPoint(0,0,0);
	}
	
	// now, let's figure out where we are in the drawing...
	ofPoint pos;
	for (int i = 0; i < points.size()-1; i++){
		if (_time >= points[i].time && _time <= points[i+1].time){
			
			// calculate pct:
			float part = _time - points[i].time;
			float whole = points[i+1].time - points[i].time;
			float pct = part / whole;
			
			// figure out where we are between a and b
			pos.x = (1-pct) * points[i].x + (pct) * points[i+1].x;
			pos.y = (1-pct) * points[i].y + (pct) * points[i+1].y;
            
			
		}
	}
	
	return pos;
}
Ejemplo n.º 2
0
void TouchLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent){
	if (isFinish())
	{
		return;
	}
	CCPoint touchp = ((CCTouch*)pTouches->anyObject())->getLocationInView();
	touchp = CCDirector::sharedDirector()->convertToUI(touchp);
	//CCLog("x= %f, y= %f",touchp.x,touchp.y);

// 	CCSprite* tianzige = Hlayer->getSprite();
	HcharacterDrawnode* tianzige = Hlayer->getm_HDrawnode();
	if (isStartOutside)
	{
		return;
	}
	if (tianzige->boundingBox().containsPoint(touchp))
	{
		//在范围内,并且起笔在范围内
		touchp = tianzige->convertToNodeSpace(touchp);
		touchPoints.push_back(touchp);
		Hlayer->getm_HDrawnode()->addPoint(touchp);
	}else if(!tianzige->boundingBox().containsPoint(touchp))
	{
		//不再范围内,并且起笔在范围内
		isOutside = true;
	}
	//CCLog("x= %f, y= %f",touchp.x,touchp.y);
	//CCLog("isStartOutside = %d, isOutside = %d",isStartOutside,isOutside);
}
Ejemplo n.º 3
0
void TouchLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent){
	getHlayer()->getInfoSprite()->setVisible(false);
	//判断写了几笔 超过笔数就不
	if (isFinish())
	{
		return;
	}

	CCPoint touchpoint = ((CCTouch*)pTouches->anyObject())->getLocationInView();
// 	CCLog("TouchLayer::ccTouchesBegan getLocationInView x= %f, y= %f",touchpoint.x,touchpoint.y);
	touchpoint = CCDirector::sharedDirector()->convertToUI(touchpoint);
// 	CCLog("TouchLayer::ccTouchesBegan convertToUI x= %f, y= %f",touchpoint.x,touchpoint.y);
	this->beginPoint = touchpoint;
// 	CCSprite* tianzige = Hlayer->getSprite();
	HcharacterDrawnode* dnode = Hlayer->getm_HDrawnode();
	if (dnode->boundingBox().containsPoint(touchpoint))
	{
		//在范围内
		touchpoint = dnode->convertToNodeSpace(touchpoint);
// 		CCLog("TouchLayer::ccTouchesBegan convertToNodeSpace x= %f, y= %f",touchpoint.x,touchpoint.y);
		touchPoints.push_back(touchpoint);
		Stroke str(touchPoints);
		Hlayer->getm_HDrawnode()->addStroke(str);
	}else
	{
		//不在范围内
		this->isStartOutside = true;
		touchPoints.clear();
	}
	
}
Ejemplo n.º 4
0
path aStar(map c, coord p, finish f){
	int end=0;
	int i,j;
	list* open=createList();
	list* closed=createList();
	node* startNode=createNode(p);
	node* current;
	node* neighbor;
	addElement(open,startNode);
	coord bestFinish=getbestFinish(p,f);

	while(!end)
		{
		current= removeElement(open);
		addElement(closed,current);
		end=isFinish(current->coord,f);
		for(i=-1;i<=1;i++)
			{
			for(j=-1;j<=1;j++)
				{
				if(i!=0 || j!=0)
					{
					neighbor=createNode(createCoord(current->coord.x+i, current->coord.y+j));
					if(! (isObstacle(neighbor->coord,c) || contains(closed,neighbor)))
						{
						if(contains(open,neighbor))
							{
							if(current->cost+1 < neighbor->cost)
								{
								neighbor->cost= current->cost+1;
								if(isSand(neighbor->coord,c))
									{
									neighbor->cost += 4;
									}
								neighbor->pred=current;
								}
							}
						else
							{
							neighbor->pred=current;
							neighbor->cost=current->cost+1;
							if(isSand(neighbor->coord,c))
								{
								neighbor->cost += 4;
								}
							neighbor->heuristic=neighbor->cost=current->cost + neighbor->cost+norm(substractCoords(bestFinish,current->coord));
							addSortedElement(open,neighbor);
							}
						}
					}
				}
		}
	}
	freeList(closed);
	freeList(open);
	path path=reconstructPath(current);
	return path;
}
Ejemplo n.º 5
0
void abalone::play(void)
{    // affichage du titre
     shell.printc(JAUNE,"\n\n\t\tabalone!\n\n");    
     shell.printc(VERT,"           _____      _               _____ _     _ \n          |  ___|    (_)             |_   _| |   | |\n          | |__ _ __  _  ___  _   _    | | | |_  | |\n          |  __| '_ \\| |/ _ \\| | | |   | | | __| | |\n          | |__| | | | | (_) | |_| |  _| |_| |_  |_|\n          \\____/_| |_| |\\___/ \\__, |  \\___/ \\__| (_)\n                    _/ |       __/ |                \n                   |__/       |___/\n\n\n\n\n");
     system("pause");
    
     // lancement du jeux
     while(!isFinish())
       getInfoFromPlayer(); // fait jouer la partie
    
     // partie terminée, affichage du gagnant
     drawPlayerInfoAndArray(); // affichage stat et jeux
     shell.printc(JAUNE,"\n\n     ** partie terminee **");
     shell.printc(JAUNE,"\n          gagnant : joueur %i !",isFinish());
     shell.printc(JAUNE,"\n\n\n     merci d'avoir joue :D\n\n");
     system("pause");
     // and bye bye :)
}
Ejemplo n.º 6
0
void TouchLayer::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent){
	if (isFinish())
	{
		return;
	}
	CCPoint touchp = ((CCTouch*)pTouches->anyObject())->getLocationInView();
	touchp = CCDirector::sharedDirector()->convertToUI(touchp);
// 	CCSprite* tianzige = Hlayer->getSprite();
	HcharacterDrawnode* tianzige = Hlayer->getm_HDrawnode();
	if (this->beginPoint.equals(touchp) && tianzige->boundingBox().containsPoint(touchp))
	{
		Hlayer->getm_HDrawnode()->removeLastStroke();
	}
	if (this->beginPoint.equals(touchp))
	{
		isStartOutside = false;
		isOutside = false;
		touchPoints.clear();
		return;
	}
	if (isStartOutside)
	{
		isStartOutside = false;
		isOutside = false;
		touchPoints.clear();
		return;
	}
	if (tianzige->boundingBox().containsPoint(touchp) && isOutside == false)
	{
		//在范围内,并且起笔在范围内,中途没有出田字格
		touchp = tianzige->convertToNodeSpace(touchp);
		touchPoints.push_back(touchp);
		Hlayer->getm_HDrawnode()->addPoint(touchp);

		//一笔完成,并且起点,中途,尾点都在范围内,点数据保存在points中
		Hlayer->judge();			//自动在HcharacterDrawnode中获取点信息

		touchPoints.clear();
	}else if (!tianzige->boundingBox().containsPoint(touchp) && isOutside == false)
	{
		//不在范围内,中途没出田字格
		Hlayer->getm_HDrawnode()->removeLastStroke();
	}else if(isOutside == true)
	{
		Hlayer->getm_HDrawnode()->removeLastStroke();
		isOutside = false;
	}
	//CCLog("x= %f, y= %f",touchp.x,touchp.y);
	//CCLog("isStartOutside = %d, isOutside = %d",isStartOutside,isOutside);
	isStartOutside = false;
	isOutside = false;
	touchPoints.clear();
}
Ejemplo n.º 7
0
void TimeLine::draw(){
    
    if (points.size() > 0){
        //  For making super smooth and gradient lines use ofMeshes.
        //  Them let you add vertex asociated to colors.
        //  OpenGL it's going to be in charge of making the gradient ; )
        //
        
        ofMesh lineMesh;
        lineMesh.setMode(OF_PRIMITIVE_LINE_STRIP);  //  There are other modes like: points, triangles and quads
        
        for (int i = 0 ; i < points.size() ; i++){
            
            //  Map the position on the array with the alpha to geting alfa gradient
            //
            //float alpha = ofMap(i+1, 1,points.size(), 0.0,1.0);
            
            lineMesh.addColor(1.0); //ofFloatColor(_color, alpha*0.3) );   //  We are using ofFloatColors that goes from 0.0 - 1.0
            //  instead of 0-255 that's way you have better quality
            lineMesh.addVertex(points[i]);
        }
        
        //  Once this object call ofMesh it's done you can draw it.
        //
        ofSetColor(255);
        lineMesh.draw();
        
        if ( isFinish() ){
            
            // figure out what time we are at, and make sure we playback cyclically (!)
            // use the duration here and make sure our timeToCheck is in the range of 0 - duration
            float timeToCheck = ofGetElapsedTimef();
            
            while (timeToCheck > getDuration() && getDuration() > 0){
                timeToCheck -= getDuration();
            }
            
            // get the position and velocity at timeToCheck
            ofPoint pos = getPositionForTime(timeToCheck);
            
            ofPushStyle();
            ofSetColor(255, 0, 0);
            ofCircle(pos, 5);
            ofPopStyle();
        }
    }
}
Ejemplo n.º 8
0
int main(int argc, char**argv)
{
	capture.open(0);
	if (capture.isOpened() == false)
	{
		std::cerr << "no capture device found" << std::endl;
		return 1;
	}
	capture.set(CV_CAP_PROP_FRAME_WIDTH,  vgaSize.width);
	capture.set(CV_CAP_PROP_FRAME_HEIGHT, vgaSize.height);
	if (capture.get(cv::CAP_PROP_FRAME_WIDTH) != (double)vgaSize.width || capture.get(cv::CAP_PROP_FRAME_HEIGHT) != (double)vgaSize.height)
	{
		std::cerr << "current device doesn't support " << vgaSize.width << "x" << vgaSize.height << " size" << std::endl;
		return 2;
	}
	cv::Mat image;
	capture >> image;

	cv::namedWindow(windowName);
	cv::imshow(windowName, image);

	initCuda();
	initArray(image);

	char key = -1;
	enum device statusDevice = useCpuSimd;
	enum precision statusPrecision = precisionFloat;
	int index = 1;
	cv::Mat stub = cv::imread(imagePath[index][0], cv::IMREAD_UNCHANGED);
	cv::Mat gain = cv::Mat(stub.rows, stub.cols/2, CV_16SC1, stub.data);
	double elapsedTime;
	while (isFinish(key) == false)
	{
		capture >> image;

		switch (key)
		{
		case 'h':
		case 'H':
			// switch to half precision
			statusPrecision = precisionHalf;
			std::cout << std::endl << header << "half  " << std::endl;
			stub = cv::imread(imagePath[index][0], cv::IMREAD_UNCHANGED);
			gain = cv::Mat(stub.rows, stub.cols/2, CV_16SC1, stub.data);
			break;
		case 'f':
		case 'F':
			// switch to single precision
			statusPrecision = precisionFloat;
			std::cout << std::endl << header << "single" << std::endl;
			stub = cv::imread(imagePath[index][1], cv::IMREAD_UNCHANGED);
			gain = cv::Mat(stub.rows, stub.cols, CV_32FC1, stub.data);
			break;
		case 'b':
		case 'B':
			// switch to gray gain
			statusPrecision = precisionByte;
			std::cout << std::endl << header << "char" << std::endl;
			gain = cv::imread(imagePath[index][2], cv::IMREAD_GRAYSCALE);
			break;
		case '0':
		case '1':
			index = key - '0';
			switch (statusPrecision)
			{
			case precisionHalf:
				// precision half
				stub = cv::imread(imagePath[index][0], cv::IMREAD_UNCHANGED);
				gain = cv::Mat(stub.rows, stub.cols/2, CV_16SC1, stub.data);
				break;
			case precisionFloat:
				// precision single
				stub = cv::imread(imagePath[index][1], cv::IMREAD_UNCHANGED);
				gain = cv::Mat(stub.rows, stub.cols, CV_32FC1, stub.data);
				break;
			case precisionByte:
				// precision single
				gain = cv::imread(imagePath[index][2], cv::IMREAD_GRAYSCALE);
				break;
			default:
				break;
			}
			break;
		case 'c':
		case 'C':
			std::cout << std::endl << "Using CPU SIMD           " << std::endl;
			statusDevice = useCpuSimd;
			break;
		case 'g':
		case 'G':
			std::cout << std::endl << "Using GPU                " << std::endl;
			statusDevice = useGpu;
			break;
		default:
			break;
		}

		if (statusDevice == useCpuSimd)
		{
			elapsedTime = multiplyImage(image, gain);
		}
		else
		{
#ifdef HAVE_CUDA
			// CUDA
			elapsedTime = multiplyImageCuda(image, gain);
#endif // HAVE_CUDA
		}
		computeStatistics(elapsedTime, key);

		if (key == 's' || key == 'S')
		{
			cv::imwrite(dumpFilename, image);
		}

		cv::imshow(windowName, image);
		key = cv::waitKey(1);
	}
	std::cout << std::endl;
	cv::destroyAllWindows();
	releaseArray();

	return 0;
}
Ejemplo n.º 9
0
task main()
{
	int EmptiesArray[MAXCOL] = {3, 3, 3, 3, 3, 3, 3};
	SensorType[S1] = sensorI2CCustom9V;
	SensorType[S2] = sensorColorNxtRED;
	SensorType[S3] = sensorTouch; //used for recalibration
	SensorType[S4] = sensorSONAR;
	
	
	while(SensorValue(S4) == 255){}
	playSound(soundDownwardTones);
	time1[T1] = 0;

	int curPos = -2;

	motor[motorA] = 10;
	motor[motorB] = 10;
	while(SensorValue[S3] != 1)
	{}
	motor[motorA] = 0;
	motor[motorB] = 0;

	displayGameBoard();
	do
	{
		updateEmpties(EmptiesArray);
		robotPlace(EmptiesArray, curPos);
		if (!isFinish())
		{
			clearTimer(T1);
			while (time1[T1]<5000)
			{
				if (time1[T1]%1000==0)
				{
					playTone (650,50);
					wait1Msec(800);
					clearSounds();
				}	
			}
			playTone (850, 50);
			curPos = P_moveUpdate(EmptiesArray);
		}
	} while(!isFinish());

	playTone(695, 14); while(bSoundActive);
	playTone(695, 14); while(bSoundActive);
	playTone(695, 14); while(bSoundActive);
	playTone(929, 83); while(bSoundActive);
	playTone(1401, 83); while(bSoundActive);
	playTone(1251, 14); while(bSoundActive);
	playTone(1188, 14); while(bSoundActive);
	playTone(1054, 14); while(bSoundActive);
	playTone(1841, 83); while(bSoundActive);
	playTone(1401, 41); while(bSoundActive);
	playTone(1251, 14); while(bSoundActive);
	playTone(1188, 14); while(bSoundActive);
	playTone(1054, 14); while(bSoundActive);
	playTone(1841, 83); while(bSoundActive);
	playTone(1401, 41); while(bSoundActive);
	playTone(1251, 14); while(bSoundActive);
	playTone(1188, 14); while(bSoundActive);
	playTone(1251, 14); while(bSoundActive);
	playTone(1054, 55); while(bSoundActive);
	wait1Msec(280);
	playTone(695, 14); while(bSoundActive);
	playTone(695, 14); while(bSoundActive);
	playTone(695, 14); while(bSoundActive);
	playTone(929, 83); while(bSoundActive);
	playTone(1401, 83); while(bSoundActive);
	playTone(1251, 14); while(bSoundActive);
	playTone(1188, 14); while(bSoundActive);
	playTone(1054, 14); while(bSoundActive);
	playTone(1841, 83); while(bSoundActive);
	playTone(1401, 41); while(bSoundActive);
	playTone(1251, 14); while(bSoundActive);
	playTone(1188, 14); while(bSoundActive);
	playTone(1054, 14); while(bSoundActive);
	playTone(1841, 83); while(bSoundActive);
	playTone(1401, 41); while(bSoundActive);
	playTone(1251, 14); while(bSoundActive);
	playTone(1188, 14); while(bSoundActive);
	playTone(1251, 14); while(bSoundActive);
	playTone(1054, 55); while(bSoundActive);//[3]
	wait1Msec(280);

}