コード例 #1
0
void NorwegianWoodStyle::polish(QPalette &palette)
{
    QColor brown(212, 140, 95);
    QColor beige(212, 140, 95);
    QColor slightlyOpaqueBlack(0, 0, 0, 63);
    
    QPixmap backgroundIamge(":/images/woodbackground.png");
    QPixmap buttonImage(":/images/woodbutton.png");
    QPixmap midImage = buttonImage;
    
    QPainter painter;
    painter.begin(&midImage);
    painter.setPen(Qt::NoPen);
    painter.fillRect(midImage.rect(), slightlyOpaqueBlack);
    painter.end();

    palette = QPalette(brown);
    
    palette.setBrush(QPalette::BrightText, Qt::white);
    palette.setBrush(QPalette::Base, beige);
    palette.setBrush(QPalette::Highlight, Qt::darkGreen);
    setTexture(palette, QPalette::Button, buttonImage); 
    setTexture(palette, QPalette::Mid, midImage); 
    setTexture(palette, QPalette::Window, backgroundIamge); 

    QBrush brush = palette.background();
    brush.setColor(brush.color().dark());

    palette.setBrush(QPalette::Disabled, QPalette::WindowText, brush);
    palette.setBrush(QPalette::Disabled, QPalette::Text, brush);
    palette.setBrush(QPalette::Disabled, QPalette::ButtonText, brush);
    palette.setBrush(QPalette::Disabled, QPalette::Base, brush);
    palette.setBrush(QPalette::Disabled, QPalette::Button, brush);
    palette.setBrush(QPalette::Disabled, QPalette::Mid, brush);
}
コード例 #2
0
ファイル: kqttester.cpp プロジェクト: okenjian/coding
void KQtTester::testImageEffects()
{
    QString report = QString("execute %1 times:\n").arg(g_nTimes);

    report += QString("none:\t%1\tms\n").arg(none());
    m_pPainter->translate(g_img.width() + 10, 0);
    report += QString("gray:\t%1\tms\n").arg(gray());
    m_pPainter->translate(g_img.width() + 10, 0);
    report += QString("watermark:\t%1\tms\n").arg(watermark());
    m_pPainter->translate(g_img.width() + 10, 0);
    report += QString("bilevel:\t%1\tms\n").arg(bilevel());

    m_pPainter->resetMatrix();
    m_pPainter->translate(0, g_img.height() + 10);
    report += QString("lightBlue:\t%1\tms\n").arg(lightBlue());
    m_pPainter->translate(g_img.width() + 10, 0);
    report += QString("darkBlue:\t%1\tms\n").arg(darkBlue());

    m_pPainter->resetMatrix();
    m_pPainter->translate(0, (g_img.height() + 10) * 2);
    report += QString("colorKey:\t%1\tms\n").arg(colorKey());
    m_pPainter->translate(g_img.width() + 10, 0);
    report += QString("brightness:\t%1\tms\n").arg(brightness());
    m_pPainter->translate(g_img.width() + 10, 0);
    report += QString("contrast:\t%1\tms\n").arg(contrast());
    m_pPainter->translate(g_img.width() + 10, 0);
    report += QString("brown:\t%1\tms\n").arg(brown());

	drawReport(report);
}
コード例 #3
0
ファイル: customstyle.cpp プロジェクト: loveywm/Hiway-v0.0.1
void CustomStyle::polish(QPalette &palette)
{
    QColor brown(Qt::white);
    QColor beige(Qt::transparent);
    QColor slightlyOpaqueBlack(0, 0, 0, 63);

//      QPainter painter;
//      painter.begin(&midImage);
//      painter.setPen(Qt::NoPen);
//      painter.fillRect(midImage.rect(), slightlyOpaqueBlack);
//      painter.end();

    palette = QPalette(brown);

    palette.setBrush(QPalette::BrightText, Qt::white);
    palette.setBrush(QPalette::Base, beige);
    palette.setBrush(QPalette::Highlight, Qt::darkGreen);
    palette.setBrush(QPalette::Button, beige);
    palette.setBrush(QPalette::ButtonText, Qt::white);
    palette.setBrush(QPalette::Mid, beige);
//	 palette.setBrush(QPalette::Window, QColor(158, 202, 243));
    palette.setBrush(QPalette::Window, beige);

    QBrush brush = palette.background();
    brush.setColor(brush.color().dark());

    palette.setBrush(QPalette::Disabled, QPalette::WindowText, brush);
    palette.setBrush(QPalette::Disabled, QPalette::Text, brush);
    palette.setBrush(QPalette::Disabled, QPalette::ButtonText, Qt::gray);
    palette.setBrush(QPalette::Disabled, QPalette::Base, brush);
    palette.setBrush(QPalette::Disabled, QPalette::Button, brush);
    palette.setBrush(QPalette::Disabled, QPalette::Mid, brush);
}
コード例 #4
0
		void paint(QPainter &painter){
			painter.setRenderHint(QPainter::Antialiasing,true);
			const T w=painter.device()->width();
			const T h=painter.device()->height();
			QPen base(QBrush(Qt::NoBrush),2);

			QPen brown(base);
			brown.setWidthF(0.01);
			brown.setStyle(Qt::SolidLine);
			brown.setColor(QColor("brown"));

			QPen green(base);
			green.setWidthF(0.04);
			green.setColor(QColor("green"));

			QPen purple(base);
			purple.setWidthF(0.01);
			purple.setColor(QColor("purple").darker());

			painter.translate(w/2,h/2);
			qreal s=qMin(w,h);
			painter.scale(s,s);

			T step=0.02;
			T gx=cx/step;
			gx-=floor(gx);
			gx*=-step;
			T gy=cy/step;
			gy-=floor(gy);
			gy*=-step;
			painter.setPen(brown);
			for(T y=gy-h;y<h;y+=step){
				painter.drawLine(QPointF(0,y-1),QPointF(w,y+1));
			}
			for(T x=gx-w;x<w;x+=step){
				painter.drawLine(QPointF(x-1,0),QPointF(x+1,h));
			}
			if(singleLimbMode){
				limbs[0]->paint(painter);
			}
			else{

				for(quint32 i=0;i<limbCount;++i){
					limbs[i]->paint(painter);
				}

				const T r=0.01;
				QPointF cob(cobx,coby);
				painter.setPen(green);
				painter.drawEllipse(cob,r,r);

				QPointF cog(cogx,cogy);
				painter.setPen(purple);
				painter.drawEllipse(cog,r,r);
			}

		}
