long long tiles(long long n){ if(dp[n]!=-1) return dp[n]; if((n==1)||(n==2)||(n==3)) return dp[n]=1; if(n==4) return dp[n]=2; return dp[n]=tiles(n-1)+tiles(n-4); }
void colour_vegetation (Planet_colours& c, const Planet& p, const Season& s) { static const Colour snow = Colour(1.0, 1.0, 1.0); static const Colour water_deep = Colour(0.05, 0.05, 0.20); static const Colour water_shallow = Colour(0.04, 0.22, 0.42); static const Colour land_low = Colour(0.95, 0.81, 0.53); static const Colour land_high = Colour(0.1, 0.1, 0.1); static const Colour vegetation = Colour(0.176, 0.32, 0.05); for (const Tile& t : tiles(p)) { if (is_water(nth_tile(terrain(p) ,id(t)))) { double d = std::min(1.0f, water_depth(nth_tile(terrain(p), id(t)))/400); c.tiles[id(t)] = interpolate(water_shallow, water_deep, d); } else { auto& climate = nth_tile(s, id(t)); if (temperature(climate) <= freezing_point()) c.tiles[id(t)] = snow; else { double d = std::min(1.0, (elevation(nth_tile(terrain(p), id(t))) - sea_level(p))/2500); Colour ground = interpolate(land_low, land_high, d); double v = std::min(1.0f, aridity(climate)/1.5f); c.tiles[id(t)] = interpolate(vegetation, ground, v); } } } }
void colour_temperature (Planet_colours& c, const Planet& p, const Season& s) { static const Colour col[8] = { Colour(1.0, 1.0, 1.0), Colour(0.7, 0, 0.5), Colour(0, 0, 0.5), Colour(0, 0, 1.0), Colour(0, 1.0, 1.0), Colour(1.0, 1.0, 0), Colour(1.0, 0.1, 0), Colour(0.45, 0, 0)}; static float limits[8] = {-50, -35, -20, -10, 0, 10, 20, 30}; for (const Tile& t : tiles(p)) { float temp = temperature(nth_tile(s, id(t))) - freezing_point(); if (temp <= limits[0]) c.tiles[id(t)] = col[0]; else if (temp >= limits[7]) c.tiles[id(t)] = col[7]; else { for (int i=0; i<7; i++) { if (temp >= limits[i] && temp < limits[i+1]) { double d = (temp - limits[i]) / (limits[i+1] - limits[i]); c.tiles[id(t)] = interpolate(col[i], col[i+1], d); break; } } } } }
void MainForm::populateScene() { stop = false; std::pair<int, int> min_norm, max_norm; calculateMinMaxPoint(min_norm, max_norm, *bf_); size_t range = static_cast<size_t>(max_norm.second - min_norm.second + 1); boost::progress_display show_progress(range); std::list<std::vector<int> > tiles(range); size_t tiles_nr = fillTiles(tiles, *bf_, min_norm, max_norm, show_progress); tbb::atomic<size_t> progress_index, mem_index; progress_index = 0; mem_index = 0; show_progress.restart(tiles_nr); std::list<std::vector<int> >::iterator it = tiles.begin(); tbb::task_scheduler_init init; for (int i = min_norm.second; i <= max_norm.second; ++i) { tbb::parallel_for(tbb::blocked_range<std::vector<int>::iterator> (it->begin(), it->end()), ApplyFooQT(this, i, &progress_index)); if (stop) break; ++it; show_progress += progress_index; progress_index = 0; } bf_->clear_cache(); }
void colour_aridity (Planet_colours& c, const Planet& p, const Season& s) { static const Colour water = Colour(1.0, 1.0, 1.0); static const Colour col[4] = { Colour(1.0, 0.0, 0.0), Colour(1.0, 1.0, 0.0), Colour(0.0, 1.0, 0.0), Colour(0.0, 0.5, 0.0)}; float limits[4] = {2.0f, 1.0f, 0.5f, 0.0f}; for (const Tile& t : tiles(p)) { if (is_water(nth_tile(terrain(p) ,id(t)))) c.tiles[id(t)] = water; else { float ar = aridity(nth_tile(s, id(t))); c.tiles[id(t)] = col[3]; for (int i=1; i<4; i++) { if (ar > limits[i]) { double d = std::min(1.0f, (ar - limits[i]) / (limits[i-1] - limits[i])); c.tiles[id(t)] = interpolate(col[i], col[i-1], d); break; } } } } }
//Init of tiles vector. Must be called. void Map::CreateTiles(int newmapwidth, int newmapheight) { height_ = newmapheight; width_ = newmapwidth; std::vector<std::vector<Tile>> tiles(newmapwidth,std::vector<Tile>(newmapheight)); tiles_ = tiles; }
static std::vector<FrameTile> tilesFromFrameImage(const Image& image, const std::vector<Snes::SnesColor>& palettes, unsigned colorsPerPalette, InvalidImageError& err) { const static unsigned TS = 8; const usize iSize = image.size(); unsigned tw = iSize.width / TS; unsigned th = iSize.height / TS; std::vector<FrameTile> tiles(tw * th); auto tileIt = tiles.begin(); for (unsigned y = 0; y < iSize.height; y += TS) { for (unsigned x = 0; x < iSize.width; x += TS) { bool s = extractFrameTile(*tileIt, image, x, y, palettes, colorsPerPalette); if (!s) { err.addInvalidTile(TS, x, y, InvalidImageError::NO_PALETTE_FOUND); } tileIt++; } } assert(tileIt == tiles.end()); return tiles; }
void HexagonalBoard::buildEdges() { std::vector<TileInterface*> boardTiles = tiles(); std::vector<AxialHexCoordinate> neighbors = AxialHexCoordinate::localNeighborsCw(); for(TileInterface* tile: boardTiles){ DefaultHexTile* resourceTile = static_cast<DefaultHexTile*>(tile); for(AxialHexCoordinate neighborCoord: neighbors){ AxialHexCoordinate neighborGlobal = mapToGcs(neighborCoord, tile); auto neighborItr = vBoard.find(neighborGlobal); if(neighborItr != vBoard.cend()){ DefaultHexTile* neighborTile = static_cast<DefaultHexTile*>(neighborItr->second); assert(neighborTile); if(resourceTile->edge(neighborCoord) == nullptr){ std::shared_ptr<EdgeInterface> commonEdge( new RoadEdge ); commonEdge->setTiles({tile, neighborTile}); resourceTile->setEdge(neighborCoord, commonEdge); neighborTile->setEdge(neighborCoord.reverse(), commonEdge); } } else { std::shared_ptr<EdgeInterface> uniqueEdge( new RoadEdge ); uniqueEdge->setTiles({tile}); resourceTile->setEdge(neighborCoord, uniqueEdge); } } } }
void GameBoard::initializeGL( QGLWidget & target ) { QImage wall( "textures/wall.jpg" ); this->wallTexture = target.bindTexture( wall ); QImage grass( "textures/grass.jpg" ); this->grassTexture = target.bindTexture( grass ); QImage roof( "textures/roof.jpg" ); this->roofTexture = target.bindTexture( roof ); QImage tiles( "textures/tiles.jpg" ); this->ghostsStartTexture = target.bindTexture( tiles ); QImage dot( "textures/dot.png" ); this->dotTexture = target.bindTexture( dot ); this->staticList = glGenLists( 1 ); glNewList( this->staticList, GL_COMPILE ); { for ( int y = 0; y < this->height; ++y ) { for ( int x = 0; x < this->width; ++x ) { if ( GameBoard::Wall == this->blocks[ y ][ x ] ) { this->addWallBlock( x, y ); } else if ( GameBoard::Path == this->blocks[ y ][ x ] ) { this->addGrassBlock( x, y ); } else if ( GameBoard::Dot == this->blocks[ y ][ x ] ) { this->addGrassBlock( x, y ); } else if ( GameBoard::Powerup == this->blocks[ y ][ x ] ) { this->addGrassBlock( x, y ); } else if ( GameBoard::Teleport1 == this->blocks[ y ][ x ] ) { this->addGrassBlock( x, y ); } else if ( GameBoard::PlayerStart == this->blocks[ y ][ x ] ) { this->addGrassBlock( x, y ); } else if ( GameBoard::PlayerWall == this->blocks[ y ][ x ] ) { this->addFloorBlock( x, y, this->roofTexture, this->defaultMaterial ); } else if ( GameBoard::GhostsStart == this->blocks[ y ][ x ] ) { this->addFloorBlock( x, y, this->ghostsStartTexture, this->defaultMaterial ); } } } } glEndList(); this->dotList = glGenLists( 1 ); this->dotQuadric = gluNewQuadric(); gluQuadricTexture( this->dotQuadric, true ); glNewList( this->dotList, GL_COMPILE ); { glBindTexture( GL_TEXTURE_2D, this->dotTexture ); gluSphere( this->dotQuadric, 0.1f, 360 / 30, 180 / 30 ); } glEndList(); }
void MapType_Hocus::write(MapPtr map, stream::expanding_output_sptr output, ExpandingSuppData& suppData) const { Map2DPtr map2d = boost::dynamic_pointer_cast<Map2D>(map); if (!map2d) throw stream::error("Cannot write this type of map as this format."); if (map2d->getLayerCount() != 2) throw stream::error("Incorrect layer count for this format."); unsigned int mapWidth, mapHeight; map2d->getMapSize(&mapWidth, &mapHeight); Map2D::LayerPtr layer; // Write the background layer boost::scoped_array<uint8_t> tiles(new uint8_t[HP_MAP_SIZE]); // Set the default background tile memset(tiles.get(), HP_DEFAULT_TILE_BG, HP_MAP_SIZE); layer = map2d->getLayer(0); const Map2D::Layer::ItemPtrVectorPtr itemsBG = layer->getAllItems(); for (Map2D::Layer::ItemPtrVector::const_iterator i = itemsBG->begin(); i != itemsBG->end(); i++ ) { assert(((*i)->x < mapWidth) && ((*i)->y < mapHeight)); tiles[(*i)->y * mapWidth + (*i)->x] = (*i)->code; } output->write((char *)tiles.get(), HP_MAP_SIZE); output->flush(); assert(output->tellp() == 14400); // Write the foreground layer stream::output_sptr layerFile = suppData[SuppItem::Layer1]; assert(layerFile); // Set the default background tile memset(tiles.get(), HP_DEFAULT_TILE_FG, HP_MAP_SIZE); layer = map2d->getLayer(1); const Map2D::Layer::ItemPtrVectorPtr itemsFG = layer->getAllItems(); for (Map2D::Layer::ItemPtrVector::const_iterator i = itemsFG->begin(); i != itemsFG->end(); i++ ) { assert(((*i)->x < mapWidth) && ((*i)->y < mapHeight)); tiles[(*i)->y * mapWidth + (*i)->x] = (*i)->code; } layerFile->seekp(0, stream::start); layerFile->write((char *)tiles.get(), HP_MAP_SIZE); layerFile->flush(); assert(layerFile->tellp() == 14400); return; }
Tile * Tile::get(const std::string & filename) { if (tiles().find(filename) != tiles().end()) { return tiles()[filename]; } // std::cout << "Loading new tile " << filename << std::endl << std::flush; Tile * t = new Tile(); t->load(filename); if (!t->loaded()) { std::cerr << "Failed to load texture " << filename << std::endl << std::flush; return NULL; } tiles()[filename] = t; return t; }
void _set_humidity (const Planet& planet, const Climate_parameters& par, Climate_generation_season& season) { for (auto& t : tiles(planet)) { float humidity = 0.0; if (is_water(nth_tile(terrain(planet), id(t)))) { humidity = saturation_humidity(season.tiles[id(t)].temperature); } season.tiles[id(t)].humidity = humidity; } _iterate_humidity(planet, par, season); }
void get_tiles(float s[DECAY_COUNT], int a, int tile_array[], unsigned int num_tilings, unsigned int memory_size) { float vals[2]; vals[0] = s[0]*10; vals[1] = s[1]*10; tiles(tile_array, num_tilings, memory_size, vals, 2, &a, 1); }
PTileListModel groupedTilesModel(const TileGroup &tile_group, bool only_uniform) { vector<const Tile*> tiles(tile_group.groupCount()); for(int n = 0; n < tile_group.entryCount(); n++) { int group_id = tile_group.entryGroup(n); if(!tiles[group_id] && (!only_uniform || tile_group.isGroupSurfaceUniform(group_id))) tiles[group_id] = tile_group.entryTile(n); } tiles.resize(remove(tiles.begin(), tiles.end(), nullptr) - tiles.begin()); return make_shared<VectorBasedModel>(tiles); }
unsigned TileGrid::blankPixelCount() const { PlatformLayerList tiles(m_tiles.size()); for (TileMap::const_iterator it = m_tiles.begin(), end = m_tiles.end(); it != end; ++it) { if (PlatformLayer *layer = it->value.layer->platformLayer()) tiles.append(layer); } return TileController::blankPixelCountForTiles(tiles, m_controller.visibleRect(), IntPoint(0, 0)); }
void flush(stream::inout& content, const Point& mapSize) { std::vector<uint8_t> tiles(mapSize.x * mapSize.y, WR_DEFAULT_BGTILE); for (auto& t : this->v_allItems) { if ((t.pos.x > mapSize.x) || (t.pos.y > mapSize.y)) { throw stream::error(createString("Layer has tiles outside map " "boundary at (" << t.pos.x << "," << t.pos.y << ")")); } tiles[t.pos.y * mapSize.x + t.pos.x] = t.code; } rleWrite(content, tiles); }
main(){ int opt; scanf("%d",&opt); for(int i=0;i<opt;i++){ long long n; memset(dp, -1, sizeof dp); scanf("%lld",&n); printf("%lld\n",tiles(n)); } }
// Jumble Tile Positions void Puzzle::jumbleTilePositions() { std::vector<int> tiles(mTiles.size()); for (unsigned i = 0; i < tiles.size(); i++) tiles[i] = i; std::random_shuffle(tiles.begin(), tiles.end()); for (unsigned i = 0; i < mTiles.size(); i++) { mTiles[i].first->setPosition(mGrid.getTilePos(tiles[i])); mTiles[i].second = tiles[i]; } }
void createSomeModel(int numTiles) { std::vector<MoTile> tiles(numTiles, MoTile(QImage(20, 30, QImage::Format_RGBA8888))); model.constructInitialState(targetImage, tiles); std::vector<float> x(numTiles); model.setXCoords(&x[0], &x[0] + numTiles); std::vector<float> y(numTiles); model.setXCoords(&y[0], &y[0] + numTiles); std::vector<float> rotations(numTiles, 0.0f); model.setRotations(&rotations[0], &rotations[0] + numTiles); std::vector<float> scales(numTiles, 0.0f); model.setRotations(&scales[0], &scales[0] + numTiles); }
void _set_wind (const Planet& planet, const Climate_parameters&, Climate_generation_season& season) { for (auto& t : tiles(planet)) { season.tiles[id(t)].wind = _default_wind(planet, id(t), season.tropical_equator); season.tiles[id(t)].wind.direction += north(planet, &t); } for (auto& t : tiles(planet)) { //tile shape in 2d, rotated according to wind direction std::vector<Vector2> corners = rotation_matrix(north(planet, &t) - season.tiles[id(t)].wind.direction) * polygon(&t, rotation_to_default(planet)); int e = edge_count(t); for (int k=0; k<e; k++) { int direction = sign(nth_edge(t, k), &t); if (corners[k].x + corners[(k+1)%e].x < 0) direction *= -1; season.edges[id(nth_edge(t, k))].wind_velocity -= 0.5 * direction * season.tiles[id(t)].wind.speed * std::abs(corners[k].y - corners[(k+1)%e].y) / length(corners[k] - corners[(k+1)%e]); } } }
void HexagonalBoard::buildVertices() { std::vector<TileInterface*> boardTiles = tiles(); std::vector<AxialHexCoordinate> vertices = AxialHexCoordinate::localVerticesCw(); std::vector<AxialHexCoordinate> edges = AxialHexCoordinate::localNeighborsCw(); for(TileInterface* tile: boardTiles){ DefaultHexTile* currentTile = static_cast<DefaultHexTile*>(tile); for(std::vector<AxialHexCoordinate>::size_type i = 0; i < vertices.size(); ++i){ VertexInterface* vertex = currentTile->vertex(vertices[i]); if(vertex == nullptr){ std::shared_ptr<VertexInterface> sharedVertex(new DefaultVertex); currentTile->setVertex(vertices[i], sharedVertex); std::set<TileInterface*> vertexTiles; std::set<EdgeInterface*> vertexEdges; EdgeInterface* cwEdge = currentTile->edge(edges[i]); assert(cwEdge); vertexEdges.insert(cwEdge); auto cwTiles = cwEdge->tiles(); for(TileInterface* edgeTile: cwTiles){ if(edgeTile == tile) { // Do nothing } else if(edgeTile){ vertexTiles.insert(edgeTile); vertexEdges.insert(static_cast<DefaultHexTile*>(edgeTile)->edge(edges[(i + 4) % 6])); static_cast<DefaultHexTile*>(edgeTile)->setVertex(vertices[(i + 4) % 6], sharedVertex); } } EdgeInterface* ccwEdge = currentTile->edge(edges[(i + 5) % 6]); assert(ccwEdge); vertexEdges.insert(ccwEdge); auto ccwTiles = ccwEdge->tiles(); for(TileInterface* edgeTile: ccwTiles){ if(edgeTile == tile) { // Do nothing } else if(edgeTile){ vertexTiles.insert(edgeTile); vertexEdges.insert(static_cast<DefaultHexTile*>(edgeTile)->edge(edges[(i + 1) % 6])); static_cast<DefaultHexTile*>(edgeTile)->setVertex(vertices[(i + 2) % 6], sharedVertex); } } sharedVertex->setTiles(std::vector<TileInterface*>(vertexTiles.begin(), vertexTiles.end())); sharedVertex->setEdges(std::vector<EdgeInterface*>(vertexEdges.begin(), vertexEdges.end())); } } } }
void runit (int num=10, int ct=2048, int numt=1) { int i,j; float vars[2]; int* the_tiles = (int*) malloc(numt*sizeof(int)); for (i=0; i<num; i++) { for (j=0; j<num; j++) { vars[0] = i*0.5; vars[1] = j*0.5; tiles(the_tiles, numt, ct, vars, 2, NULL, 0); } } }
void runitl (int num=10, int ct=2048, int numt=1) { int i,j; float vars[2]; int* tlist = (int*)malloc((num*num*numt)*sizeof(int)); for (i=0; i < num; i++) { for (j=0; j < num; j++) { vars[0] = i*0.5; vars[1] = j*0.5; tiles(tlist+(i*num*num+j), numt, ct, vars, 2,NULL,0); } } }
void runitn_ct (int num=10, collision_table* ct=NULL, int numt=4) { int i,j; float vars[2]; int* the_tiles = (int*)malloc(numt*sizeof(int)); for (i=0; i < num; i++) { for (j=0; j < num; j++) { vars[0] = i*0.5; vars[1] = j*0.5; tiles(the_tiles,numt, ct, vars, 2, NULL, 0); } } }
Surface ShpFile::getSurfaceArray(uint8_t tilesX, uint8_t tilesY, ...) { std::vector<uint32_t> tiles(tilesX*tilesY); va_list arg_ptr; va_start(arg_ptr, tilesY); for(uint32_t i = 0; i < tilesX*tilesY; i++) { tiles[i] = va_arg( arg_ptr, uint32_t ); if(getIndex(tiles[i]) >= _size) throw(Exception(LOG_ERROR, "ShpFile", "getSurfaceArray(): There exist only %d files in this *.shp.",_size)); } va_end(arg_ptr); return getSurfaceArray(tilesX, tilesY, &tiles.front()); }
void _set_temperature (const Planet& planet, const Climate_parameters&, Climate_generation_season& season) { auto temperature_at_latitude = [](float latitude) { return freezing_point() - 25 + 50*cos(latitude); }; for (auto& t : tiles(planet)) { float temperature = temperature_at_latitude(season.tropical_equator - latitude(planet, vector(t))); if (is_land(nth_tile(terrain(planet), id(t)))) { if (elevation(nth_tile(terrain(planet), id(t))) > sea_level(planet)) temperature -= temperature_lapse(elevation(nth_tile(terrain(planet), id(t))) - sea_level(planet)); } else { temperature = 0.3*temperature + 0.7*temperature_at_latitude(latitude(planet, vector(t))); } season.tiles[id(t)].temperature = temperature; } }
void runit2 (int num=10, int ct=2048, int numt=1) { int i,j; float vars[4]; int ints[2]; int* the_tiles = (int*)malloc(numt*sizeof(int)); for (i=0; i < num; i++) { for (j=0; j < num; j++) { vars[0] = i*0.5; vars[1] = j*0.5; vars[2] = float(i+j)/2; vars[3] = float(i-j)/2; ints[0] = i; ints[1] = j; tiles(the_tiles, numt, ct, vars, 4, ints, 2); } } }
void colour_topography (Planet_colours& c, const Planet& p) { static const Colour water_deep = Colour(0.0, 0.0, 0.25); static const Colour water = Colour(0.0, 0.12, 0.5); static const Colour water_shallow = Colour(0.0, 0.4, 0.6); static const Colour land[6] = { Colour(0.0, 0.4, 0.0), Colour(0.0, 0.7, 0.0), Colour(1.0, 1.0, 0.0), Colour(1.0, 0.5, 0.0), Colour(0.7, 0.0, 0.0), Colour(0.1, 0.1, 0.1)}; double land_limits[7] = {-500, 0, 500, 1000, 1500, 2000, 2500}; for (const Tile& t : tiles(p)) { const Terrain_tile& ter = nth_tile(terrain(p), id(t)); double elev = elevation(ter) - sea_level(p); if (is_water(ter)) { if (elev < -1000) { c.tiles[id(t)] = water_deep; } else if (elev < -500) { double d = (elev+500)/(-500); c.tiles[id(t)] = interpolate(water, water_deep, d); } else { double d = elev/(-500); c.tiles[id(t)] = interpolate(water_shallow, water, d); } } else { c.tiles[id(t)] = land[5]; for (int i=0; i<5; i++) { if (elev <= land_limits[i+1]) { double d = std::max(0.0, std::min(1.0, (elev - land_limits[i]) / (land_limits[i+1] - land_limits[i]))); c.tiles[id(t)] = interpolate(land[i], land[i+1], d); break; } } } } }
void colour_humidity (Planet_colours& c, const Planet& p, const Season& s) { static const Colour water = Colour(1.0, 1.0, 1.0); static const Colour land_dry = Colour(1.0, 1.0, 0.5); static const Colour land_mid = Colour(1.0, 1.0, 0.0); static const Colour land_humid = Colour(0.0, 0.7, 0.0); for (const Tile& t : tiles(p)) { double h = humidity(nth_tile(s, id(t))) / saturation_humidity(temperature(nth_tile(s, id(t)))); if (is_water(nth_tile(terrain(p), id(t)))) { c.tiles[id(t)] = water; } else { if (h <= 0.5) { double d = h / 0.5; c.tiles[id(t)] = interpolate(land_dry, land_mid, d); } else { double d = (h-0.5)/0.5; c.tiles[id(t)] = interpolate(land_mid, land_humid, d); } } } }
void contour_phi( const Vec3d& domain_low, double domain_dx, Array3d& phi, std::vector<Vec3st>& tris, std::vector<Vec3d>& verts ) { MarchingTilesHiRes tiles( domain_low, domain_dx, phi ); std::cout << "Contouring..." << std::endl; tiles.contour(); std::cout << "Improving..." << std::endl; tiles.improve_mesh(); std::cout << "Copying..." << std::endl; for ( size_t i = 0; i < tiles.tri.size(); ++i ) { tris.push_back( Vec3st( tiles.tri[i] ) ); } for ( size_t i = 0; i < tiles.x.size(); ++i ) { verts.push_back( tiles.x[i] ); } std::cout << "done" << std::endl; }