Example #1
0
// static
void GSubImageFinder2::test()
{
	// Make some random image
	GImage foo;
	foo.setSize(256, 256);
	foo.clear(0xff000000);
	foo.boxFill(13, 8, 12, 17, 0xff808030);
	foo.boxFill(8, 13, 10, 9, 0xff407040);
	foo.boxFill(20, 20, 220, 220, 0xffffffee);

	// Make the finder
	GSubImageFinder2 finder(&foo);

	// Make a sub-image
	GRect r2(0, 0, 256, 256);
	GRect r;
	r.x = 13;
	r.y = 17;
	r.w = 32;
	r.h = 32;
	GImage bar;
	bar.setSize(32, 32);
	bar.blit(0, 0, &foo, &r);

	// Find the sub-image
	r.x = 0;
	r.y = 0;
	int x, y;
	finder.findSubImage(&x, &y, &bar, &r);
	if(x != 13 || y != 17)
		throw "wrong answer";
}
Example #2
0
	HelloDialog(HelloController* pController, int w, int h)
	: GWidgetDialog(w, h, 0xff90d0f0) // a=ff, r=90, g=d0, b=f0
	{
		m_pController = pController;
		m_pImage = new GImage();
		m_pImage->setSize(800, 600);
		m_pCanvas = new GWidgetCanvas(this, 10, 30, m_pImage->width(), m_pImage->height(), m_pImage);
		m_pQuitButton = new GWidgetTextButton(this, 850, 300, 80, 24, "Quit");
	}
Example #3
0
// static
void GPlotWindow::stringLabel(GImage* pImage, const char* szText, int x, int y, float size, unsigned int color, double angle)
{
	// Draw the label such that it ends at the center of the temp image
	int width = GImage::measureTextWidth(szText, size);
	int nSize = (int)(std::max((float)width, size * 12) * 2.3);
	GImage tmp;
	tmp.setSize(nSize, nSize);
	tmp.clear(0x0);
	tmp.text(szText, nSize / 2 - width, (int)((nSize - size * 12) / 2), size, color, 1000, 1000);

	// Rotate the label around the center
	GImage tmp2;
	tmp2.rotate(&tmp, nSize / 2, nSize / 2, angle);

	// Blit such that the label ends at the specified point
	GRect r(0, 0, nSize, nSize);
	pImage->blitAlpha(x - nSize / 2, y - nSize / 2, &tmp2, &r);
}
Example #4
0
	CarOnHillModel(GRand* prng, GImage* pImage, GWidgetTextLabel* pWins)
	{
		m_pWins = pWins;
		m_wins = 0;
		m_pImage = pImage;
		m_carPos = 0;
		m_velocity = 0;
		m_prng = prng;

		// Load the car image and add some border so we can rotate it
		GImage tmp;
		tmp.loadPng("minicar.png");
		m_pCar = new GImage();
		m_pCar->setSize(70, 60);
		GRect r(0, 0, 60, 36);
		m_pCar->blit(5, 5, &tmp, &r);
		m_pRotatedCar = new GImage();

		// Make the agent
		GMixedRelation* pRelAgent = new GMixedRelation();
		sp_relation relAgent;
		relAgent = pRelAgent;
		pRelAgent->addAttr(0); // position
		pRelAgent->addAttr(0); // velocity
		pRelAgent->addAttr(2); // action {forward, reverse}
		double initialState[2];
		initialState[0] = m_carPos;
		initialState[1] = m_velocity;
		double goalState[2];
		goalState[0] = 2;
		goalState[1] = 0;
		m_pActionIterator = new GDiscreteActionIterator(2);
		m_pAgents[0] = new CarQAgent(relAgent, initialState, m_prng, m_pActionIterator);
		((GQLearner*)m_pAgents[0])->setLearningRate(.9);
		((GQLearner*)m_pAgents[0])->setDiscountFactor(0.999);
	}
Example #5
0
	CarOnHillDialog(CarOnHillController* pController, int w, int h)
	: GWidgetDialog(w, h, 0xff90d0f0)
	{
		m_pController = pController;

		m_pBullets = new GWidgetBulletGroup(this, 820, 102, 14, 14, 2, 30, true);
		new GWidgetTextLabel(this, 840, 100, 100, 24, "Mouse", 0xff306000);
		new GWidgetTextLabel(this, 840, 130, 100, 24, "Q-Learner", 0xff306000);
		m_pBullets->setSelection(1);

		m_pWins = new GWidgetTextLabel(this, 820, 300, 100, 24, "Wins: 0", 0xff306000, 0xff90d0f0);

		m_pUpdateDisplay = new GWidgetCheckBox(this, 820, 402, 18, 18);
		m_pUpdateDisplay->setChecked(true);
		new GWidgetTextLabel(this, 840, 400, 100, 24, "Slow", 0xff306000);

		m_pImage = new GImage();
		m_pImage->setSize(800, 600);

		m_pCanvas = new GWidgetCanvas(this, 10, 30, m_pImage->width(), m_pImage->height(), m_pImage);
		m_prng = new GRand(0);
		m_pModel = new CarOnHillModel(m_prng, m_pImage, m_pWins);
		m_bPrevUpdate = true;
	}
Example #6
0
GImage* GPlotWindow::labelAxes(int maxHorizAxisLabels, int maxVertAxisLabels, int precision, float size, unsigned int color, double angle)
{
	int spacing = 10;
	int horizMargin = 200;
	int vertMargin = 200;
	GImage* pOutImage = new GImage();
	pOutImage->setSize(m_pImage->width() + horizMargin, m_pImage->height() + vertMargin);
	pOutImage->clear(0xffffffff);
	GRect r(0, 0, m_pImage->width(), m_pImage->height());
	pOutImage->blit(horizMargin, 0, m_pImage, &r);
	if(maxHorizAxisLabels > 0)
	{
		GPlotLabelSpacer spacer(m_window.x, m_window.x + m_window.w, maxHorizAxisLabels);
		for(int i = 0; i < spacer.count(); i++)
		{
			double pos = spacer.label(i);
			int x1, y1;
			windowToView(pos, 0, &x1, &y1);
			numericLabel(pOutImage, pos, horizMargin + x1, m_pImage->height() + spacing, precision, size, color, angle);
		}
	}
	else if(maxHorizAxisLabels == -1)
	{
		GPlotLabelSpacerLogarithmic spacer(m_window.x, m_window.x + m_window.w);
		while(true)
		{
			double pos;
			bool primary;
			if(!spacer.next(&pos, &primary))
				break;
			if(primary)
			{
				double x = log(pos);
				int x1, y1;
				windowToView(x, 0, &x1, &y1);
				numericLabel(pOutImage, pos, horizMargin + x1, m_pImage->height() + spacing, precision, size, color, angle);
			}
		}
	}
	if(maxVertAxisLabels > 0)
	{
		GPlotLabelSpacer spacer(m_window.y, m_window.y + m_window.h, maxVertAxisLabels);
		for(int i = 0; i < spacer.count(); i++)
		{
			double pos = spacer.label(i);
			int x1, y1;
			windowToView(0, pos, &x1, &y1);
			numericLabel(pOutImage, pos, horizMargin - spacing, y1, precision, size, color, 0.0);
		}
	}
	else if(maxVertAxisLabels == -1)
	{
		GPlotLabelSpacerLogarithmic spacer(m_window.y, m_window.y + m_window.h);
		while(true)
		{
			double pos;
			bool primary;
			if(!spacer.next(&pos, &primary))
				break;
			if(primary)
			{
				double y = log(pos);
				int x1, y1;
				windowToView(0, y, &x1, &y1);
				numericLabel(pOutImage, pos, horizMargin - spacing, y1, precision, size, color, 0.0);
			}
		}
	}
	return pOutImage;
}