Ejemplo n.º 1
0
// 主函数
int main( int argc, char* argv[] ) {
    int i, ms_x = -1024, ms_y = -1024, exitflag = 0;
    int fps = 60;
    double dtime;

    int mode = preinit( argc, argv ); // 记录初始化模式
    if ( mode < 0 ) return 0;

    randomize(); // 初始化随机种子
    initgraph( -1, -1 ); // 打开图形窗口,以全屏模式

    showmouse( mode );
    sc_width = getwidth();
    sc_heigh = getheight();

    // 初始化所有星星
    for ( i = 0; i < g_max; i++ ) {
        InitStar( i );
        star[i].x = randomf();
    }
    // 绘制星空,按任意键或移动鼠标退出
    setfont( 12, 6, "宋体" );
    setrendermode( RENDER_MANUAL );
    dtime = fclock();
    while ( kbmsg() ) getkey();

    for ( ; !exitflag && is_run() && kbmsg() == 0; delay_fps( fps ) ) { //每秒画120帧,kbhit(1)是获取键盘任意键的消息,详见pdf
        // 如果有鼠标消息
        while ( mousemsg() ) {
            mouse_msg msg = getmouse();
            if ( ms_x <= -1024 ) {
                ms_x = msg.x;
                ms_y = msg.y;
            }
            // 处理鼠标,移动超出范围就退出
            if ( mode == 0 ) { // 仅全屏模式才处理鼠标
                int x = msg.x, y = msg.y;
                x -= ms_x;
                y -= ms_y;
                if ( x * x + y * y > 400 ) exitflag = 1;
            }
        }
        // 显示星星
        double dt = 1.0 / fps; //fclock() - dtime;
        dtime += dt;
        for ( int i = 0; i < g_max; i++ ) {
            MoveStar( i, dt );
        }
        // 显示FPS
        {
            char str[60];
            sprintf( str, "%8.2f FPS", getfps());
            outtextxy( 0, 0, str ); //显示fps
        }
    }
    closegraph(); // 关闭图形窗口
    return 0;
}
Ejemplo n.º 2
0
// 移动星星
void MoveStar( int i, double dt ) {
    // 擦掉原来的星星
    putpixel( ( int )( star[i].x * sc_width ), star[i].y, 0 );
    // 计算新位置
    star[i].x += star[i].step * dt * 60;
    if ( star[i].x > 1 ) InitStar( i );
    // 画新星星
    putpixel( ( int )( star[i].x * sc_width ), star[i].y, star[i].color );
}
Ejemplo n.º 3
0
flurry_info_t *new_flurry_info(global_info_t *global, int streams, ColorModes colour, float thickness, float speed, double bf)
{
	int i,k;
	flurry_info_t *flurry = (flurry_info_t *)malloc(sizeof(flurry_info_t));

	if (!flurry) return NULL;

	flurry->flurryRandomSeed = RandFlt(0.0, 300.0);

	flurry->dframe = 0;
	flurry->fOldTime = 0;
	flurry->fTime = TimeInSecondsSinceStart() + flurry->flurryRandomSeed;
	flurry->fDeltaTime = flurry->fTime - flurry->fOldTime;

	flurry->numStreams = streams;
	flurry->streamExpansion = thickness;
	flurry->currentColorMode = colour;
	flurry->briteFactor = bf;

	flurry->s = (SmokeV*)malloc(sizeof(SmokeV));
	InitSmoke(flurry->s);

	flurry->star = (Star*)malloc(sizeof(Star));
	InitStar(flurry->star);

	flurry->star->rotSpeed = speed;

	for (i = 0; i < MAX_SPARKS; i++)
	{
		flurry->spark[i] = (Spark*)malloc(sizeof(Spark));
		InitSpark(flurry->spark[i]);
		flurry->spark[i]->mystery = 1800 * (i + 1) / 13; /* 100 * (i + 1) / (flurry->numStreams + 1); */
		UpdateSpark(global, flurry, flurry->spark[i]);
	}

	for (i = 0; i < NUMSMOKEPARTICLES / 4; i++) {
		for (k = 0; k < 4; k++) {
			flurry->s->p[i].dead.i[k] = 1;
		}
	}

	flurry->next = NULL;

	return flurry;
}
Ejemplo n.º 4
0
void ModelClass::SetFromXml(wxXmlNode* ModelNode, bool zeroBased)
{
    wxString tempstr,channelstr;
    wxString customModel,RGBorder;
    long degrees, StartChannel, channel;
    size_t i;

    ModelXml=ModelNode;
    TreeDegrees=0;
    StrobeRate=0;
    Nodes.clear();

    name=ModelNode->GetAttribute("name");
    DisplayAs=ModelNode->GetAttribute("DisplayAs");
    if (ModelNode->HasAttribute("StringType"))
    {
        // post 3.1.4
        StringType=ModelNode->GetAttribute("StringType");
    }
    else
    {
        // 3.1.4 and earlier
        StringType=ModelNode->GetAttribute("Order","RGB")+" Nodes";
    }
    SingleNode=HasSingleNode(StringType);
    SingleChannel=HasSingleChannel(StringType);
    RGBorder=SingleNode ? "RGB" : RGBorder=StringType.Left(3);
    rgbidx[0]=std::max(RGBorder.Find('R'),0);
    rgbidx[1]=std::max(RGBorder.Find('G'),0);
    rgbidx[2]=std::max(RGBorder.Find('B'),0);

    tempstr=ModelNode->GetAttribute("parm1");
    tempstr.ToLong(&parm1);
    tempstr=ModelNode->GetAttribute("parm2");
    tempstr.ToLong(&parm2);
    tempstr=ModelNode->GetAttribute("parm3");
    tempstr.ToLong(&parm3);
    tempstr=ModelNode->GetAttribute("StartChannel","1");
    tempstr.ToLong(&StartChannel);
    tempstr=ModelNode->GetAttribute("Dir");
    IsLtoR=tempstr != "R";
    if (ModelNode->HasAttribute("StartSide"))
    {
        tempstr=ModelNode->GetAttribute("StartSide");
        isBotToTop = (tempstr == "B");
    }
    else
    {
        isBotToTop=true;
    }

    tempstr=ModelNode->GetAttribute("Antialias","0");
    tempstr.ToLong(&Antialias);
    AliasFactor=1 << Antialias;
    MyDisplay=IsMyDisplay(ModelNode);

    tempstr=ModelNode->GetAttribute("offsetXpct","0");
    tempstr.ToDouble(&offsetXpct);
    tempstr=ModelNode->GetAttribute("offsetYpct","0");
    tempstr.ToDouble(&offsetYpct);
    tempstr=ModelNode->GetAttribute("PreviewScale","0.333");
    tempstr.ToDouble(&PreviewScale);
    tempstr=ModelNode->GetAttribute("PreviewRotation","0");
    tempstr.ToLong(&degrees);
    PreviewRotation=degrees;

    // calculate starting channel numbers for each string
    size_t NumberOfStrings= HasOneString(DisplayAs) ? 1 : parm1;
    int ChannelsPerString=parm2*3;
    if (SingleChannel)
        ChannelsPerString=1;
    else if (SingleNode)
        ChannelsPerString=3;

    if (ModelNode->HasAttribute("CustomModel"))
    {
        customModel = ModelNode->GetAttribute("CustomModel");
        int maxval=GetCustomMaxChannel(customModel);
        // fix NumberOfStrings
        if (SingleNode)
        {
            NumberOfStrings=maxval;
        }
        else
        {
            ChannelsPerString=maxval*3;
        }
    }

    tempstr=ModelNode->GetAttribute("Advanced","0");
    bool HasIndividualStartChans=tempstr == "1";
    stringStartChan.clear();
    stringStartChan.resize(NumberOfStrings);
    for (i=0; i<NumberOfStrings; i++)
    {
        tempstr=StartChanAttrName(i);
        if (!zeroBased && HasIndividualStartChans && ModelNode->HasAttribute(tempstr))
        {
            ModelNode->GetAttribute(tempstr, &channelstr);
            channelstr.ToLong(&channel);
            stringStartChan[i] = channel-1;
        }
        else
        {
            stringStartChan[i] = (zeroBased? 0 : StartChannel-1) + i*ChannelsPerString;
        }
    }

    // initialize model based on the DisplayAs value
    wxStringTokenizer tkz(DisplayAs, " ");
    wxString token = tkz.GetNextToken();
    if (token == "Tree")
    {
        InitVMatrix();
        token = tkz.GetNextToken();
        token.ToLong(&degrees);
        SetTreeCoord(degrees);
    }
    else if (DisplayAs == "Custom")
    {
        InitCustomMatrix(customModel);
        CopyBufCoord2ScreenCoord();
    }
    else if (DisplayAs == "Vert Matrix")
    {
        InitVMatrix();
        CopyBufCoord2ScreenCoord();
    }
    else if (DisplayAs == "Horiz Matrix")
    {
        InitHMatrix();
        CopyBufCoord2ScreenCoord();
    }
    else if (DisplayAs == "Single Line")
    {
        InitLine();
        SetLineCoord();
    }
    else if (DisplayAs == "Arches")
    {
        InitHMatrix(); // Old call was InitLine();
        SetArchCoord();
    }
    else if (DisplayAs == "Window Frame")
    {
        InitFrame();
        CopyBufCoord2ScreenCoord();
    }
    else if (DisplayAs == "Star")
    {
        InitStar();
        CopyBufCoord2ScreenCoord();
    }
    else if (DisplayAs == "Wreath")
    {
        InitWreath();
        CopyBufCoord2ScreenCoord();
    }

    size_t NodeCount=GetNodeCount();
    for(size_t i=0; i<NodeCount; i++)
    {
        Nodes[i]->sparkle = rand() % 10000;
    }
}
Ejemplo n.º 5
0
LONG Blank( PrefObject *Prefs )
{
	LONG ToFrontCount = 0, Wid, Hei, i, x, y, Stars, Speed, RetVal = OK;
	struct RastPort *Rast;
	struct Screen *Scr;
	struct Window *Wnd;
	Coord3D *p;
	Coord2D *p2;
	
	Stars = Prefs[0].po_Level;
	Speed = Prefs[2].po_Level;
	
	Coords = AllocVec( Stars * sizeof( Coord3D ), MEMF_CLEAR );
	OldCoords = AllocVec( Stars * sizeof( Coord2D ), MEMF_CLEAR );
	Scr = OpenScreenTags( 0L, SA_Depth, 2, SA_Overscan, OSCAN_STANDARD,
						 SA_DisplayID, Prefs[4].po_ModeID, SA_Behind, TRUE,
						 SA_Quiet, TRUE, SA_ShowTitle, FALSE, SA_Title,
						 "Garshnescreen", TAG_DONE );

	if( Coords && OldCoords && Scr )
	{
		Wid = Scr->Width;
		Hei = Scr->Height;
		
		Rast = &( Scr->RastPort );
		SetRast( Rast, 0 );
		for( i = 0; i < 4; i++ )
			SetRGB4(&( Scr->ViewPort ), i, 4 * i, 4 * i, 4 * i );
		
		for( i = 0; i < Stars; i++ )
		{
			InitStar( &Coords[i], Speed );
			OldCoords[i].x = 0;
			OldCoords[i].y = 0;
		}
		
		Wnd = BlankMousePointer( Scr );
		ScreenToFront( Scr );
		
		while( RetVal == OK )
		{
			WaitTOF();

			if(!( ++ToFrontCount % 60 ))
				ScreenToFront( Scr );
			
			for( p2 = OldCoords, p = Coords, i = 0;
				i < Stars; i++, p++, p2++ )
			{
				x = p2->x;
				y = p2->y;
				
				SetAPen( Rast, 0 );
				switch( p->z / 200 )
				{
				case 0:
					WritePixel( Rast, x, y+1 );
					WritePixel( Rast, x+1, y+1 );
				case 1:
				case 2:
				case 3:
				case 4:
					WritePixel( Rast, x+1, y );
				default:
					WritePixel( Rast, x, y );
				}

				p->z -= p->speed;
				if( p->z <= -1000 )
					InitStar( p, Speed );
				
				x = Wid/2 + ( 200 * p->x ) / ( p->z + 1000 );
				y = Hei/2 + ( 200 * p->y ) / ( p->z + 1000 );
				
				if(( x < 0 )||( x > Wid-2 )||( y < 0 )||( y > Hei-2 ))
				{
					InitStar( p, Speed );
					p2->x = 0;
					p2->y = 0;
				}
				else
				{
					p2->x = x;
					p2->y = y;
					SetAPen( Rast, 3 );
					/* Warning: This is a little twisted. */
					switch( p->z/200 )
					{
					case 9:
					case 8:
						SetAPen( Rast, 2 );
						break;
					case 0:
						WritePixel( Rast, x, y+1 );
						WritePixel( Rast, x+1, y+1 );
					case 4:
					case 3:
					case 2:
					case 1:
						WritePixel( Rast, x+1, y );
					case 7:
					case 6:
					case 5:
						break;
					default:
						SetAPen( Rast, 1 );
						break;
					}
					WritePixel( Rast, x, y );
				}
			}
			if(!( ToFrontCount % 5 ))
				RetVal = ContinueBlanking();
		}
		UnblankMousePointer( Wnd );
	}
	else
		RetVal = FAILED;

	if( Scr )
		CloseScreen( Scr );
	if( Coords )
		FreeVec( Coords );
	if( OldCoords )
		FreeVec( OldCoords );

	return RetVal;
}