MetaBalls - эксперименты

Эксперименты.

Добавляем в проект градиентный спрайт:

 Создаём объект контроллер:

Содержимое события Create:

balls = [];

surf = surface_create(room_width, room_height);

for(var i=0; i<=20;i++)
{
	balls[i] = new Ball( random_range(0,room_width),random_range(0,room_height) );
}

Содержимое события Step:

for(var i=0; i<array_length(balls);i++)
{	
	balls[i].update_coord();	
}

 Содержимое события Draw:

surface_set_target(surf)
draw_clear_alpha(c_black,0);
gpu_set_blendmode(bm_add);
for(var i=0; i<array_length(balls);i++)
{
	balls[i].drawself();
}
gpu_set_blendmode(bm_normal);
surface_reset_target();

gpu_set_alphatestenable(true);
gpu_set_alphatestref(210);
draw_surface(surf,0,0)
gpu_set_alphatestenable(false);

 

Объект контроллер использует базовый класс Ball:

/// @description 
//Site:   MidaDev.ru
//Author: Dimusikus

function Ball(_x,_y) constructor
{
	static xmin = 0;
	static ymin = 0;
	static xmax = room_width;
	static ymax = room_height;
	
	//инициализация переменных
	xpos = _x;
	ypos = _y;
	
	//рандомная позиция шара
	xspeed =  random_range(0.5,1) * choose(1,-1);
	yspeed =  random_range(0.5,1) * choose(1,-1);
	
	//обновление позиции шара каждый шаг
	static update_coord = function()
	{
		xpos+=xspeed;
		if xpos>xmax then{ xspeed = -xspeed;	xpos=xmax;};
		if xpos<xmin then{ xspeed = -xspeed;	xpos=xmin;};
		
		ypos+=yspeed;
		if ypos>ymax then{ yspeed = -yspeed;	ypos=xmax;};
		if ypos<ymin then{ yspeed = -yspeed;	ypos=xmin;};
	};
	
	//рисование
	static drawself = function(){draw_sprite(spr_sphere1,0, xpos, ypos);};
}

На выходе получаем:

Ничего сложного.


Поэкспериментировав с переменными можно получить различные эффекты: