• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Voronoi Diagrams gets drawn in wrong colors.

I followed this youtube tutorial to create Voronoi Diagrams using surfaces in game maker 2. so far it works but my colors are not really random but they are all a dark redish. I could not figure out where this happens, though.

oMapGeneration
GML:
/// Create Event
randomize();

// Create surface
global.width = room_width;
global.height = room_height;
global.biome_surface = surface_create(global.width,global.height);

// Seeds to create
seeds = 8;

// Create seed
repeat (seeds) {
    var xx = irandom(global.width);
    var yy = irandom(global.height);
    with instance_create_layer(xx,yy,layer,oSeed) {
        var red = irandom(255);
        var green = irandom(255);
        var blue = irandom(255);
        biome_color = make_color_rgb(red,green,blue);
    }
}
// Create object that draws
instance_create_layer(0,0,layer,oBiomeCreate);
GML:
/// draw event
draw_surface_ext(global.biome_surface,0,0,1,1,0,c_white,1);
oSeed
Code:
//Create Event
biome_color = c_white;
biome_name = "";
depth = -1000;
oBiomeCreate
GML:
///Create Event
for (var xx = 0; xx < global.width; xx++) {
    for (var yy = 0; yy < global.height; yy++) {
        x = xx;
        y = yy;
        // Get nearest seed
        var seed = instance_nearest(x,y,oSeed);
        surface_set_target(global.biome_surface);
        // Add sprite to surface
        draw_sprite_ext(sprite_index,0,x,y,1,1,image_angle,seed.biome_color,1);
        surface_reset_target();
    }
}
instance_destroy();
As I understood the in the oMapGeneration the seeds are getting their positions and they are getting their colors which are randomized.
Then in oBiomeCreate it just loops trough every pixel and is looking for the closest seed to that pixel then it draws sets the surface on that pixel to the color of the closes seed
I really do not understand why picks those colors everytime:

redishVoronoiDiagram.PNG
 

Nidoking

Member
What does the sprite you're drawing actually look like? Is it perfectly white? Perfectly black? Some flavor of dark red, perhaps?
 

NightFrost

Member
Not relevant to question, but wouldn't this procedure be a lot faster in a shader? Fragment shader's whole MO is pixel manipulation in parallel operations.
 
"1x1 pixel" is not a color.

A what-colored 1x1 pixel is it? This matters due to the way sprites are blended. In order to cleanly blend with any color you set, the sprite should be white.
I will check again but yes, I think that the sprite is white. sorry, I meant to say it is a white sprite with a width and height of 1
 

NightFrost

Member
any idea how to.do it?
If you know how to write shaders, the answer would be, send the seed data to an array in the shader, and have fragment shader loop them and use distance() to get the closest one and set the pixel to its color. If you don't know, I would have to start from "what is a shader" and you'd be better served instead looking at TheReverend's shaders with GameMaker videos.
 
Top