### OverlappingModel for Texture Synthesis
Source: https://context7.com/mxgmn/wavefunctioncollapse/llms.txt
Generates textures by learning NxN pixel patterns from a source bitmap. Supports various parameters for output dimensions, periodicity, and symmetry. Includes an example with a ground constraint.
```csharp
var model = new OverlappingModel(
name: "Rooms", // Loads samples/Rooms.png
N: 3, // Pattern size (3x3 pixels)
width: 48, // Output width
height: 48, // Output height
periodicInput: true, // Treat input as tileable
periodic: true, // Output wraps around edges
symmetry: 8, // Use all rotations/reflections (1-8)
ground: false, // No ground constraint
heuristic: Model.Heuristic.Entropy // Minimum entropy heuristic
);
// Generate multiple variations
for (int i = 0; i < 5; i++)
{
if (model.Run(seed: i * 1000, limit: -1))
{
model.Save($"output/rooms-variation-{i}.png");
}
}
// Example with ground constraint (bottom row anchored)
var platformModel = new OverlappingModel(
name: "Platformer",
N: 3,
width: 64,
height: 32,
periodicInput: true,
periodic: true,
symmetry: 2, // Only horizontal reflection
ground: true, // Anchor bottom pattern
heuristic: Model.Heuristic.Scanline
);
```
--------------------------------
### Initialize and Run SimpleTiledModel
Source: https://context7.com/mxgmn/wavefunctioncollapse/llms.txt
Demonstrates how to instantiate and execute the SimpleTiledModel in C# for various generation scenarios.
```csharp
// Create simple tiled model from tileset XML
// Requires: tilesets/Knots.xml and tilesets/Knots/*.png tiles
var model = new SimpleTiledModel(
name: "Knots", // Loads tilesets/Knots.xml
subsetName: "Standard", // Use "Standard" tile subset (or null for all)
width: 24, // Output width in tiles
height: 24, // Output height in tiles
periodic: true, // Output wraps around
blackBackground: false, // Show partial states (not black)
heuristic: Model.Heuristic.Entropy
);
if (model.Run(seed: 42, limit: -1))
{
model.Save("output/knots.png");
}
// Castle tileset with Scanline heuristic for better connectivity
var castleModel = new SimpleTiledModel(
name: "Castle",
subsetName: null, // Use all tiles
width: 50,
height: 50,
periodic: false, // Non-periodic output
blackBackground: false,
heuristic: Model.Heuristic.Scanline
);
// Generate with text output for reconstruction
var summerModel = new SimpleTiledModel("Summer", null, 6, 6, false, false,
Model.Heuristic.Entropy);
if (summerModel.Run(seed: 100, limit: -1))
{
summerModel.Save("output/summer.png");
string textOutput = summerModel.TextOutput();
File.WriteAllText("output/summer.txt", textOutput);
// Output: "ground 0, ground 0, tree 2, ..."
}
```
--------------------------------
### Build and Run Commands for .NET Core
Source: https://context7.com/mxgmn/wavefunctioncollapse/llms.txt
Standard CLI commands for building, publishing, and executing the WaveFunctionCollapse project.
```bash
dotnet run --configuration Release WaveFunctionCollapse.csproj
```
```bash
dotnet publish --configuration Release WaveFunctionCollapse.csproj
```
```bash
./bin/publish/WaveFunctionCollapse.exe
```
--------------------------------
### Configure Observation Heuristics in C#
Source: https://context7.com/mxgmn/wavefunctioncollapse/llms.txt
Demonstrates initializing models with different heuristics and comparing their performance.
```csharp
// Entropy heuristic - best for most cases, minimizes contradictions
var entropyModel = new OverlappingModel("City", 3, 80, 80,
true, true, 8, false, Model.Heuristic.Entropy);
// MRV heuristic - faster, good for simple patterns
var mrvModel = new OverlappingModel("Wrinkles", 3, 120, 120,
false, true, 8, false, Model.Heuristic.MRV);
// Scanline heuristic - deterministic order, good for connected structures
var scanlineModel = new SimpleTiledModel("Castle", null, 50, 50,
false, false, Model.Heuristic.Scanline);
// Comparison of results
Console.WriteLine("Testing heuristics on same seed...");
foreach (var h in new[] { Model.Heuristic.Entropy, Model.Heuristic.MRV, Model.Heuristic.Scanline })
{
var model = new OverlappingModel("Rooms", 3, 48, 48, true, true, 8, false, h);
var sw = System.Diagnostics.Stopwatch.StartNew();
bool success = model.Run(seed: 42, limit: -1);
sw.Stop();
Console.WriteLine($"{h}: {(success ? "Success" : "Failed")} in {sw.ElapsedMilliseconds}ms");
}
```
--------------------------------
### Build Wave Function Collapse Application
Source: https://github.com/mxgmn/wavefunctioncollapse/blob/master/README.md
Use this command to build the Wave Function Collapse application in release mode. This prepares the application for deployment.
```bash
dotnet run --configuration Release WaveFunctionCollapse.csproj
```
--------------------------------
### Publish Wave Function Collapse Application
Source: https://github.com/mxgmn/wavefunctioncollapse/blob/master/README.md
Use this command to publish the Wave Function Collapse application. This creates a self-contained executable in the `bin/publish` folder.
```bash
dotnet publish --configuration Release WaveFunctionCollapse.csproj
```
--------------------------------
### Configure Batch Processing with samples.xml
Source: https://context7.com/mxgmn/wavefunctioncollapse/llms.txt
Configures multiple generation jobs for both Overlapping and Simple Tiled models in a single batch file.
```xml
```
--------------------------------
### Run Wave Function Collapse Algorithm
Source: https://context7.com/mxgmn/wavefunctioncollapse/llms.txt
Executes the WFC algorithm with a given seed and iteration limit. Returns true on success, false on contradiction. Handles retries for contradictions.
```csharp
Model model = new OverlappingModel("Flowers", N: 3, width: 48, height: 48,
periodicInput: true, periodic: true, symmetry: 8, ground: false,
heuristic: Model.Heuristic.Entropy);
int seed = 12345;
int limit = -1; // -1 means no limit
bool success = model.Run(seed, limit);
if (success)
{
model.Save("output/flowers-generated.png");
Console.WriteLine("Generation successful!");
}
else
{
Console.WriteLine("Contradiction encountered - retry with different seed");
}
// Retry pattern for handling contradictions
Random random = new Random();
for (int attempt = 0; attempt < 10; attempt++)
{
int trySeed = random.Next(10000);
if (model.Run(trySeed, limit: 1000))
{
model.Save($"output/result-{trySeed}.png");
break;
}
}
```
--------------------------------
### Define Tileset XML Configuration
Source: https://context7.com/mxgmn/wavefunctioncollapse/llms.txt
Defines tiles, symmetry types, adjacency constraints, and subsets for the SimpleTiledModel.
```xml
```
--------------------------------
### Load and Save Bitmaps with BitmapHelper
Source: https://context7.com/mxgmn/wavefunctioncollapse/llms.txt
Utilizes ImageSharp to load, manipulate, and save pixel data for pattern matching.
```csharp
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
// Load a bitmap image into pixel array
var (pixels, width, height) = BitmapHelper.LoadBitmap("samples/MyTexture.png");
Console.WriteLine($"Loaded {width}x{height} image with {pixels.Length} pixels");
// Analyze unique colors in sample
var uniqueColors = pixels.Distinct().ToList();
Console.WriteLine($"Sample contains {uniqueColors.Count} unique colors");
// Save generated bitmap to file
int[] generatedPixels = new int[64 * 64];
// ... fill with generated data ...
BitmapHelper.SaveBitmap(generatedPixels, 64, 64, "output/generated.png");
// Custom post-processing example
var (originalPixels, w, h) = BitmapHelper.LoadBitmap("output/rooms-42.png");
for (int i = 0; i < originalPixels.Length; i++)
{
// Convert to grayscale
int argb = originalPixels[i];
int r = (argb >> 16) & 0xff;
int g = (argb >> 8) & 0xff;
int b = argb & 0xff;
int gray = (r + g + b) / 3;
originalPixels[i] = unchecked((int)(0xff000000 | (gray << 16) | (gray << 8) | gray));
}
BitmapHelper.SaveBitmap(originalPixels, w, h, "output/rooms-grayscale.png");
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.