コード例 #5
0
YellowToBrownScale::YellowToBrownScale() {
  _colors.resize(256);

  QColor yellow = Qt::yellow;
  QColor brown(139 ,69, 19);

  for (unsigned i=0; i<256; ++i) {
    _colors[i] = interpolate(yellow, brown, i/256.f);
  }
}
コード例 #6
0
ファイル: runBrownTown.C プロジェクト: dodo5575/scripts
int main(int argc, char* argv[]) {
  if ( argc != 4 ) {
    printf("Usage: %s configFile outputName randomSeed\n", argv[0]);
    printf("You entered %i arguments.\n", argc-1);
    return 0;
  }

  const char* configFile = argv[1];
  const char* outArg = argv[2];
  const long int randomSeed = atol(argv[3]);

  GrandBrownTown brown(configFile, outArg, randomSeed);
  printf("Running...\n");
  brown.run();

  return 0;
}
コード例 #7
0
void 												
World::build(void) {
	int num_samples = 1; 
	
	// view plane  
	  
	vp.set_hres(400);
	vp.set_vres(400);
	vp.set_pixel_size(0.5);
	vp.set_samples(num_samples);
	
	// the ambient light here is the same as the default set in the World
	// constructor, and can therefore be left out
	
	Ambient* ambient_ptr = new Ambient;
	ambient_ptr->scale_radiance(1.0);
	set_ambient_light(ambient_ptr); 

	background_color = black;			// default color - this can be left out
	
	tracer_ptr = new RayCast(this); 

	
	// camera
	
	Pinhole* pinhole_ptr = new Pinhole;
	pinhole_ptr->set_eye(0, 0, 500); 
	pinhole_ptr->set_lookat(0.0);
	pinhole_ptr->set_view_distance(600.0);
	pinhole_ptr->compute_uvw();     
	set_camera(pinhole_ptr);

	
	// light
	
	Directional* light_ptr1 = new Directional;
	light_ptr1->set_direction(100, 100, 200);
	light_ptr1->scale_radiance(3.0); 	
	add_light(light_ptr1);
	
	
	// colors

	RGBColor yellow(1, 1, 0);										// yellow
	RGBColor brown(0.71, 0.40, 0.16);								// brown
	RGBColor darkGreen(0.0, 0.41, 0.41);							// darkGreen
	RGBColor orange(1, 0.75, 0);									// orange
	RGBColor green(0, 0.6, 0.3);									// green
	RGBColor lightGreen(0.65, 1, 0.30);								// light green
	RGBColor darkYellow(0.61, 0.61, 0);								// dark yellow
	RGBColor lightPurple(0.65, 0.3, 1);								// light purple
	RGBColor darkPurple(0.5, 0, 1);									// dark purple
	RGBColor grey(0.25);											// grey
	
	
	// Matte material reflection coefficients - common to all materials
	
	float ka = 0.25;
	float kd = 0.75;
	
	
	// spheres
	
	Matte* matte_ptr1 = new Matte;   
	matte_ptr1->set_ka(ka);	
	matte_ptr1->set_kd(kd);
	matte_ptr1->set_cd(yellow);				
	Sphere*	sphere_ptr1 = new Sphere(Point3D(5, 3, 0), 30); 
	sphere_ptr1->set_material(matte_ptr1);	   							// yellow
	add_object(sphere_ptr1);
	
	Matte* matte_ptr2 = new Matte;
	matte_ptr2->set_ka(ka);	
	matte_ptr2->set_kd(kd);
	matte_ptr2->set_cd(brown);
	Sphere*	sphere_ptr2 = new Sphere(Point3D(45, -7, -60), 20); 
	sphere_ptr2->set_material(matte_ptr2);								// brown
	add_object(sphere_ptr2);
	

	Matte* matte_ptr3 = new Matte;
	matte_ptr3->set_ka(ka);	
	matte_ptr3->set_kd(kd);
	matte_ptr3->set_cd(darkGreen);	
	Sphere*	sphere_ptr3 = new Sphere(Point3D(40, 43, -100), 17); 
	sphere_ptr3->set_material(matte_ptr3);								// dark green
	add_object(sphere_ptr3);
	
	Matte* matte_ptr4 = new Matte;
	matte_ptr4->set_ka(ka);	
	matte_ptr4->set_kd(kd);
	matte_ptr4->set_cd(orange);
	Sphere*	sphere_ptr4 = new Sphere(Point3D(-20, 28, -15), 20); 
	sphere_ptr4->set_material(matte_ptr4);								// orange
	add_object(sphere_ptr4);
	
	Matte* matte_ptr5 = new Matte;
	matte_ptr5->set_ka(ka);	
	matte_ptr5->set_kd(kd);
	matte_ptr5->set_cd(green);
	Sphere*	sphere_ptr5 = new Sphere(Point3D(-25, -7, -35), 27); 			
	sphere_ptr5->set_material(matte_ptr5);								// green
	add_object(sphere_ptr5);
	
	Matte* matte_ptr6 = new Matte;
	matte_ptr6->set_ka(ka);	
	matte_ptr6->set_kd(kd);
	matte_ptr6->set_cd(lightGreen);
	Sphere*	sphere_ptr6 = new Sphere(Point3D(20, -27, -35), 25); 
	sphere_ptr6->set_material(matte_ptr6);								// light green
	add_object(sphere_ptr6);
	
	Matte* matte_ptr7 = new Matte;
	matte_ptr7->set_ka(ka);	
	matte_ptr7->set_kd(kd);
	matte_ptr7->set_cd(green);
	Sphere*	sphere_ptr7 = new Sphere(Point3D(35, 18, -35), 22); 
	sphere_ptr7->set_material(matte_ptr7);   							// green
	add_object(sphere_ptr7);
	
	Matte* matte_ptr8 = new Matte;
	matte_ptr8->set_ka(ka);	
	matte_ptr8->set_kd(kd);
	matte_ptr8->set_cd(brown);
	Sphere*	sphere_ptr8 = new Sphere(Point3D(-57, -17, -50), 15);  
	sphere_ptr8->set_material(matte_ptr8);								// brown
	add_object(sphere_ptr8);
	
	Matte* matte_ptr9 = new Matte;
	matte_ptr9->set_ka(ka);	
	matte_ptr9->set_kd(kd);
	matte_ptr9->set_cd(lightGreen);
	Sphere*	sphere_ptr9 = new Sphere(Point3D(-47, 16, -80), 23); 
	sphere_ptr9->set_material(matte_ptr9);								// light green
	add_object(sphere_ptr9);
		
	Matte* matte_ptr10 = new Matte;
	matte_ptr10->set_ka(ka);	
	matte_ptr10->set_kd(kd);
	matte_ptr10->set_cd(darkGreen);	
	Sphere*	sphere_ptr10 = new Sphere(Point3D(-15, -32, -60), 22); 
	sphere_ptr10->set_material(matte_ptr10);     						// dark green
	add_object(sphere_ptr10);
	
	Matte* matte_ptr11 = new Matte;
	matte_ptr11->set_ka(ka);	
	matte_ptr11->set_kd(kd);
	matte_ptr11->set_cd(darkYellow);
	Sphere*	sphere_ptr11 = new Sphere(Point3D(-35, -37, -80), 22); 
	sphere_ptr11->set_material(matte_ptr11);							// dark yellow
	add_object(sphere_ptr11);
	
	Matte* matte_ptr12 = new Matte;
	matte_ptr12->set_ka(ka);	
	matte_ptr12->set_kd(kd);
	matte_ptr12->set_cd(darkYellow);
	Sphere*	sphere_ptr12 = new Sphere(Point3D(10, 43, -80), 22); 
	sphere_ptr12->set_material(matte_ptr12);							// dark yellow
	add_object(sphere_ptr12);
	
	Matte* matte_ptr13 = new Matte;
	matte_ptr13->set_ka(ka);	
	matte_ptr13->set_kd(kd);
	matte_ptr13->set_cd(darkYellow);		
	Sphere*	sphere_ptr13 = new Sphere(Point3D(30, -7, -80), 10); 
	sphere_ptr13->set_material(matte_ptr13);
	add_object(sphere_ptr13);											// dark yellow (hidden)
	
	Matte* matte_ptr14 = new Matte;
	matte_ptr14->set_ka(ka);	
	matte_ptr14->set_kd(kd);
	matte_ptr14->set_cd(darkGreen);	
	Sphere*	sphere_ptr14 = new Sphere(Point3D(-40, 48, -110), 18); 
	sphere_ptr14->set_material(matte_ptr14); 							// dark green
	add_object(sphere_ptr14);
	
	Matte* matte_ptr15 = new Matte;
	matte_ptr15->set_ka(ka);	
	matte_ptr15->set_kd(kd);
	matte_ptr15->set_cd(brown);	
	Sphere*	sphere_ptr15 = new Sphere(Point3D(-10, 53, -120), 18); 
	sphere_ptr15->set_material(matte_ptr15); 							// brown
	add_object(sphere_ptr15);
	
	Matte* matte_ptr16 = new Matte;
	matte_ptr16->set_ka(ka);	
	matte_ptr16->set_kd(kd);
	matte_ptr16->set_cd(lightPurple);
	Sphere*	sphere_ptr16 = new Sphere(Point3D(-55, -52, -100), 10); 
	sphere_ptr16->set_material(matte_ptr16);							// light purple
	add_object(sphere_ptr16);
	
	Matte* matte_ptr17 = new Matte;
	matte_ptr17->set_ka(ka);	
	matte_ptr17->set_kd(kd);
	matte_ptr17->set_cd(brown);
	Sphere*	sphere_ptr17 = new Sphere(Point3D(5, -52, -100), 15); 		
	sphere_ptr17->set_material(matte_ptr17);							// browm
	add_object(sphere_ptr17);
	
	Matte* matte_ptr18 = new Matte;
	matte_ptr18->set_ka(ka);	
	matte_ptr18->set_kd(kd);
	matte_ptr18->set_cd(darkPurple);
	Sphere*	sphere_ptr18 = new Sphere(Point3D(-20, -57, -120), 15); 
	sphere_ptr18->set_material(matte_ptr18);							// dark purple
	add_object(sphere_ptr18);
	
	Matte* matte_ptr19 = new Matte;
	matte_ptr19->set_ka(ka);	
	matte_ptr19->set_kd(kd);
	matte_ptr19->set_cd(darkGreen);
	Sphere*	sphere_ptr19 = new Sphere(Point3D(55, -27, -100), 17); 
	sphere_ptr19->set_material(matte_ptr19);							// dark green
	add_object(sphere_ptr19);

	Matte* matte_ptr20 = new Matte;
	matte_ptr20->set_ka(ka);	
	matte_ptr20->set_kd(kd);
	matte_ptr20->set_cd(brown);
	Sphere*	sphere_ptr20 = new Sphere(Point3D(50, -47, -120), 15); 
	sphere_ptr20->set_material(matte_ptr20);							// browm
	add_object(sphere_ptr20);
	 
	Matte* matte_ptr21 = new Matte;
	matte_ptr21->set_ka(ka);	
	matte_ptr21->set_kd(kd);
	matte_ptr21->set_cd(lightPurple); 	
	Sphere*	sphere_ptr21 = new Sphere(Point3D(70, -42, -150), 10); 
	sphere_ptr21->set_material(matte_ptr21);							// light purple
	add_object(sphere_ptr21);
	
	Matte* matte_ptr22 = new Matte;
	matte_ptr22->set_ka(ka);	
	matte_ptr22->set_kd(kd);
	matte_ptr22->set_cd(lightPurple);
	Sphere*	sphere_ptr22 = new Sphere(Point3D(5, 73, -130), 12); 
	sphere_ptr22->set_material(matte_ptr22);							// light purple
	add_object(sphere_ptr22);
	
	Matte* matte_ptr23 = new Matte;
	matte_ptr23->set_ka(ka);	
	matte_ptr23->set_kd(kd);
	matte_ptr23->set_cd(darkPurple);
	Sphere*	sphere_ptr23 = new Sphere(Point3D(66, 21, -130), 13); 			
	sphere_ptr23->set_material(matte_ptr23);							// dark purple
	add_object(sphere_ptr23);	
	
	Matte* matte_ptr24 = new Matte;
	matte_ptr24->set_ka(ka);	
	matte_ptr24->set_kd(kd);
	matte_ptr24->set_cd(lightPurple);  
	Sphere*	sphere_ptr24 = new Sphere(Point3D(72, -12, -140), 12); 
	sphere_ptr24->set_material(matte_ptr24);							// light purple
	add_object(sphere_ptr24);
	
	Matte* matte_ptr25 = new Matte;
	matte_ptr25->set_ka(ka);	
	matte_ptr25->set_kd(kd);
	matte_ptr25->set_cd(green);
	Sphere*	sphere_ptr25 = new Sphere(Point3D(64, 5, -160), 11); 			
	sphere_ptr25->set_material(matte_ptr25);					 		// green
	add_object(sphere_ptr25);
	  
	Matte* matte_ptr26 = new Matte;
	matte_ptr26->set_ka(ka);	
	matte_ptr26->set_kd(kd);
	matte_ptr26->set_cd(lightPurple);
	Sphere*	sphere_ptr26 = new Sphere(Point3D(55, 38, -160), 12); 		
	sphere_ptr26->set_material(matte_ptr26);							// light purple
	add_object(sphere_ptr26);
	
	Matte* matte_ptr27 = new Matte;
	matte_ptr27->set_ka(ka);	
	matte_ptr27->set_kd(kd);
	matte_ptr27->set_cd(lightPurple);
	Sphere*	sphere_ptr27 = new Sphere(Point3D(-73, -2, -160), 12); 		
	sphere_ptr27->set_material(matte_ptr27);							// light purple
	add_object(sphere_ptr27);
	 
	Matte* matte_ptr28 = new Matte;
	matte_ptr28->set_ka(ka);	
	matte_ptr28->set_kd(kd);
	matte_ptr28->set_cd(darkPurple);
	Sphere*	sphere_ptr28 = new Sphere(Point3D(30, -62, -140), 15); 
	sphere_ptr28->set_material(matte_ptr28); 							// dark purple
	add_object(sphere_ptr28);
	
	Matte* matte_ptr29 = new Matte;
	matte_ptr29->set_ka(ka);	
	matte_ptr29->set_kd(kd);
	matte_ptr29->set_cd(darkPurple);
	Sphere*	sphere_ptr29 = new Sphere(Point3D(25, 63, -140), 15); 
	sphere_ptr29->set_material(matte_ptr29);							// dark purple
	add_object(sphere_ptr29);
	
	Matte* matte_ptr30 = new Matte;
	matte_ptr30->set_ka(ka);	
	matte_ptr30->set_kd(kd);
	matte_ptr30->set_cd(darkPurple);
	Sphere*	sphere_ptr30 = new Sphere(Point3D(-60, 46, -140), 15);  
	sphere_ptr30->set_material(matte_ptr30); 							// dark purple
	add_object(sphere_ptr30);
	
	Matte* matte_ptr31 = new Matte;
	matte_ptr31->set_ka(ka);	
	matte_ptr31->set_kd(kd);
	matte_ptr31->set_cd(lightPurple);
	Sphere*	sphere_ptr31 = new Sphere(Point3D(-30, 68, -130), 12); 
	sphere_ptr31->set_material(matte_ptr31); 							// light purple
	add_object(sphere_ptr31);
	
	Matte* matte_ptr32 = new Matte;
	matte_ptr32->set_ka(ka);	
	matte_ptr32->set_kd(kd);
	matte_ptr32->set_cd(green);
	Sphere*	sphere_ptr32 = new Sphere(Point3D(58, 56, -180), 11);   
	sphere_ptr32->set_material(matte_ptr32);							//  green
	add_object(sphere_ptr32);
	
	Matte* matte_ptr33 = new Matte;
	matte_ptr33->set_ka(ka);	
	matte_ptr33->set_kd(kd);
	matte_ptr33->set_cd(green);
	Sphere*	sphere_ptr33 = new Sphere(Point3D(-63, -39, -180), 11); 
	sphere_ptr33->set_material(matte_ptr33);							// green 
	add_object(sphere_ptr33);
	
	Matte* matte_ptr34 = new Matte;
	matte_ptr34->set_ka(ka);	
	matte_ptr34->set_kd(kd);
	matte_ptr34->set_cd(lightPurple);
	Sphere*	sphere_ptr34 = new Sphere(Point3D(46, 68, -200), 10); 	
	sphere_ptr34->set_material(matte_ptr34);							// light purple
	add_object(sphere_ptr34);
	
	Matte* matte_ptr35 = new Matte;
	matte_ptr35->set_ka(ka);	
	matte_ptr35->set_kd(kd);
	matte_ptr35->set_cd(lightPurple);
	Sphere*	sphere_ptr35 = new Sphere(Point3D(-3, -72, -130), 12); 
	sphere_ptr35->set_material(matte_ptr35);							// light purple
	add_object(sphere_ptr35);
	
	
	// vertical plane
	
	Matte* matte_ptr36 = new Matte;
	matte_ptr36->set_ka(ka);	
	matte_ptr36->set_kd(kd);
	matte_ptr36->set_cd(grey);
	Plane* plane_ptr = new Plane(Point3D(0, 0, -150), Normal(0, 0, 1));
	plane_ptr->set_material(matte_ptr36);
	add_object (plane_ptr);
}
コード例 #8
0
void 												
World::build(void) {
	int num_samples = 16;

	vp.set_hres(600);
	vp.set_vres(600);
	vp.set_pixel_size(0.5);
	vp.set_samples(num_samples);  
//	vp.set_gamut_display(true);        // for Figure 14.23(b)
	
	tracer_ptr = new RayCast(this);	
	
	Pinhole* pinhole_ptr = new Pinhole;
	pinhole_ptr->set_eye(0, 0, 10000);
	pinhole_ptr->set_lookat(0.0);   
	pinhole_ptr->set_view_distance(15000);	
	pinhole_ptr->compute_uvw(); 
	set_camera(pinhole_ptr);
	
	Directional* light_ptr = new Directional;
	light_ptr->set_direction(100, 100, 200);
	light_ptr->set_color(1.0, 1.0, 1.0); 	
	light_ptr->scale_radiance(4.5); 	  		
	add_light(light_ptr);
	
	
	// colors

	RGBColor yellow(1, 1, 0);										// yellow
	RGBColor brown(0.71, 0.40, 0.16);								// brown
	RGBColor dark_green(0.0, 0.41, 0.41);							// dark_green
	RGBColor orange(1, 0.75, 0);									// orange
	RGBColor green(0, 0.6, 0.3);									// green
	RGBColor light_green(0.65, 1, 0.30);							// light green
	RGBColor dark_yellow(0.61, 0.61, 0);							// dark yellow
	RGBColor light_purple(0.65, 0.3, 1);							// light purple
	RGBColor dark_purple(0.5, 0, 1);								// dark purple
	
	
	// Matt material reflection coefficients
	
	float ka = 0.25;
	float kd = 0.75;
	
	
	// spheres
	
	Matte* matte_ptr1 = new Matte;
	matte_ptr1->set_ka(ka);	
	matte_ptr1->set_kd(kd);
	matte_ptr1->set_cd(yellow);				
	Sphere*	sphere_ptr1 = new Sphere(Point3D(5, 3, 0), 30); 
	sphere_ptr1->set_material(matte_ptr1);	   							// yellow
	add_object(sphere_ptr1);
	
	Matte* matte_ptr2 = new Matte;
	matte_ptr2->set_ka(ka);	
	matte_ptr2->set_kd(kd);
	matte_ptr2->set_cd(brown);
	Sphere*	sphere_ptr2 = new Sphere(Point3D(45, -7, -60), 20); 
	sphere_ptr2->set_material(matte_ptr2);								// brown
	add_object(sphere_ptr2);
	

	Matte* matte_ptr3 = new Matte;
	matte_ptr3->set_ka(ka);	
	matte_ptr3->set_kd(kd);
	matte_ptr3->set_cd(dark_green);	
	Sphere*	sphere_ptr3 = new Sphere(Point3D(40, 43, -100), 17); 
	sphere_ptr3->set_material(matte_ptr3);								// dark green
	add_object(sphere_ptr3);
	
	Matte* matte_ptr4 = new Matte;
	matte_ptr4->set_ka(ka);	
	matte_ptr4->set_kd(kd);
	matte_ptr4->set_cd(orange);
	Sphere*	sphere_ptr4 = new Sphere(Point3D(-20, 28, -15), 20); 
	sphere_ptr4->set_material(matte_ptr4);								// orange
	add_object(sphere_ptr4);
	
	Matte* matte_ptr5 = new Matte;
	matte_ptr5->set_ka(ka);	
	matte_ptr5->set_kd(kd);
	matte_ptr5->set_cd(green);
	Sphere*	sphere_ptr5 = new Sphere(Point3D(-25, -7, -35), 27); 			
	sphere_ptr5->set_material(matte_ptr5);								// green
	add_object(sphere_ptr5);
	
	Matte* matte_ptr6 = new Matte;
	matte_ptr6->set_ka(ka);	
	matte_ptr6->set_kd(kd);
	matte_ptr6->set_cd(light_green);
	Sphere*	sphere_ptr6 = new Sphere(Point3D(20, -27, -35), 25); 
	sphere_ptr6->set_material(matte_ptr6);								// light green
	add_object(sphere_ptr6);
	
	Matte* matte_ptr7 = new Matte;
	matte_ptr7->set_ka(ka);	
	matte_ptr7->set_kd(kd);
	matte_ptr7->set_cd(green);
	Sphere*	sphere_ptr7 = new Sphere(Point3D(35, 18, -35), 22); 
	sphere_ptr7->set_material(matte_ptr7);   							// green
	add_object(sphere_ptr7);
	
	Matte* matte_ptr8 = new Matte;
	matte_ptr8->set_ka(ka);	
	matte_ptr8->set_kd(kd);
	matte_ptr8->set_cd(brown);
	Sphere*	sphere_ptr8 = new Sphere(Point3D(-57, -17, -50), 15);  
	sphere_ptr8->set_material(matte_ptr8);								// brown
	add_object(sphere_ptr8);
	
	Matte* matte_ptr9 = new Matte;
	matte_ptr9->set_ka(ka);	
	matte_ptr9->set_kd(kd);
	matte_ptr9->set_cd(light_green);
	Sphere*	sphere_ptr9 = new Sphere(Point3D(-47, 16, -80), 23); 
	sphere_ptr9->set_material(matte_ptr9);								// light green
	add_object(sphere_ptr9);
		
	Matte* matte_ptr10 = new Matte;
	matte_ptr10->set_ka(ka);	
	matte_ptr10->set_kd(kd);
	matte_ptr10->set_cd(dark_green);	
	Sphere*	sphere_ptr10 = new Sphere(Point3D(-15, -32, -60), 22); 
	sphere_ptr10->set_material(matte_ptr10);     						// dark green
	add_object(sphere_ptr10);
	
	Matte* matte_ptr11 = new Matte;
	matte_ptr11->set_ka(ka);	
	matte_ptr11->set_kd(kd);
	matte_ptr11->set_cd(dark_yellow);
	Sphere*	sphere_ptr11 = new Sphere(Point3D(-35, -37, -80), 22); 
	sphere_ptr11->set_material(matte_ptr11);							// dark yellow
	add_object(sphere_ptr11);
	
	Matte* matte_ptr12 = new Matte;
	matte_ptr12->set_ka(ka);	
	matte_ptr12->set_kd(kd);
	matte_ptr12->set_cd(dark_yellow);
	Sphere*	sphere_ptr12 = new Sphere(Point3D(10, 43, -80), 22); 
	sphere_ptr12->set_material(matte_ptr12);							// dark yellow
	add_object(sphere_ptr12);
	
	Matte* matte_ptr13 = new Matte;
	matte_ptr13->set_ka(ka);	
	matte_ptr13->set_kd(kd);
	matte_ptr13->set_cd(dark_yellow);		
	Sphere*	sphere_ptr13 = new Sphere(Point3D(30, -7, -80), 10); 
	sphere_ptr13->set_material(matte_ptr13);
	add_object(sphere_ptr13);											// dark yellow (hidden)
	
	Matte* matte_ptr14 = new Matte;
	matte_ptr14->set_ka(ka);	
	matte_ptr14->set_kd(kd);
	matte_ptr14->set_cd(dark_green);	
	Sphere*	sphere_ptr14 = new Sphere(Point3D(-40, 48, -110), 18); 
	sphere_ptr14->set_material(matte_ptr14); 							// dark green
	add_object(sphere_ptr14);
	
	Matte* matte_ptr15 = new Matte;
	matte_ptr15->set_ka(ka);	
	matte_ptr15->set_kd(kd);
	matte_ptr15->set_cd(brown);	
	Sphere*	sphere_ptr15 = new Sphere(Point3D(-10, 53, -120), 18); 
	sphere_ptr15->set_material(matte_ptr15); 							// brown
	add_object(sphere_ptr15);
	
	Matte* matte_ptr16 = new Matte;
	matte_ptr16->set_ka(ka);	
	matte_ptr16->set_kd(kd);
	matte_ptr16->set_cd(light_purple);
	Sphere*	sphere_ptr16 = new Sphere(Point3D(-55, -52, -100), 10); 
	sphere_ptr16->set_material(matte_ptr16);							// light purple
	add_object(sphere_ptr16);
	
	Matte* matte_ptr17 = new Matte;
	matte_ptr17->set_ka(ka);	
	matte_ptr17->set_kd(kd);
	matte_ptr17->set_cd(brown);
	Sphere*	sphere_ptr17 = new Sphere(Point3D(5, -52, -100), 15); 		
	sphere_ptr17->set_material(matte_ptr17);							// browm
	add_object(sphere_ptr17);
	
	Matte* matte_ptr18 = new Matte;
	matte_ptr18->set_ka(ka);	
	matte_ptr18->set_kd(kd);
	matte_ptr18->set_cd(dark_purple);
	Sphere*	sphere_ptr18 = new Sphere(Point3D(-20, -57, -120), 15); 
	sphere_ptr18->set_material(matte_ptr18);							// dark purple
	add_object(sphere_ptr18);
	
	Matte* matte_ptr19 = new Matte;
	matte_ptr19->set_ka(ka);	
	matte_ptr19->set_kd(kd);
	matte_ptr19->set_cd(dark_green);
	Sphere*	sphere_ptr19 = new Sphere(Point3D(55, -27, -100), 17); 
	sphere_ptr19->set_material(matte_ptr19);							// dark green
	add_object(sphere_ptr19);

	Matte* matte_ptr20 = new Matte;
	matte_ptr20->set_ka(ka);	
	matte_ptr20->set_kd(kd);
	matte_ptr20->set_cd(brown);
	Sphere*	sphere_ptr20 = new Sphere(Point3D(50, -47, -120), 15); 
	sphere_ptr20->set_material(matte_ptr20);							// browm
	add_object(sphere_ptr20);
	 
	Matte* matte_ptr21 = new Matte;
	matte_ptr21->set_ka(ka);	
	matte_ptr21->set_kd(kd);
	matte_ptr21->set_cd(light_purple); 	
	Sphere*	sphere_ptr21 = new Sphere(Point3D(70, -42, -150), 10); 
	sphere_ptr21->set_material(matte_ptr21);							// light purple
	add_object(sphere_ptr21);
	
	Matte* matte_ptr22 = new Matte;
	matte_ptr22->set_ka(ka);	
	matte_ptr22->set_kd(kd);
	matte_ptr22->set_cd(light_purple);
	Sphere*	sphere_ptr22 = new Sphere(Point3D(5, 73, -130), 12); 
	sphere_ptr22->set_material(matte_ptr22);							// light purple
	add_object(sphere_ptr22);
	
	Matte* matte_ptr23 = new Matte;
	matte_ptr23->set_ka(ka);	
	matte_ptr23->set_kd(kd);
	matte_ptr23->set_cd(dark_purple);
	Sphere*	sphere_ptr23 = new Sphere(Point3D(66, 21, -130), 13); 			
	sphere_ptr23->set_material(matte_ptr23);							// dark purple
	add_object(sphere_ptr23);	
	
	Matte* matte_ptr24 = new Matte;
	matte_ptr24->set_ka(ka);	
	matte_ptr24->set_kd(kd);
	matte_ptr24->set_cd(light_purple);  
	Sphere*	sphere_ptr24 = new Sphere(Point3D(72, -12, -140), 12); 
	sphere_ptr24->set_material(matte_ptr24);							// light purple
	add_object(sphere_ptr24);
	
	Matte* matte_ptr25 = new Matte;
	matte_ptr25->set_ka(ka);	
	matte_ptr25->set_kd(kd);
	matte_ptr25->set_cd(green);
	Sphere*	sphere_ptr25 = new Sphere(Point3D(64, 5, -160), 11); 			
	sphere_ptr25->set_material(matte_ptr25);					 		// green
	add_object(sphere_ptr25);
	  
	Matte* matte_ptr26 = new Matte;
	matte_ptr26->set_ka(ka);	
	matte_ptr26->set_kd(kd);
	matte_ptr26->set_cd(light_purple);
	Sphere*	sphere_ptr26 = new Sphere(Point3D(55, 38, -160), 12); 		
	sphere_ptr26->set_material(matte_ptr26);							// light purple
	add_object(sphere_ptr26);
	
	Matte* matte_ptr27 = new Matte;
	matte_ptr27->set_ka(ka);	
	matte_ptr27->set_kd(kd);
	matte_ptr27->set_cd(light_purple);
	Sphere*	sphere_ptr27 = new Sphere(Point3D(-73, -2, -160), 12); 		
	sphere_ptr27->set_material(matte_ptr27);							// light purple
	add_object(sphere_ptr27);
	 
	Matte* matte_ptr28 = new Matte;
	matte_ptr28->set_ka(ka);	
	matte_ptr28->set_kd(kd);
	matte_ptr28->set_cd(dark_purple);
	Sphere*	sphere_ptr28 = new Sphere(Point3D(30, -62, -140), 15); 
	sphere_ptr28->set_material(matte_ptr28); 							// dark purple
	add_object(sphere_ptr28);
	
	Matte* matte_ptr29 = new Matte;
	matte_ptr29->set_ka(ka);	
	matte_ptr29->set_kd(kd);
	matte_ptr29->set_cd(dark_purple);
	Sphere*	sphere_ptr29 = new Sphere(Point3D(25, 63, -140), 15); 
	sphere_ptr29->set_material(matte_ptr29);							// dark purple
	add_object(sphere_ptr29);
	
	Matte* matte_ptr30 = new Matte;
	matte_ptr30->set_ka(ka);	
	matte_ptr30->set_kd(kd);
	matte_ptr30->set_cd(dark_purple);
	Sphere*	sphere_ptr30 = new Sphere(Point3D(-60, 46, -140), 15);  
	sphere_ptr30->set_material(matte_ptr30); 							// dark purple
	add_object(sphere_ptr30);
	
	Matte* matte_ptr31 = new Matte;
	matte_ptr31->set_ka(ka);	
	matte_ptr31->set_kd(kd);
	matte_ptr31->set_cd(light_purple);
	Sphere*	sphere_ptr31 = new Sphere(Point3D(-30, 68, -130), 12); 
	sphere_ptr31->set_material(matte_ptr31); 							// light purple
	add_object(sphere_ptr31);
	
	Matte* matte_ptr32 = new Matte;
	matte_ptr32->set_ka(ka);	
	matte_ptr32->set_kd(kd);
	matte_ptr32->set_cd(green);
	Sphere*	sphere_ptr32 = new Sphere(Point3D(58, 56, -180), 11);   
	sphere_ptr32->set_material(matte_ptr32);							//  green
	add_object(sphere_ptr32);
	
	Matte* matte_ptr33 = new Matte;
	matte_ptr33->set_ka(ka);	
	matte_ptr33->set_kd(kd);
	matte_ptr33->set_cd(green);
	Sphere*	sphere_ptr33 = new Sphere(Point3D(-63, -39, -180), 11); 
	sphere_ptr33->set_material(matte_ptr33);							// green 
	add_object(sphere_ptr33);
	
	Matte* matte_ptr34 = new Matte;
	matte_ptr34->set_ka(ka);	
	matte_ptr34->set_kd(kd);
	matte_ptr34->set_cd(light_purple);
	Sphere*	sphere_ptr34 = new Sphere(Point3D(46, 68, -200), 10); 	
	sphere_ptr34->set_material(matte_ptr34);							// light purple
	add_object(sphere_ptr34);
	
	Matte* matte_ptr35 = new Matte;
	matte_ptr35->set_ka(ka);	
	matte_ptr35->set_kd(kd);
	matte_ptr35->set_cd(light_purple);
	Sphere*	sphere_ptr35 = new Sphere(Point3D(-3, -72, -130), 12); 
	sphere_ptr35->set_material(matte_ptr35);							// light purple
	add_object(sphere_ptr35);
	
}
コード例 #9
0
int main(int argc, char* argv[])
{
  if ( argc != 11 ) {
    printf("Usage: %s gridFile gateGridFile steps diffusion dt externalForceZ num outPeriod gateZ outName\n", argv[0]);
    printf("You entered %i arguments.\n", argc);
    return 0;
  }
  const double kT = 1.0;

  const char* gridFile = argv[1];
  const char* gateGridFile = argv[2];
  const char* outName = argv[argc-1];

  const long int steps = atol(argv[3]);
  const double diffusion = strtod(argv[4],NULL);
  const double dt = strtod(argv[5],NULL);
  const double externalForceZ = strtod(argv[6],NULL);
  const int num = atoi(argv[7]);
  const int outPeriod = atoi(argv[8]);
  const double gateZ = strtod(argv[9],NULL);

  printf("Brownian Dynamics initiated with command:\n");
  for (int i = 0; i < argc; i++) printf("%s ", argv[i]);
  printf("\n");
  printf("Running %d Brownian Dynamics steps with grid %s, diffusion constant %g, and timestep %g.\n", steps, argv[1], diffusion, dt);
  printf("The external force along z is %f.\n", externalForceZ);
  printf("There are %d particles.\n", num);
  printf("The output period is %d.\n", outPeriod);
  printf("A typical displacement in one output period is %g.\n", sqrt(2*diffusion*dt*outPeriod));
  printf("Periodic boundaries in x, y, and z.\n");
  printf("\nParameter list: \n");
  printf("gridFile %s\n", gridFile);
  printf("gateGridFile %s\n", gateGridFile);
  printf("steps %d\n", steps);
  printf("diffusion %.10g\n", diffusion);
  printf("dt %.10g\n", dt);
  printf("externalForceZ %.10g\n", externalForceZ);
  printf("num %d\n", num);
  printf("outPeriod %d\n", outPeriod);
  printf("gateZ %.10g\n", gateZ);
  printf("outName %s\n\n", outName);

  char outTrajFile[256];
  sprintf(outTrajFile, "traj_%s.pdb", outName);
 
  // Load the potential grid.
  Grid pot(gridFile);
  Grid gate(gateGridFile);
  Vector3 extForce = Vector3(0, 0, externalForceZ);

  // Instantiate the Brownian Dynamics object.
  BrownTown brown(pot, gate, diffusion, kT, dt);
  brown.setPeriodic(1,1,1);
  
  // Seed the random number generator.
  int seed = (unsigned int)time((time_t *)NULL);
  printf("Random number generator seed: %i\n", seed);
  Random randoGen(seed);

  // Set initial conditions.
  Vector3* r = new Vector3[num];
  for (int i = 0; i < num; i++) {
    //r[i] = 0.5*(pot.getOrigin() + pot.getCenter());
    r[i] = pot.getCenter();
  }
  bool gated0 = false;

  Vector3 sysDim = pot.getExtent();
  writePdbTraj(outTrajFile, r, num, sysDim, (gated0)?1.0:0.0); 

  // Run the Brownian Dynamics steps.
  for (long int s = 0; s < steps; s++) {
    double t = dt*s;
    
    int currEvents = 0;
    bool gated = false;
    for (int i = 0; i < num; i++) {
      Vector3 rando = randoGen.gaussian_vector();
      r[i] = brown.step(r[i], extForce, rando, gated0);
      if (fabs(r[i].z) < gateZ) gated = true;
    }
    gated0 = gated;

     if (s % outPeriod == 0) {
	double percent = (100.0*s)/steps;
	printf("%.2f percent complete, step %d\n", percent, s);
      
	appendPdbTraj(outTrajFile, r, num, sysDim, (gated0)?1.0:0.0);    
      }
  }

  delete[] r;

  return 0;
}
コード例 #10
0
ファイル: GameScreen.cpp プロジェクト: Owarai/BadSnakeGame
void GameScreen::paintEvent(QPaintEvent * event) {


	if (r >= 255) {
		r_dir = RANGE_DOWN;
		g_dir = RANGE_UP;
		b_dir = RANGE_IDLE;
	}

	if (g >= 255) {
		r_dir = RANGE_IDLE;
		g_dir = RANGE_DOWN;
		b_dir = RANGE_UP;
	}

	if (b >= 255) {
		r_dir = RANGE_UP;
		g_dir = RANGE_IDLE;
		b_dir = RANGE_DOWN;
	}

	if (r_dir == RANGE_UP) {
		r += 5;
	}
	else if (r_dir == RANGE_DOWN){
		r -= 5;
	}
	if (g_dir == RANGE_UP) {
		g += 5;
	}
	else if (g_dir == RANGE_DOWN){
		g -= 5;
	}
	if (b_dir == RANGE_UP) {
		b += 5;
	}
	else if (b_dir == RANGE_DOWN) {
		b -= 5;
	}

	QColor white(255, 255, 255);
	QColor darkWhite(250, 250, 250);
	QColor pink(255, 192, 203);
	QColor brown(97, 25, 11);
	QColor rainbow(r, g, b);
	QColor neg_rainbow(255 - r, 255 - g, 255 - b);
	
	QPainter painter(this);
	painter.fillRect(0, 0, width(), height(), darkWhite);
	painter.setPen(QPen(Qt::black, 1));

	if (mode == MODE_MENU) {
		painter.drawText(400, 300, "Press the Space Key to Start");
	}
	else if (mode == MODE_RUNNING) {

		//draw coffee
		painter.setPen(QPen(darkWhite, 1));
		for (int i = 0; i < coffee_loc.size(); i++) {
			painter.drawRect(coffee_loc[i].first * sq_s, coffee_loc[i].second * sq_s, sq_s, sq_s);
			painter.fillRect(coffee_loc[i].first * sq_s + 1, coffee_loc[i].second * sq_s + 1, sq_s - 1, sq_s - 1, rainbow);
		}

		//draw fruit
		painter.setPen(QPen(pink, 1));
		painter.setBrush(pink);
		for (int i = 0; i < fruit_loc.size(); i++) {
			painter.drawEllipse((fruit_loc[i].first * sq_s), (fruit_loc[i].second * sq_s), sq_s, sq_s);
		}

		//draw snake
		painter.setPen(QPen(darkWhite, 1));
		for (int i = 0; i < body.size(); i++) {
			painter.drawRect(body[i].first * sq_s, body[i].second * sq_s, sq_s, sq_s);
			painter.fillRect(body[i].first * sq_s + 1, body[i].second * sq_s + 1, sq_s - 1, sq_s - 1,neg_rainbow);
		}

	}
	else if (mode == MODE_GAMEOVER) {
		painter.setPen(QPen(Qt::lightGray, 1));
		for (int i = 0; i < body.size(); i++) {
			painter.drawRect(body[i].first * sq_s, body[i].second * sq_s, sq_s, sq_s);
			painter.fillRect(body[i].first * sq_s + 1, body[i].second * sq_s + 1, sq_s - 1, sq_s - 1, Qt::gray);
		}
		painter.setPen(QPen(Qt::red, 1));
		painter.drawText(400, 300, "GAMEOVER");
	}




	


}
コード例 #11
0
ファイル: brownTownCluster.C プロジェクト: dodo5575/scripts
int main(int argc, char* argv[])
{
  if ( argc != 4 ) {
    printf("Usage: %s configFile outputName randomSeed\n", argv[0]);
    printf("You entered %i arguments.\n", argc-1);
    return 0;
  }
   
  const char* configFile = argv[1];
  const char* outArg = argv[2];
  const long int randomSeed = atol(argv[3]);

  char outTrajFile[256];
  char outCurrFile[256];
  sprintf(outTrajFile, "%s.pdb", outArg);
  sprintf(outCurrFile, "curr_%s.dat", outArg);

  printf("Brownian Dynamics initiated with command:\n");
  for (int i = 0; i < argc; i++) printf("%s\n", argv[i]);
 
  // Read the parameter file.
  Reader config(configFile);
  printf("Read config file %s.\n", configFile);
  const int numParams = config.length();
  const int numParts = config.countParameter("particle");
  BrownianParticle* part = new BrownianParticle[numParts];
  String* partGridFile = new String[numParts];
  
  // Set the defaults.
  String outName("out");
  double timestep = 1e-4;
  long int steps = 100;
  int interparticleForce = 1;
  int fullElect = 1;
  double kT = 1.0;
  double coulombConst = 566.440698/92.0;
  double electricField = 0.0;
  double cutoff = 10.0;
  int outPeriod = 200;
  
  // Set other parameters.
  const int decompPeriod = 4;
  const double switchLen = 2.0;
  const double switchStart = cutoff-switchLen;
  const double maxInitialPot = 0.5;

  int currPart = -1;
  for (int i = 0; i < numParams; i++) {
    String param = config.getParameter(i);
    String value = config.getValue(i);

    if (param == String("outName")) outName = value;
    else if (param == String("timestep")) timestep = strtod(value.val(), NULL);
    else if (param == String("steps")) steps = atol(value.val());
    else if (param == String("interparticleForce")) interparticleForce = atoi(value.val());
    else if (param == String("fullElect")) fullElect = atoi(value.val());
    else if (param == String("kT")) kT = strtod(value.val(), NULL);
    else if (param == String("coulombConst")) coulombConst = strtod(value.val(), NULL);
    else if (param == String("electricField")) electricField = strtod(value.val(), NULL);
    else if (param == String("cutoff")) cutoff = strtod(value.val(), NULL);
    else if (param == String("outPeriod")) outPeriod = atoi(value.val());
    else if (param == String("particle")) { currPart++; part[currPart] = BrownianParticle(value); }
    else if (param == String("num")) part[currPart].num = atoi(value.val());
    else if (param == String("gridFile")) partGridFile[currPart] = value;
    else if (param == String("diffusion")) part[currPart].diffusion = strtod(value.val(), NULL);
    else if (param == String("charge")) part[currPart].charge = strtod(value.val(), NULL);
    else if (param == String("radius")) part[currPart].radius = strtod(value.val(), NULL);
    else if (param == String("eps")) part[currPart].eps = strtod(value.val(), NULL);
  }
   
  // Write the parameters.
  printf("\nParameters: \n");
  printf("outName %s\n", outName.val());
  printf("timestep %.10g\n", timestep);
  printf("steps %ld\n", steps);
  printf("interparticleForce %d\n", interparticleForce);
  printf("fullElect %d\n", fullElect);
  printf("kT %.10g\n", kT);
  printf("coulombConst %.10g\n", coulombConst);
  printf("electricField %.10g\n", electricField);
  printf("cutoff %.10g\n", cutoff);
  printf("outPeriod %d\n", outPeriod);
  
  // Write the particles.
  printf("\nParticles:\n");
  
  for (int i = 0; i < numParts; i++) {
    printf("particle %s\n", part[i].name.val());
    printf("num %d\n", part[i].num);
    printf("gridFile %s\n", partGridFile[i].val());
    printf("diffusion %.10g\n", part[i].diffusion);
    printf("charge %.10g\n", part[i].charge);
    printf("radius %.10g\n", part[i].radius);
    printf("eps %.10g\n\n", part[i].eps);
  }

  // Load the potential grids.
  printf("Loading the potential grids...\n");
  for (int i = 0; i < numParts; i++) {
    part[i].grid = new Grid(partGridFile[i].val());
    printf("Loaded %s.\n", partGridFile[i].val());
    printf("System size %s.\n", part[i].grid->getExtent().toString().val());
  }

  // Instantiate the Brownian Dynamics object.
  BrownTown brown(kT, timestep, *(part[0].grid));
  brown.setPeriodic(1,1,1);

 // Seed the random number generator. 
 long int randomSeed1 = randomSeed;
  for (int i = 0; i < 4; i++) randomSeed1 *= randomSeed1 + 1;
  int seed = (unsigned int)time((time_t *)NULL) + randomSeed1;
  printf("\nRandom number generator seed: %i\n", seed);
  Random randoGen(seed);

  // Get the total number of particles.
  int num = 0;
  for (int i = 0; i < numParts; i++) num += part[i].num;

  // Get the system dimensions.
  Vector3 sysDim = part[0].grid->getExtent();
  Vector3 origin = part[0].grid->getOrigin();
  Vector3 destin = part[0].grid->getDestination();
  
  // Set initial conditions.
  Vector3* pos = new Vector3[num];
  Vector3* pos1 = new Vector3[num];
  Vector3* posLast = new Vector3[num];
  int* type = new int[num];
  String* name = new String[num];
  int pn = 0;
  int p = 0;
  for (int i = 0; i < num; i++) {
    type[i] = p;
    name[i] = part[p].name;

    // Get the initial positions.
     do {
      pos[i] = brown.wrap(Vector3(sysDim.x*randoGen.uniform(),
				  sysDim.y*randoGen.uniform(),
				  sysDim.z*randoGen.uniform()));
    } while (part[type[i]].grid->interpolatePotential(pos[i]) > maxInitialPot);
    //pos[i] = part[0].grid->getCenter();
    pos1[i] = pos[i];
    posLast[i] = pos[i];

    pn++;
    if (pn >= part[p].num) {
      p++;
      pn = 0;
    }

  }

  // Trajectory PDB
  writePdbTraj(outTrajFile, pos, name, num, sysDim, 0.0); 
  //FILE* out = fopen(outCurrFile, "w");

  // Prepare the force object.
  ComputeForce internal(num, part, numParts, *(part[0].grid), switchStart, switchLen, coulombConst);
  internal.decompose(pos);
  Vector3* forceInternal = new Vector3[num];
  for (int i = 0; i < num; i++) forceInternal[i] = 0.0;
  Vector3 rando = randoGen.gaussian_vector();
  ////////////////////////////////////////////////////////////////
  // Run the Brownian Dynamics steps.
  clock_t clock0 = clock();
  for (long int s = 0; s < steps; s++) {
    // Compute the internal forces.
    if (interparticleForce) {
       switch (fullElect) {
      case 0:
	// Remake the cell decomposition.
	if (s % decompPeriod == 0) internal.decompose(pos);
	// Compute using the cell decomposition.
	internal.compute(forceInternal, pos, type);
	break;
      case 1:
	// Compute long range electrostatic forces.
	internal.computeFull(forceInternal, pos, type);
	break;
      case 2:
	// Compute only hardcore forces.
	internal.computeHardcoreFull(forceInternal, pos, type);
	break;
      }
    }
    
    // Loop through the particles.
    for (int i = 0; i < num; i++) {
      // Compute the external forces.
      Vector3 forceExternal = Vector3(0.0, 0.0, part[type[i]].charge*electricField);
      Vector3 forceGrid = part[type[i]].grid->interpolateForce(pos[i]);
      //Vector3 forceGrid = 0.0;

      // Compute the total force.
      Vector3 force = forceInternal[i] + forceExternal + forceGrid;

      // Get the random kick.
      Vector3 rando = randoGen.gaussian_vector();

      // Step
      pos1[i] = brown.stepPeriodic(pos[i], force, rando, part[type[i]].diffusion);
    }

    if (s % outPeriod == 0) {
      appendPdbTraj(outTrajFile, pos1, name, num, sysDim, 0.0);

      //computeCurrent(pos1, posLast);
      for (int i = 0; i < num; i++) posLast[i] = pos1[i];

      if (s % (10*outPeriod) == 0) {
	double percent = (100.0*s)/steps;
	clock_t clock1 = clock();
	double stepTime = diffclock(clock0, clock1)/(10*outPeriod);
	printf("step %ld, time %g, %.2f percent complete, %.1f ms/step\n", s, s*timestep, percent, stepTime);
	clock0 = clock1;
      }
    }
    
    // Swap the position pointers.
    Vector3* temp = pos;
    pos = pos1;
    pos1 = temp;
  }
  //fclose(out);


  delete[] pos;
  delete[] pos1;
  delete[] posLast;
  delete[] type;
  delete[] name;
  delete[] part;
  delete[] partGridFile;
  delete[] forceInternal;

  return 0;
}