BOOL FindLaunchPos( LONG i, LONG wid, LONG hei ) { LONG x, y; x = wid; y = RangeRand( hei ); FOREVER { if( x <= 2 * IM_WIDTH ) return FALSE; if( TestExtent( 0, i, x, y ) == -1 ) { Toasters[i].x = Toasters[i].old_x = x; Toasters[i].y = Toasters[i].old_y = y; Toasters[i].xspeed = RangeRand( 3 ) + 1; Toasters[i].yspeed = RangeRand( 2 ) + 1; Toasters[i].phase = RangeRand( IMAGEMAX ); return TRUE; } if( y > -IM_HEIGHT ) y -= IM_HEIGHT; else x -= IM_WIDTH; } }
VOID DrawLine (struct RastPort *RP, PrefObject *mP, LONG Size, LONG Index) { LONG Col; Line[Index].X = RangeRand (Size * 2) - Size; Line[Index].Y = RangeRand (Size * 2) - Size; Line[Index].X2 = RangeRand (Size * 2) - Size; Line[Index].Y2 = RangeRand (Size * 2) - Size; Col = RangeRand (Colors); SetAPen (RP, Col); Move (RP, HalfWidth + Line[Index].X, HalfHeight + Line[Index].Y); Draw (RP, HalfWidth + Line[Index].X2, HalfHeight + Line[Index].Y2); Move (RP, HalfWidth - Line[Index].X, HalfHeight + Line[Index].Y); Draw (RP, HalfWidth - Line[Index].X2, HalfHeight + Line[Index].Y2); Move (RP, HalfWidth + Line[Index].X, HalfHeight - Line[Index].Y); Draw (RP, HalfWidth + Line[Index].X2, HalfHeight - Line[Index].Y2); Move (RP, HalfWidth - Line[Index].X, HalfHeight - Line[Index].Y); Draw (RP, HalfWidth - Line[Index].X2, HalfHeight - Line[Index].Y2); Move (RP, HalfWidth + Line[Index].Y, HalfHeight + Line[Index].X); Draw (RP, HalfWidth + Line[Index].Y2, HalfHeight + Line[Index].X2); Move (RP, HalfWidth - Line[Index].Y, HalfHeight + Line[Index].X); Draw (RP, HalfWidth - Line[Index].Y2, HalfHeight + Line[Index].X2); Move (RP, HalfWidth + Line[Index].Y, HalfHeight - Line[Index].X); Draw (RP, HalfWidth + Line[Index].Y2, HalfHeight - Line[Index].X2); Move (RP, HalfWidth - Line[Index].Y, HalfHeight - Line[Index].X); Draw (RP, HalfWidth - Line[Index].Y2, HalfHeight - Line[Index].X2); }
VOID InitStar( Coord3D *p, LONG speed ) { p->x = 1500 - ( LONG )RangeRand( 3000 ); p->y = 1000 - ( LONG )RangeRand( 2000 ); p->z = 1000 + ( LONG )RangeRand( 2000 ); p->speed = ( LONG )RangeRand( 10 ) + speed; }
void doGoats(struct RastPort *r) { LONG ptr = numGoats-1; LONG i,n,newX,newY,startDir,tmpDir; LONG flag = 0; while (ptr >= 0) { if (goatQ[ptr] ) { flag = 1; x = goats[ptr].x; y = goats[ptr].y; SetAPen(r, backgroundClr); WritePixel(r, x, y); startDir = tmpDir = (LONG)RangeRand(8); while (1) { n = neighbor(r, tmpDir); if (n != grassClr || n == -1) { tmpDir = (tmpDir+1) % 8; if (tmpDir == startDir) { goatQ[ptr] = 0; break; } } else { goats[ptr].x = newX = tx; goats[ptr].y = newY = ty; ++grassEaten[ptr]; if (grassEaten[ptr] >= reproduction) { grassEaten[ptr] = 0; i = 0; while(goatQ[i] != 0 && i < numGoats) ++i; if (i != numGoats) { goats[i].x = newX; goats[i].y = newY; goatQ[i] = 1; grassEaten[i] = 0; } } SetAPen(r,goatClr); WritePixel(r,newX,newY); break; } } } --ptr; } if (!flag) { goatQ[0] = 1; goats[0].x = (LONG)RangeRand(Width-1); goats[0].y = (LONG)RangeRand(Height-1); grassEaten[0] = 0; } }
bool AddPoint() { if (vertex_.size() == Settings::MaxPoints) return false; int idx = RangeRand(vertex_.size()); PointIt it = vertex_.begin(); std::advance(it, idx); vertex_.insert(it, DnaPoint(RangeRand(Settings::ScreenWidth), RangeRand(Settings::ScreenHeight))); return true; }
void Emitter::Update(double elapsed) { Array <int> particlesToRemove; //eliminacion de particulas for( unsigned int i = 0; i < particles.Size(); i++ ) { particles[i]->Update( elapsed ); for( unsigned int a = 0; a < affectors.Size(); a++ ) affectors[a].AddParticles( particles[i] ); if( particles[i]->GetLifetime() <= 0 ) { particlesToRemove.Add( i ); delete particles[i]; for( unsigned int a = 0; a < affectors.Size(); a++ ) affectors[a].DeleteParticles( particles[i] ); } } for( int i = particlesToRemove.Size() - 1; i >= 0 ; i-- ) { particles.RemoveAt( particlesToRemove[i] ); } //fin eliminacion particulas //creacion de particulas int32 nParticles = 0; double velX, velY, velAng, life; uint8 r, g, b; if( IsEmitting() ) { nParticles = static_cast<int32>( RangeRand( static_cast<int32>( minrate ), static_cast<int32>( maxrate ) ) * elapsed ); } for( uint32 i = 0; i < (uint32)nParticles; i++ ) { velX = RangeRand( minvelx, maxvelx ); velY = RangeRand( minvely, maxvely ); velAng = RangeRand( minangvel, maxangvel ); life = RangeRand( minlifetime, maxlifetime) ; r = (uint8)RangeRand( minr, maxr ); g = (uint8)RangeRand( ming, maxg ); b = (uint8)RangeRand( minb, maxb ); Particle *particle = new Particle( image, velX, velY, velAng, life, autofade ); particle->SetPosition( x, y ); particle->SetColor( r, g, b, 255 ); particle->SetBlendMode( blendMode ); particles.Add( particle ); } //fin creacion particulas }
void randomSpheres(Scene* &scene, Camera* &camera, QtFilm* &film) { // Create scene scene = new Scene(new ListAggregate()); *scene << new SkyLight(vec3(0.8f, 0.8f, 1.0f)); Texture* spheresTexture = ImageLoading::LoadImage("/Users/gael/Desktop/Courses/CSE_168/models/textures/earth.jpg"); Texture* planeTexture = ImageLoading::LoadImage("/Users/gael/Desktop/Courses/CSE_168/models/textures/scale_brown.png"); // Materials Matte* spheresMaterial = new Matte(spheresTexture); Matte* planeMaterial = new Matte(planeTexture); //white->setColor(vec3(0.6f)); // Create ground plane Plane* groundShape = new Plane(); GeometricPrimitive* ground = new GeometricPrimitive(groundShape, planeMaterial); *scene << ground; // Create spheres for(int i=0; i<20; ++i) { Sphere* sphereShape = new Sphere(); GeometricPrimitive* sphere = new GeometricPrimitive(sphereShape, spheresMaterial); float rad = RangeRand(0.25f,0.5f); vec3 pos(RangeRand(-5.0f,5.0f), rad, RangeRand(-5.0f,5.0f)); sphereShape->setRadius(rad); sphereShape->setCenter(pos); *scene << sphere; } // Create lights DirectionalLight* sunlgt = new DirectionalLight(); sunlgt->setSpectrum(Spectrum(vec3(1.0f, 1.0f, 0.9f))); sunlgt->setIntensity(1.0f); sunlgt->setDirection(vec3(2.0f, -3.0f, -2.0f)); *scene << sunlgt; // Create camera PerspectiveCamera* perspectiveCamera = new PerspectiveCamera(); perspectiveCamera->lookAt(vec3(-0.75f,0.25f,5.0f), vec3(0.0f,0.5f,0.0f)); film = new QtFilm(vec2(800, 600)); perspectiveCamera->setFilm(film); perspectiveCamera->setVFov(40.0f); perspectiveCamera->setAspect(1.33f); camera = perspectiveCamera; }
void doHerders(struct RastPort *r) { LONG ptr = numHerders-1; LONG i,n,newX,newY,startDir,tmpDir; LONG flag = 0; while( ptr >= 0 ) { if( herderQ[ptr] ) { flag = 1; x = herders[ptr].x; y = herders[ptr].y; SetAPen(r, grassClr); WritePixel(r, x, y); startDir = tmpDir = (LONG)RangeRand(8); while (1) { n = neighbor(r, tmpDir); if (n == grassClr || n == -1) { tmpDir = (tmpDir+1) % 8; if (tmpDir == startDir) { herderQ[ptr] = 0; break; } } else { herders[ptr].x = newX = tx; herders[ptr].y = newY = ty; i = 0; while(herderQ[i] && i < numHerders) ++i; if (i != numHerders) { herders[i].x = newX; herders[i].y = newY; herderQ[i] = 1; } SetAPen(r,herderClr); WritePixel(r,newX,newY); break; } } } --ptr; } if (!flag) { herderQ[0] = 1; herders[0].x = (LONG)RangeRand(Width-1); herders[0].y = (LONG)RangeRand(Height-1); } }
bool MovePoly() { int origpos = RangeRand(poly_.size()); int newpos = RangeRand(poly_.size()); if (newpos == origpos) return false; PolyIt it = poly_.begin(); std::advance(it, origpos); DnaPolygon p(*it); poly_.erase(it); it = poly_.begin(); std::advance(it, newpos); poly_.insert(it, p); return true; }
bool AddPoly() { if (poly_.size() == Settings::MaxPolygons) return false; int idx = RangeRand(poly_.size()); PolyIt it = poly_.begin(); std::advance(it, idx); poly_.insert(it, DnaPolygon()); return true; }
LONG FracBlank( struct Screen *Scr, UWORD Wid, UWORD Hei ) { float x = 0, y = 0, xx, yy, a, b, c; LONG i, xe, ye, flg_end = OK, mod = ( 1L << Scr->BitMap.Depth ) - 1; struct RastPort *Rast = &( Scr->RastPort ); SetRast( Rast, 0 ); ScreenToFront( Scr ); a = (float)RangeRand( 1000 ) / 10 - 50.0; do b = (float)RangeRand( 1000 ) / 10 - 50.0; while( b == 0.0 ); c = (float)RangeRand( 1000 ) / 10 - 50.0; for( i = 0; i < 50000 && flg_end == OK; i++ ) { if(!( i % 50 )) { ScreenToFront( Scr ); flg_end = ContinueBlanking(); } if( x < 0 ) xx = y + sqrt( fabs( b * x - c )); else xx = y - sqrt( fabs( b * x - c )); yy = a - x; xe = Wid / 2 + (SHORT)x; ye = Hei / 2 + (SHORT)y; if(( xe >= 0 )&&( ye >= 0 )&&( xe < Wid )&&( ye < Hei )) { SetAPen( Rast, ( ReadPixel( Rast, xe, ye ) + 1 ) % mod + 1 ); WritePixel( Rast, xe, ye ); } x = xx; y = yy; } return flg_end; }
bool DelPoly() { if (poly_.size() == Settings::MinPolygons) return false; int idx = RangeRand(poly_.size()); PolyIt it = poly_.begin(); std::advance(it, idx); poly_.erase(it); return true; }
bool DelPoint() { if (vertex_.size() == Settings::MinPoints) return false; int idx = RangeRand(vertex_.size()); PointIt it = vertex_.begin(); std::advance(it, idx); vertex_.erase(it); return true; }
bool Mutate() { bool dirty = false; if (DoMutate(PointMaxMutation)) { X(RangeRand(Settings::ScreenWidth)); Y(RangeRand(Settings::ScreenHeight)); dirty = true; } if (DoMutate(PointMidMutation)) { DnaPoint p(RangeRand(Settings::PointMidMovement) * 2 - Settings::PointMidMovement, RangeRand(Settings::PointMidMovement) * 2 - Settings::PointMidMovement); *this += p; dirty = true; } if (DoMutate(PointMinMutation)) { DnaPoint p(RangeRand(Settings::PointSmallMovement) * 2 - Settings::PointSmallMovement, RangeRand(Settings::PointSmallMovement) * 2 - Settings::PointSmallMovement); *this += p; dirty = true; } if (X() < 0) X(0); if (Y() < 0) Y(0); if (X() >= Settings::ScreenWidth) X(Settings::ScreenWidth - 1); if (Y() >= Settings::ScreenHeight) Y(Settings::ScreenHeight - 1); return dirty; }
DnaPolygon() { vertex_.push_back(DnaPoint(RangeRand(Settings::ScreenWidth), RangeRand(Settings::ScreenHeight))); vertex_.push_back(DnaPoint(RangeRand(Settings::ScreenWidth), RangeRand(Settings::ScreenHeight))); vertex_.push_back(DnaPoint(RangeRand(Settings::ScreenWidth), RangeRand(Settings::ScreenHeight))); Color(R255, R255, R255); Alpha(IntervalRand(Settings::AlphaMin, Settings::AlphaMax)); }
int PWSfileV1V2::WriteV2Header() { CItemData header; // Fill out with V2-specific info // To make a dictionary attack a little harder, we make the length // of the first record (Name) variable, by appending variable length randomness // to the fixed string // OOPS - can't do this yet, since previous versions (pre-2.14) read the name // (in ReadV2Header) // and compare it directly to VersionString to check version - a small // mistake that would cause a pre-2.14 executable to barf reading a database // written by 2.14 and later. // #idef-ing this out, while correcting the code // in ReadV2Header. Perhaps this can be fixed a year from now? #ifdef BREAK_PRE_2_14_COMPATIBILITY unsigned int rlen = RangeRand(62) + 2; // 64 is a trade-off... char *rbuf = new char[rlen]; PWSrand::GetInstance()->GetRandomData(rbuf, rlen-1); rbuf[rlen-1] = TCHAR('\0'); // although zero may be there before - who cares? stringT rname(V2ItemName); rname += rbuf; delete[] rbuf; header.SetName(rname, _T("")); #else header.SetName(V2ItemName, _T("")); #endif /* BREAK_PRE_2_14_COMPATIBILITY */ header.SetPassword(VersionString); header.SetNotes(m_hdr.m_prefString); // need to fallback to V17, since the record // won't be readable otherwise! VERSION sv = m_curversion; m_curversion = V17; int status = WriteRecord(header); // restore after writing V17-format header m_curversion = sv; m_hdr.m_nCurrentMajorVersion = 2; m_hdr.m_nCurrentMinorVersion = 0; return status; }
LONG Dragon( struct Screen *Scr, SHORT Wid, SHORT Hei ) { LONG Color = 1, mod = (( 1L << Scr->BitMap.Depth ) - 1 ) * 5; LONG i, RetVal = OK, xd, yd; float a = PI-(( float )RangeRand( 100 )+10.0)/5000, xx, yy, x = 0, y = 0; struct RastPort *RP = &( Scr->RastPort ); SetRast( RP, 0 ); ScreenToFront( Scr ); for( i = 0; i < 1000000 && RetVal == OK; i++ ) { if(!( i % 100 )) { RetVal = ContinueBlanking(); ScreenToFront( Scr ); } xx = y - sin( x ); yy = a - x; xd = Wid / 2 + (SHORT)( 2.0 * x ); yd = Hei / 2 + (SHORT)( 2.0 * y ); Color = ( Color + 1 ) % mod; if(( xd >= 0 )&&( yd >= 0 )&&( xd < Wid )&&( yd < Hei )) { SetAPen( RP, Color/5 + 1 ); WritePixel( RP, xd, yd ); } x = xx; y = yy; } return RetVal; }
WORD StartMatch(BYTE team1,BYTE team2) { FILE *f; BOOL /*swapped=FALSE,*/ team_swap=FALSE,control_swap=FALSE,nightgame=FALSE,random_strict=FALSE; WORD risultato=-1,parent_menu; int t; parent_menu=current_menu; // Obtengo el timestamp y lo convierto a string struct timeval start_game; gettimeofday(&start_game, NULL); char timestamp_in_string [30]; sprintf (timestamp_in_string, "%lu", start_game.tv_sec); filename = concat(folder, teamlist[team1].name); filename = concat(filename, "-"); filename = concat(filename, teamlist[team2].name); // temporanea, solo x evitare l'apertura della squadra! if(network_game) controllo[team2]=-1; if(!training&&!network_game) { if(RangeRand(2)) { UBYTE temp; temp=team1; team1=team2; team2=temp; team_swap=TRUE; } if(controllo[team2]>=0 && controllo[team1]==controllo[team2]) { control_swap=TRUE; controllo[team2]--; if(controllo[team2]<0) controllo[team2]=1; } } else if(network_game && network_player->num) { UBYTE temp=team1; D(bug("Player got team 1, swapping teams\n")); team1=team2; team2=temp; team_swap=TRUE; } if( (daytime==0 && RangeRand(2)==0 ) || daytime==2 ) nightgame=TRUE; if(controllo[team1]>=0&&!arcade_teams) { SetTeamSettings(team1, TRUE); ChangeMenu(MENU_TEAM_SETTINGS); while(HandleMenuIDCMP()); } if(controllo[team2]>=0&&!training&&!arcade_teams) { SetTeamSettings(team2, TRUE); ChangeMenu(MENU_TEAM_SETTINGS); while(HandleMenuIDCMP()); } window_opened=FALSE; // write_config(TEMP_DIR "thismatch"/*-*/); if(arcade_teams) { extern BYTE arcade_team[]; arcade_team[0]=team1; arcade_team[1]=team2; } team_a=team1; team_b=team2; /* * Questo codice si occupa di inviare la squadra e ricevere * l'altra, notare la specularita' a seconda del controller * che si e' deciso di utilizzare. */ if(!network_game || network_player->num == 0) { if(network_game && !SendTeam(team1)) return -1; leftteam_dk=teamlist[team1]; } else if(network_game && !ReceiveTeam(&leftteam_dk)) return -1; if(!network_game || network_player->num == 1) { if(network_game && !SendTeam(team2)) return -1; rightteam_dk=teamlist[team2]; } else if(network_game && !ReceiveTeam(&rightteam_dk)) return -1; if(!training && !network_game) { if(!CheckMaglie(team1,team2)) rightteam_dk.jerseys[0]=rightteam_dk.jerseys[1]; } use_offside = FALSE; if(training) { rightteam_dk.jerseys[0]=rightteam_dk.jerseys[1]; } else if (offside) use_offside = TRUE; sprintf(shirt[0],"gfx/play%lc%lc%lc.obj"/*-*/, ( (nightgame||arcade) ? 'n' : 'e'), ( (field==8&&!arcade) ? 's' : 'r'), teamlist[team1].jerseys[0].type+'a'); sprintf(shirt[1],"gfx/play%lc%lc%lc.obj"/*-*/, ( (nightgame||arcade) ? 'n' : 'e'), ( (field==8&&!arcade) ? 's' : 'r'), (training ? teamlist[team2].jerseys[1].type : teamlist[team2].jerseys[0].type)+'a'); if(!field) t=RangeRand(6); else t=field-1; current_field= (arcade ? 0 : t); if(arcade) { if(!final&&!warp) { sprintf(fieldname,"gfx/arcade.gfx"/*-*/); sprintf(palette,"gfx/eat16arcade.col"/*-*/); } else { sprintf(fieldname,"gfx/a_final.gfx"/*-*/); sprintf(palette,"gfx/eat16arcade.col"/*-*/); } }
LONG Blank( PrefObject *Prefs ) { LONG ToFrontCount = 0, Wid, Hei, Drops, x, y, r, i, incr, RetVal = OK; struct RastPort *Rast; struct Screen *Scr; struct Window *Wnd; LONG d, xs, ys, rs; Drops = Prefs[0].po_Level; Scr = OpenScreenTags( 0L, SA_Depth, Prefs[2].po_Depth, SA_Quiet, TRUE, SA_Overscan, OSCAN_STANDARD, SA_Behind, TRUE, SA_DisplayID, Prefs[2].po_ModeID, SA_ShowTitle, FALSE, SA_Title, "Garshnescreen", TAG_DONE ); if( Scr ) { Wid = Scr->Width; Hei = Scr->Height; d = min( Wid, Hei ); xs = 3 * Wid; ys = 4 * Hei; Rast = &( Scr->RastPort ); SetRast( Rast, 0 ); for( i = 0; i < 4; i++ ) SetRGB4(&( Scr->ViewPort ), i, 4 * i, 4 * i, 4 * i ); Wnd = BlankMousePointer( Scr ); ScreenToFront( Scr ); while( RetVal == OK ) { if(!( ++ToFrontCount % 60 )) ScreenToFront( Scr ); if(!( ToFrontCount % Drops )) SetRast(&( Scr->RastPort ), 0 ); r = RangeRand( d/13 ) + d/25; if( Wid > Hei ) rs = r * xs / ys; else rs = r * ys / xs; x = RangeRand( Wid - 2*rs ) + rs; y = RangeRand( Hei - 2*rs ) + rs; incr = max( Wid/160, 1 ); for( i = 0; i < r; i += incr ) { WaitTOF(); SetAPen( &Scr->RastPort, ( ULONG )RangeRand(( 1L << Prefs[2].po_Depth ) - 1 ) + 1 ); if( Wid > Hei ) { DrawEllipse(&( Scr->RastPort ), x, y, i * xs / ys, i ); if( i ) { SetAPen(&( Scr->RastPort ), 0 ); DrawEllipse(&( Scr->RastPort ), x, y, xs * ( i - incr ) / ys, i - incr ); } } else { DrawEllipse(&( Scr->RastPort ), x, y, i, ys * i / xs ); if( i ) { SetAPen(&( Scr->RastPort ), 0 ); DrawEllipse(&( Scr->RastPort ), x, y, i - incr, ( i - incr ) * ys / xs ); } } } RetVal = ContinueBlanking(); } UnblankMousePointer( Wnd ); } else RetVal = FAILED; if( Scr ) CloseScreen( Scr ); return RetVal; }
LONG Blank( PrefObject *Prefs ) { LONG ToFrontCount = 0, Wid, Hei, Drops, x, y, r, i, incr, RetVal = OK; struct RastPort *Rast; struct Screen *Scr; struct Window *Wnd; Drops = Prefs[0].po_Level; Scr = OpenScreenTags( 0L, SA_Depth, Prefs[2].po_Depth, SA_Quiet, TRUE, SA_Overscan, OSCAN_STANDARD, SA_Behind, TRUE, SA_DisplayID, Prefs[2].po_ModeID, TAG_DONE ); if( 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 ); Wnd = BlankMousePointer( Scr ); ScreenToFront( Scr ); while( RetVal == OK ) { if(!( ++ToFrontCount % 60 )) ScreenToFront( Scr ); if(!( ToFrontCount % Drops )) SetRast(&( Scr->RastPort ), 0 ); r = RangeRand( Wid/13 ) + Wid/25; x = RangeRand( Wid - 2*r ) + r; y = RangeRand( Hei - 2*r ) + r; incr = max( Wid/160, 1 ); for( i = 0; i < r; i += incr ) { WaitTOF(); SetAPen( &Scr->RastPort, ( ULONG )RangeRand(( 1L << Prefs[2].po_Depth ) - 1 ) + 1 ); DrawEllipse(&( Scr->RastPort ), x, y, i, i ); if( i ) { SetAPen(&( Scr->RastPort ), 0 ); DrawEllipse(&( Scr->RastPort ), x, y, i - incr, i - incr ); } } RetVal = ContinueBlanking(); } UnblankMousePointer( Wnd ); } else RetVal = FAILED; if( Scr ) CloseScreen( Scr ); return RetVal; }
VOID IterateFire( struct RastPort *Rast ) { LONG l; struct Fire *f, *tf; if(( NumFires < MaxFires )&&( RangeRand( 100 ) > 90 )) { for( tf = FireTable; tf->type; tf++ ); if( tf != LastFire ) { tf->type = FIRE; tf->x = ( Wid / 4 + RangeRand( Wid / 2 )) * SCALE; tf->y = ( Hei - 5 ) * SCALE; tf->color = RangeRand(( 1L << Rast->BitMap->Depth ) - 1 ) + 1; tf->vx = RangeRand( SCALE * Hei / 100 ) - SCALE; tf->vy = -1 * ( Power * SCALE * Hei / 400 ); tf->time = RangeRand( 100 ) + 100; NumFires++; } } for( f = FireTable; f != LastFire; f++ ) { switch( f->type ) { case NONE: break; case FIRE: if( !f->time ) { for( l = 0, tf = FireTable; ( l < MAX_EXPLOSIONS )&& ( tf != LastFire ); tf++ ) { if( !tf->type ) { CopyMem( f, tf, sizeof( struct Fire )); tf->type = EXPLODING; tf->vx = ( RangeRand( 100 ) - 50 ) * ( Radius * Wid / 1000 ); tf->vy = ( RangeRand( 100 ) - 50 ) * ( Radius * Hei / 1000 ); tf->time = RangeRand( 10 ) + 50; l++; } } NumFires--; f->type = NONE; } else { SetAPen( Rast, 0 ); WritePixel( Rast, f->x/SCALE, f->y/SCALE ); f->x += f->vx; f->y += f->vy; if( CheckFire( f )) { f->type = NONE; NumFires--; } else { SetAPen( Rast, f->color ); WritePixel( Rast, f->x/SCALE, f->y/SCALE ); f->vy += ACCEL; f->time--; } } break; case EXPLODING: SetAPen( Rast, 0 ); WritePixel( Rast, f->x/SCALE, f->y/SCALE ); if( !f->time ) f->type = NONE; else { f->x += f->vx; f->y += f->vy; if( CheckFire( f )) f->type = NONE; else { SetAPen( Rast, f->color ); WritePixel( Rast, f->x/SCALE, f->y/SCALE ); f->vy += ACCEL; f->time--; } } break; } } }
LONG Blank( PrefObject *Prefs ) { LONG delay_rate, i, j, counter = 0, RetVal = OK; struct RastPort *Rast; struct Screen *FTScr; struct Window *FTWin; struct Window *Wnd; NumToasters = Prefs[OBJECTS].po_Level; delay_rate = 11 - Prefs[SPEED].po_Level; Toasters = AllocVec( sizeof( Toaster ) * NumToasters, MEMF_CLEAR ); FTScr = OpenScreenTags( NULL, SA_DisplayID, Prefs[MODE].po_ModeID, SA_Depth, 4, SA_Overscan, OSCAN_STANDARD, SA_Type, CUSTOMSCREEN, SA_Quiet, TRUE, SA_Behind, TRUE, TAG_DONE ); if( Toasters && FTScr ) { for( i = 0; i < 48; i += 3 ) if( GfxBase->lib_Version < 39 ) SetRGB4(&( FTScr->ViewPort ), i/3, ( cmap[i] * 16 ) / 256, ( cmap[i+1] * 16 ) / 256, ( cmap[i+2] * 16 ) / 256 ); else SetRGB32(&( FTScr->ViewPort ), i/3, cmap[i]<<24, cmap[i+1]<<24, cmap[i+2]<<24 ); FTWin = OpenWindowTags( 0L, WA_Width, FTScr->Width, WA_Height, FTScr->Height, WA_IDCMP, 0L, WA_Flags, WFLG_SIMPLE_REFRESH|WFLG_BORDERLESS, WA_CustomScreen, FTScr, TAG_DONE ); if( FTWin ) { Rast = FTWin->RPort; SetAPen( Rast, 0 ); for( i = 0; i < NumToasters; i++ ) if( !FindLaunchPos( i, ( LONG )FTWin->Width, ( LONG )FTWin->Height )) Toasters[i].delay = 30; Wnd = BlankMousePointer( FTScr ); ScreenToFront( FTScr ); while( RetVal == OK ) { WaitTOF(); if(!( ++counter % 60 )) ScreenToFront( FTScr ); if(!( counter % delay_rate )) { for( i = 0; i < NumToasters; i++ ) { if( !Toasters[i].delay ) { Toasters[i].old_x = Toasters[i].x; Toasters[i].old_y = Toasters[i].y; Toasters[i].x -= Toasters[i].xspeed; Toasters[i].y += Toasters[i].yspeed; Toasters[i].xcol = -1; Toasters[i].ycol = -1; } } for( i = 0; i < NumToasters; i++ ) { if( !Toasters[i].delay ) { j = -1; while(( j = TestExtent( j+1, i, Toasters[i].x, Toasters[i].y )) >= 0 ) { if( abs( Toasters[j].old_x - Toasters[i].old_x ) < IM_WIDBUF ) { if( Toasters[i].y < Toasters[j].y ) Toasters[i].ycol = j; if( Toasters[i].xspeed == Toasters[j].xspeed ) Toasters[i].xspeed++; } else { if( Toasters[i].x > Toasters[j].x ) Toasters[i].xcol = j; if( Toasters[i].yspeed == Toasters[j].yspeed ) Toasters[i].yspeed++; } if( abs( Toasters[j].old_y - Toasters[i].old_y ) < IM_HEIBUF ) { if( Toasters[i].x > Toasters[j].x ) Toasters[i].xcol = j; if( Toasters[i].yspeed == Toasters[j].yspeed ) Toasters[i].yspeed++; } } } } for( i = 0; i < NumToasters; i++ ) { if( !Toasters[i].delay ) { Toasters[i].x = Toasters[i].old_x - ActXSpeed( i ); Toasters[i].y = Toasters[i].old_y + ActYSpeed( i ); } } for( i = 0; i < NumToasters; i++ ) { if( !Toasters[i].delay ) { j = -1; while(( j = TestExtent( j+1, i, Toasters[i].x, Toasters[i].y )) >= 0 ) { if( abs( Toasters[j].old_x - Toasters[i].old_x ) < IM_WIDBUF ) if( Toasters[i].x > Toasters[j].x ) Toasters[i].x = Toasters[i].old_x; else if( Toasters[i].y < Toasters[j].y ) Toasters[i].y = Toasters[i].old_y; if( abs( Toasters[j].old_y - Toasters[i].old_y ) < IM_HEIBUF ) if( Toasters[i].y < Toasters[j].y ) Toasters[i].y = Toasters[i].old_y; } } } for( i = 0; i < NumToasters; i++ ) { if( !Toasters[i].delay ) { Toasters[i].phase = ( Toasters[i].phase + 1 ) % IMAGEMAX; EraseRect( Rast, Toasters[i].x + IM_WIDTH, Toasters[i].old_y, Toasters[i].x + IM_WIDTH + Toasters[i].xspeed, Toasters[i].old_y + IM_HEIGHT ); EraseRect( Rast, Toasters[i].old_x, Toasters[i].old_y, Toasters[i].old_x + IM_WIDTH, Toasters[i].old_y + Toasters[i].yspeed ); DrawImage( Rast, img[Toasters[i].phase], Toasters[i].x, Toasters[i].y ); if(( Toasters[i].x < -IM_WIDTH-1 )|| ( Toasters[i].y > FTWin->Height )) Toasters[i].delay = RangeRand( 50 ); } else if(!( --Toasters[i].delay )) Toasters[i].delay = FindLaunchPos( i, ( LONG )FTWin->Width, ( LONG )FTWin->Height ) ? 0 : 30; } } RetVal = ContinueBlanking(); } SetSignal( 0L, SIGBREAKF_CTRL_C ); UnblankMousePointer( Wnd ); CloseWindow( FTWin ); } else RetVal = FAILED; CloseScreen( FTScr ); } else RetVal = FAILED; FreeVec( Toasters ); return RetVal; }
LONG IFS( struct Screen *scr, SHORT width, SHORT height, PrefObject *Prefs ) { LONG flg_end = OK; int colors = (1L << scr->BitMap.Depth); double x,y, /* the coordinate which gets computed */ prob; /* probability for continuing withot Clscr */ int num, /* total number of fctns for the current IFS */ thef; /* the currently applied function */ int i,j,k; /* multi-purpose counters, array indices */ int wx,wy; /* window coordinate of current point */ int tx,ty; /* # pixels to transpose the Origin (x,y) */ double aa[FNUM][4], /* For each f: a 2x2 matrix and */ vv[FNUM][2], /* a transposition vector */ comp[FNUM], /* the compression of each function (1/comp[n] * is the compression of the function) */ totcomp; /* sum of all the size factors. The larger this * is, the longer we should compute */ double CONTINUEPROBABILITY,CONTPROBDECREASE; bool TRANSPOSE,USEPROBABILITY,oncedone; int LENGTH,FUNCTIONS; struct RastPort *rp = &( scr->RastPort ); CONTINUEPROBABILITY = ((double)Prefs[PREF_CONTPROB].po_Level)/100.0; CONTPROBDECREASE = ((double)Prefs[PREF_DECREASE].po_Level)/100.0; USEPROBABILITY = !(Prefs[PREF_AREA].po_Level); TRANSPOSE = !(Prefs[PREF_TRANSPOSE].po_Level); LENGTH = Prefs[PREF_ITERATIONS].po_Level; FUNCTIONS = Prefs[PREF_FUNCTIONS].po_Level; while (1) { Move(rp,0,0); SetRast(rp,0); SetAPen(rp,1); ScreenToFront( scr ); prob = CONTINUEPROBABILITY; oncedone = FALSE; while (((double)RangeRand(1000))/1000 < prob || !oncedone) { oncedone = TRUE; prob = prob - CONTPROBDECREASE; num = RangeRand(FUNCTIONS-2)+2; /* Compute the iterated function */ totcomp = 0; { int moverand = RangeRand(4); /* select a move factor with the appropriate probability */ double MOVEFACTOR; switch(moverand) { case 0: MOVEFACTOR = MOVEFACTORA; break; case 1: case 2: MOVEFACTOR = MOVEFACTORB; break; case 3: MOVEFACTOR = MOVEFACTORC; break; default: MOVEFACTOR = MOVEFACTORB; break; /* should never happen */ } /* compute the functions and their compression */ for (k=0; k<num; k++) { for (i=0; i<2; i++) { vv[k][i] = (FLOATRAND() - 0.5) * MOVEFACTOR; } for (i=0; i<4; i++) { aa[k][i] = (FLOATRAND() - 0.5) * SIZEFACTOR; } comp[k] = abs(aa[k][0]*aa[k][2]-aa[k][1]*aa[k][3]); totcomp = totcomp + comp[k]; } } /* and a probability distribution, eg. * 2,3,1,4 -> 0.2, 0.3, 0.1, 0.4 -> 0.2, 0.5, 0.6, 1.0 */ for (k=0; k<num; k++) { comp[k] = comp[k]/totcomp; if (k>0) { comp[k] = comp[k]+comp[k-1]; } } comp[num-1] = 1.1; /* just to be safe of numerical errors, we increment * the final probability a bit */ /* Initialize the transpositions of the origin */ if (TRANSPOSE) { tx = (int)(RangeRand(width/2))-width/4; ty = (int)(RangeRand(height/2))-height/4; } else { tx = ty = 0; } /* set the color for the function */ SetAPen(rp,(int)(RangeRand(colors-1)+1)); /* and now: compute the IFS. We do this using several iterations * instead of just one big step. This gives a picture which looks * a bit more structured. */ for (i=0; i<(int)(LENGTH*totcomp); i++) { x=y=0; for (j=0; j<ITER; j++) { double xx; /* Find a function to use */ if (USEPROBABILITY) { double p; p = FLOATRAND(); thef = 0; while (comp[thef] < p) { thef++; } } else { thef = RangeRand(num); } /* compute (x,y) = (x,y)*aa + vv */ xx = (x*aa[thef][0]+y*aa[thef][1])+vv[thef][0]; y = (x*aa[thef][2]+y*aa[thef][3])+vv[thef][1]; x = xx; /* Convert it to a window coordinate and plot it */ wx = WINCO(x,width); wy = WINCO(y,height); /* And transpose it, if necessary */ wx = wx + tx; wy = wy + ty; if (wx > 0 && wx < width && wy > 0 && wy < height) WritePixel(rp,wx,wy); } ScreenToFront( scr ); flg_end = ContinueBlanking(); if (flg_end != OK) { return flg_end; } } } } return flg_end; }