//--------------------------------------------------------- bool CLife::On_Execute(void) { //----------------------------------------------------- m_pLife = m_Grid_Target.Get_Grid("LIFE", SG_DATATYPE_Byte); if( !m_pLife ) { Error_Set(_TL("could not create target grid")); return( false ); } //----------------------------------------------------- m_nColors = Parameters("FADECOLOR")->asInt(); for(int y=0; y<m_pLife->Get_NY(); y++) { for(int x=0; x<m_pLife->Get_NX(); x++) { m_pLife->Set_Value(x, y, CSG_Random::Get_Uniform(0, 100) < 50 ? 0 : m_nColors); } } //----------------------------------------------------- m_pLife->Set_Name(_TL("Conway's Game of Life")); m_pLife->Set_NoData_Value(-1); DataObject_Add (m_pLife); DataObject_Set_Colors(m_pLife, 11, SG_COLORS_WHITE_BLUE); DataObject_Update (m_pLife, 0, m_nColors, SG_UI_DATAOBJECT_SHOW); //----------------------------------------------------- int i; m_Count.Create(m_pLife->Get_System(), SG_DATATYPE_Byte); for(i=1; Process_Get_Okay(true) && Next_Cycle(i > m_nColors); i++) { Process_Set_Text(CSG_String::Format("%s: %d", _TL("Life Cycle"), i)); DataObject_Update(m_pLife, 0, m_nColors); } m_Count.Destroy(); //----------------------------------------------------- if( is_Progress() ) { Message_Add(CSG_String::Format("\n%s %d %s\n", _TL("Dead after"), i, _TL("Life Cycles")), false); } return( true ); }
//--------------------------------------------------------- bool CWator::On_Execute(void) { //----------------------------------------------------- m_pWator = m_Grid_Target.Get_Grid("GRID", SG_DATATYPE_Byte); if( !m_pWator ) { Error_Set(_TL("could not create target grid")); return( false ); } //----------------------------------------------------- m_pWator->Set_Name(_TL("Wa-Tor")); m_pWator->Set_NoData_Value(-1); CSG_Colors Colors(3); Colors.Set_Color(0, SG_COLOR_BLACK); Colors.Set_Color(1, SG_COLOR_GREEN); Colors.Set_Color(2, SG_COLOR_RED ); DataObject_Add (m_pWator); DataObject_Set_Colors(m_pWator, Colors); DataObject_Update (m_pWator, 0, 2, SG_UI_DATAOBJECT_SHOW); //----------------------------------------------------- if( Parameters("REFRESH")->asBool() ) { double Fish_perc = Parameters("INIT_FISH" )->asDouble(); double Shark_perc = Parameters("INIT_SHARK")->asDouble() + Fish_perc; #pragma omp parallel for for(int y=0; y<m_pWator->Get_NY(); y++) { for(int x=0; x<m_pWator->Get_NX(); x++) { double perc = CSG_Random::Get_Uniform(0, 100); if( perc <= Fish_perc ) { m_pWator->Set_Value(x, y, FISH); } else if( perc <= Shark_perc ) { m_pWator->Set_Value(x, y, SHARK); } else { m_pWator->Set_Value(x, y, 0); } } } } //----------------------------------------------------- CSG_Table *pTable = Parameters("TABLE")->asTable(); pTable->Destroy(); pTable->Set_Name(_TL("Wa-Tor")); pTable->Add_Field("Cycle" , SG_DATATYPE_Int); pTable->Add_Field("Fishes", SG_DATATYPE_Int); pTable->Add_Field("Sharks", SG_DATATYPE_Int); //----------------------------------------------------- m_Fish_Birth = Parameters("FISH_BIRTH" )->asInt(); m_Shark_Birth = Parameters("SHARK_BIRTH" )->asInt(); m_Shark_Starve = Parameters("SHARK_STARVE")->asInt(); m_Next .Create(m_pWator, SG_DATATYPE_Byte); m_Age .Create(m_pWator, SG_DATATYPE_Byte); m_Starve.Create(m_pWator, SG_DATATYPE_Byte); #pragma omp parallel for for(int y=0; y<m_pWator->Get_NY(); y++) { for(int x=0; x<m_pWator->Get_NX(); x++) { switch( m_pWator->asByte(x, y) ) { case FISH: m_Age .Set_Value(x, y, CSG_Random::Get_Uniform(0.0, m_Fish_Birth )); break; case SHARK: m_Age .Set_Value(x, y, CSG_Random::Get_Uniform(0.0, m_Shark_Birth )); m_Starve.Set_Value(x, y, CSG_Random::Get_Uniform(0.0, m_Shark_Starve)); break; } } } //----------------------------------------------------- int i; SG_UI_Progress_Lock(true); for(i=1; Process_Get_Okay(true) && Next_Cycle(); i++) { Process_Set_Text("%s: %d", _TL("Life Cycle"), i); CSG_Table_Record *pRecord = pTable->Add_Record(); pRecord->Set_Value(0, i); pRecord->Set_Value(1, m_nFishes); pRecord->Set_Value(2, m_nSharks); DataObject_Update(m_pWator, 0, 2); DataObject_Update(pTable); } SG_UI_Progress_Lock(false); //----------------------------------------------------- m_Next .Destroy(); m_Age .Destroy(); m_Starve.Destroy(); if( is_Progress() ) { Message_Fmt("\n%s %d %s", _TL("Dead after"), i, _TL("Life Cycles")); } return( true ); }