aboutsummaryrefslogtreecommitdiff
path: root/Plugins/shuffle.c
blob: 060459552d3d631493d10f62f2beb7af7fea1e6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <string.h>
#include "plugin.h"

void perform_effect(_frame f, _args a)
{
	int i, o=1000, x1, y1, x2, y2, range=10;
	char *t;
	pixel8 *p1, *p2;
	pixel32 dot;
	byte pixelsize=f.pixelformat/8;

	if(f.pixelformat>32) return;

	if(a.s)
	{
		o = atoi(a.s);
		if(o==0) o=1000;

		if(t = strstr(a.s, " "))
		if((range = atoi(t+1))==0) return;
	}

	for(i=0; i<o; i++)
	{
		x1 = rand()%f.width;
		y1 = rand()%f.height;
		x2 = x1 + (rand()%(range*2) - range);
		y2 = y1 + (rand()%(range*2) - range);

		if(x2<0) x2=0;
		if(x2>=f.width) x2=f.width-1;
		if(y2<0) y2=0;
		if(y2>=f.height) y2=f.height-1;

		p1 = scanline(f, y1);
		p2 = scanline(f, y2);

		memcpy(&dot, &p2[x2*pixelsize], pixelsize);
		memcpy(&p2[x2*pixelsize], &p1[x1*pixelsize], pixelsize);
		memcpy(&p1[x1*pixelsize], &dot, pixelsize);
	}
}