wfc 1.0.1 copy "wfc: ^1.0.1" to clipboard
wfc: ^1.0.1 copied to clipboard

retracted

A package providing procedural map generation using the Wave Function Collapse algorithm.

example/example.dart

import 'dart:io';
import 'dart:math';

import 'package:wfc/src/base_model.dart';

import '../wfc.dart';

void main() async {
  // Set up paths
  final String currentDirectory = Directory.current.path;
  final String jsonPath = "$currentDirectory/assets/samples.json";
  final String outputPath = "$currentDirectory/example_output/";

  // Clean the output directory
  final outputDirectory = Directory(outputPath);
  if (!outputDirectory.existsSync()) {
    outputDirectory.createSync();
  } else {
    outputDirectory.listSync().whereType<File>().forEach((file) => file.deleteSync());
  }

  // Load the sample tile data
  final tiles = await parseTilesFromFile(jsonPath);

  // Create a random seed
  final random = Random();
  int seed = random.nextInt(1 << 32);

  // Pick the first tile to demonstrate
  if (tiles.isNotEmpty) {
    final tile = tiles.first;

    // Create a model from the tile
    final model = createModel(tile, currentDirectory);

    // Run the algorithm and save the output
    if (model.run(seed, tile.limit)) {
      model.save(outputPath, tile, seed);
      print("Example completed successfully. Output saved to $outputPath");
    } else {
      print("A contradiction occurred while running the algorithm.");
    }
  } else {
    print("No tiles found in $jsonPath.");
  }
}
3
likes
0
points
288
downloads

Publisher

unverified uploader

Weekly Downloads

A package providing procedural map generation using the Wave Function Collapse algorithm.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

image, xml

More

Packages that depend on wfc