本文整理汇总了C#中Procedurality.Channel.normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Channel.normalize方法的具体用法?C# Channel.normalize怎么用?C# Channel.normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Procedurality.Channel
的用法示例。
在下文中一共展示了Channel.normalize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CratersAlgo
public static Channel CratersAlgo(int sizeX, int sizeY, int numCraters, int seed)
{
Channel chan = new Channel(sizeX, sizeY);
Console.WriteLine();
Random rand = new Random(seed);
for (int i = 0; i < numCraters; )
{
int x = rand.Next(0, sizeX);
int y = rand.Next(0, sizeY);
double radius = (rand.NextDouble() * 84.0) - 20;
// Clamp
//x=(x<0) ? 0 : ((x>size-1) ? size-1 : x);
//x=(y<0) ? 0 : ((y>size-1) ? size-1 : y);
//radius=(radius<20.0) ? 20.0 : ((radius>84.0) ? 84.0 : radius);
Channel crater = (new Crater(sizeX, sizeY, x, y, radius)).toChannel();
if (crater.findMax() != 1.0)
{
continue;
}
//if(crater.findMin()!=0.0)
//{
// Console.Write("!");
// continue;
//}
i++;
drawTextProgressBar(i, numCraters);
//crater.toLayer().saveAsPNG("../sims/crater_debug.png");
chan.channelAdd(crater.normalize(-0.01f, 0.01f));
}
chan.normalize();
Console.WriteLine("\nRange [{0},{1}]", chan.findMin(), chan.findMax());
return chan;
}
示例2: getDistance
public Channel getDistance(float c1, float c2, float c3)
{
Channel channel = new Channel(sizeX, sizeY);
for (int y = 0; y < sizeY; y++)
{
for (int x = 0; x < sizeX; x++)
{
channel.putPixel(x, y, c1*dist1.getPixel(x, y) + c2*dist2.getPixel(x, y) + c3*dist3.getPixel(x, y));
}
}
return channel.normalize();
}
示例3: Hill
public Hill(int size,int xp,int yp,float radius)
{
double r=(double)radius;
channel = new Channel(size,size);
double hill_height=5.0d*(radius/40.0d);
for(int x=0;x<size;x++)
{
for(int y=0;y<size;y++)
{
double dx = (double)(yp-x);
double dy = (double)(xp-y);
double dist = Math.Sqrt(dx*dx + dy*dy);
if(dist<radius)
{
double height = 1.0d-((dx*dx + dy*dy) / (r*r));
height = (height*hill_height);
channel.putPixel(x,y,Convert.ToSingle(height));//$radius^2 + (($x-$hx)^2 - ($y-(256-$hy))^2);
}
//channel.putPixel(x,y,(radius*radius) + (((x-dx)*(x-dx)) - ((y-dy)*(y-dy))));
}
}
channel.normalize();
}
示例4: Midpoint
//.........这里部分代码省略.........
for (x_block = 0; x_block < (1<<i); x_block+= (1<<i) - 1) {
x = x_block*block_size;
for (y_block = 0, y = 0; y_block < (1<<i); y_block++) {
v1 = channel.getPixel(x, y);
v2 = channel.getPixel((x + block_size) % size, y);
v3 = channel.getPixel(x, (y + block_size) % size);
v4 = channel.getPixel((x + block_size) % size, (y + block_size) % size);
v5 = 0.25f*(v1 + v2 + v3 + v4) + (float)random.NextDouble()*amp - amp_half;
channel.putPixel(x + block_size_half, y + block_size_half, v5);
y+= block_size;
}
}
// top and bottom edge blocks
for (x_block = 1, x = block_size; x_block < (1<<i) - 1; x_block++) {
for (y_block = 0; y_block < (1<<i); y_block+= (1<<i) - 1) {
y = y_block*block_size;
v1 = channel.getPixel(x, y);
v2 = channel.getPixel((x + block_size) % size, y);
v3 = channel.getPixel(x, (y + block_size) % size);
v4 = channel.getPixel((x + block_size) % size, (y + block_size) % size);
v5 = 0.25f*(v1 + v2 + v3 + v4) + (float)random.NextDouble()*amp - amp_half;
channel.putPixel(x + block_size_half, y + block_size_half, v5);
}
x+= block_size;
}
}
// calculate left and bottom edge midpoints
if (i < 2) {
for (x_block = 0, x = 0; x_block < (1<<i); x_block++) {
for (y_block = 0, y = 0; y_block < (1<<i); y_block++) {
v1 = channel.getPixel(x, y);
v5 = channel.getPixel(x + block_size_half, y + block_size_half);
v2 = channel.getPixel((x + block_size) % size, y);
v3 = channel.getPixel(x, (y + block_size) % size);
v6 = channel.getPixel(((x - block_size_half) + size) % size, (y + block_size_half) % size);
v7 = channel.getPixel((x + block_size_half) % size, ((y - block_size_half) + size) % size);
v8 = 0.25f*(v1 + v3 + v5 + v6) + (float)random.NextDouble()*amp - amp_half;
v9 = 0.25f*(v1 + v2 + v5 + v7) + (float)random.NextDouble()*amp - amp_half;
channel.putPixel(x, y + block_size_half, v8);
channel.putPixel(x + block_size_half, y, v9);
y+= block_size;
}
x+= block_size;
}
} else {
// safe blocks
for (x_block = 1, x = block_size; x_block < (1<<i) - 1; x_block++) {
for (y_block = 1, y = block_size; y_block < (1<<i) - 1; y_block++) {
v1 = channel.getPixel(x, y);
v5 = channel.getPixel(x + block_size_half, y + block_size_half);
v2 = channel.getPixel(x + block_size, y);
v3 = channel.getPixel(x, y + block_size);
v6 = channel.getPixel(x - block_size_half, y + block_size_half);
v7 = channel.getPixel(x + block_size_half, y - block_size_half);
v8 = 0.25f*(v1 + v3 + v5 + v6) + (float)random.NextDouble()*amp - amp_half;
v9 = 0.25f*(v1 + v2 + v5 + v7) + (float)random.NextDouble()*amp - amp_half;
channel.putPixel(x, y + block_size_half, v8);
channel.putPixel(x + block_size_half, y, v9);
y+= block_size;
}
x+= block_size;
}
// left and right edge blocks
for (x_block = 0; x_block < (1<<i); x_block+= (1<<i) - 1) {
x = x_block*block_size;
for (y_block = 0, y = 0; y_block < (1<<i); y_block++) {
v1 = channel.getPixel(x, y);
v5 = channel.getPixel(x + block_size_half, y + block_size_half);
v2 = channel.getPixel((x + block_size) % size, y);
v3 = channel.getPixel(x, (y + block_size) % size);
v6 = channel.getPixel(((x - block_size_half) + size) % size, (y + block_size_half) % size);
v7 = channel.getPixel((x + block_size_half) % size, ((y - block_size_half) + size) % size);
v8 = 0.25f*(v1 + v3 + v5 + v6) + (float)random.NextDouble()*amp - amp_half;
v9 = 0.25f*(v1 + v2 + v5 + v7) + (float)random.NextDouble()*amp - amp_half;
channel.putPixel(x, y + block_size_half, v8);
channel.putPixel(x + block_size_half, y, v9);
y+= block_size;
}
}
// top and bottom edge blocks
for (x_block = 1, x = block_size; x_block < (1<<i) - 1; x_block++) {
for (y_block = 0; y_block < (1<<i); y_block+= (1<<i) - 1) {
y = y_block*block_size;
v1 = channel.getPixel(x, y);
v5 = channel.getPixel(x + block_size_half, y + block_size_half);
v2 = channel.getPixel((x + block_size) % size, y);
v3 = channel.getPixel(x, (y + block_size) % size);
v6 = channel.getPixel(((x - block_size_half) + size) % size, (y + block_size_half) % size);
v7 = channel.getPixel((x + block_size_half) % size, ((y - block_size_half) + size) % size);
v8 = 0.25f*(v1 + v3 + v5 + v6) + (float)random.NextDouble()*amp - amp_half;
v9 = 0.25f*(v1 + v2 + v5 + v7) + (float)random.NextDouble()*amp - amp_half;
channel.putPixel(x, y + block_size_half, v8);
channel.putPixel(x + block_size_half, y, v9);
}
x+= block_size;
}
}
}
channel.normalize();
}
示例5: Gen
//.........这里部分代码省略.........
for (x_block = 1, x = block_size; x_block < (1<<i) - 1; x_block++) {
for (y_block = 0; y_block < (1<<i); y_block+= (1<<i) - 1) {
y = y_block*block_size;
v1 = channel.getPixel(x, y);
v2 = channel.getPixel((x + block_size) % sizeX, y);
v3 = channel.getPixel(x, (y + block_size) % sizeY);
v4 = channel.getPixel((x + block_size) % sizeX, (y + block_size) % sizeY);
avr = 0.25f*(v1 + v2 + v3 + v4);
v5 = avr*(1f + (float)random.NextDouble()*amp - amp_half);
channel.putPixel(x + block_size_half, y + block_size_half, v5);
}
x+= block_size;
}
}
// calculate left and bottom edge midpoints
if (i < 2) {
for (x_block = 0, x = 0; x_block < (1<<i); x_block++) {
for (y_block = 0, y = 0; y_block < (1<<i); y_block++) {
v1 = channel.getPixel(x, y);
v5 = channel.getPixel(x + block_size_half, y + block_size_half);
v2 = channel.getPixel((x + block_size) % sizeX, y);
v3 = channel.getPixel(x, (y + block_size) % sizeY);
v6 = channel.getPixel(((x - block_size_half) + sizeX) % sizeX, (y + block_size_half) % sizeY);
v7 = channel.getPixel((x + block_size_half) % sizeX, ((y - block_size_half) + sizeY) % sizeY);
avr = 0.25f*(v1 + v3 + v5 + v6);
v8 = avr*(1f + (float)random.NextDouble()*amp - amp_half);
avr = 0.25f*(v1 + v2 + v5 + v7);
v9 = avr*(1f + (float)random.NextDouble()*amp - amp_half);
channel.putPixel(x, y + block_size_half, v8);
channel.putPixel(x + block_size_half, y, v9);
y+= block_size;
}
x+= block_size;
}
} else {
// safe blocks
for (x_block = 1, x = block_size; x_block < (1<<i) - 1; x_block++) {
for (y_block = 1, y = block_size; y_block < (1<<i) - 1; y_block++) {
v1 = channel.getPixel(x, y);
v5 = channel.getPixel(x + block_size_half, y + block_size_half);
v2 = channel.getPixel(x + block_size, y);
v3 = channel.getPixel(x, y + block_size);
v6 = channel.getPixel(x - block_size_half, y + block_size_half);
v7 = channel.getPixel(x + block_size_half, y - block_size_half);
avr = 0.25f*(v1 + v3 + v5 + v6);
v8 = avr*(1f + (float)random.NextDouble()*amp - amp_half);
avr = 0.25f*(v1 + v2 + v5 + v7);
v9 = avr*(1f + (float)random.NextDouble()*amp - amp_half);
channel.putPixel(x, y + block_size_half, v8);
channel.putPixel(x + block_size_half, y, v9);
y+= block_size;
}
x+= block_size;
}
// left and right edge blocks
for (x_block = 0; x_block < (1<<i); x_block+= (1<<i) - 1) {
x = x_block*block_size;
for (y_block = 0, y = 0; y_block < (1<<i); y_block++) {
v1 = channel.getPixel(x, y);
v5 = channel.getPixel(x + block_size_half, y + block_size_half);
v2 = channel.getPixel((x + block_size) % sizeX, y);
v3 = channel.getPixel(x, (y + block_size) % sizeY);
v6 = channel.getPixel(((x - block_size_half) + sizeX) % sizeX, (y + block_size_half) % sizeY);
v7 = channel.getPixel((x + block_size_half) % sizeX, ((y - block_size_half) + sizeY) % sizeY);
avr = 0.25f*(v1 + v3 + v5 + v6);
v8 = avr*(1f + (float)random.NextDouble()*amp - amp_half);
avr = 0.25f*(v1 + v2 + v5 + v7);
v9 = avr*(1f + (float)random.NextDouble()*amp - amp_half);
channel.putPixel(x, y + block_size_half, v8);
channel.putPixel(x + block_size_half, y, v9);
y+= block_size;
}
}
// top and bottom edge blocks
for (x_block = 1, x = block_size; x_block < (1<<i) - 1; x_block++) {
for (y_block = 0; y_block < (1<<i); y_block+= (1<<i) - 1) {
y = y_block*block_size;
v1 = channel.getPixel(x, y);
v5 = channel.getPixel(x + block_size_half, y + block_size_half);
v2 = channel.getPixel((x + block_size) % sizeX, y);
v3 = channel.getPixel(x, (y + block_size) % sizeY);
v6 = channel.getPixel(((x - block_size_half) + sizeX) % sizeX, (y + block_size_half) % sizeY);
v7 = channel.getPixel((x + block_size_half) % sizeX, ((y - block_size_half) + sizeY) % sizeY);
avr = 0.25f*(v1 + v3 + v5 + v6);
v8 = avr*(1f + (float)random.NextDouble()*amp - amp_half);
avr = 0.25f*(v1 + v2 + v5 + v7);
v9 = avr*(1f + (float)random.NextDouble()*amp - amp_half);
channel.putPixel(x, y + block_size_half, v8);
channel.putPixel(x + block_size_half, y, v9);
}
x+= block_size;
}
}
}
float[] mm=channel.findMinMax();
//Console.WriteLine("Range Mountain->[{0},{1}]",mm[0],mm[1]);
channel.normalize();
mm=channel.findMinMax();
//Console.WriteLine("Range Mountain->[{0},{1}]",mm[0],mm[1]);
}
示例6: HillsAlgo
public static Channel HillsAlgo(int sizeX, int sizeY, int numHills, int seed)
{
Console.WriteLine();
Channel chan = new Channel(sizeX, sizeY);
Random rand = new Random(seed);
for (int i = 0; i < numHills; )
{
int x = rand.Next(0, sizeX);
int y = rand.Next(0, sizeY);
double radius = ((rand.NextDouble() * 84.0) - 20);
Channel crater = (new Hill(sizeX, sizeY, x, y, (float)radius)).toChannel();
if (crater.findMax() != 1.0)
{
continue;
}
i++;
drawTextProgressBar(i, numHills);
//crater.toLayer().saveAsPNG("../sims/crater_debug.png");
chan.channelAdd(crater.normalize(0f, 0.01f));
}
chan.normalize();
Console.WriteLine("\nRange [{0},{1}]", chan.findMin(), chan.findMax());
return chan;
}