-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarq.pl
More file actions
99 lines (83 loc) · 1.87 KB
/
marq.pl
File metadata and controls
99 lines (83 loc) · 1.87 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use IO::Socket::INET;
use GD;
#$imagefile = "C:/Users/Awol/Pictures/m2018logo.png";
$imagefile = $ARGV[0];
if (substr($imagefile,-4) eq ".png")
{
$image = GD::Image->newFromPng($imagefile, 1);
$img_type = "PNG";
}
else
{
$image = GD::Image->new($imagefile);
$img_type = "OTHER";
}
$imagedraw = GD::Image->new($image->width,$image->height,1);
#$imagedraw->trueColor(1);
$start_x = $ARGV[1];
$start_y = $ARGV[2];
$random = $ARGV[3];
$direction = $ARGV[4];
# flush after every write
$| = 1;
my ($socket,$data);
# We call IO::Socket::INET->new() to create the UDP Socket
# and bind with the PeerAddr.
$socket = new IO::Socket::INET (
PeerAddr => '10.13.38.175:8080',
Proto => 'tcp'
) or die "ERROR in Socket Creation : $!\n";
#send operation
while(1)
{
if ($direction eq "left")
{
$start_x = $start_x - 2;
$start_x = 1400 if ($start_x <= -200);
}
if ($direction eq "right")
{
$start_x = $start_x + 2;
$start_x = -200 if ($start_x >= 1400);
}
if ($direction eq "down")
{
$start_y = $start_y + 2;
$start_y = -200 if ($start_y >= 1000);
}
if ($direction eq "up")
{
$start_y = $start_y - 2;
$start_y = 1000 if ($start_y <= -200);
}
for($i=0;$i<$image->width;$i++)
{
for($j=0;$j<$image->height;$j++)
{
$new_x = $start_x + $i;
$new_y = $start_y + $j;
$index = $image->getPixel($i,$j);
if ($img_type eq "PNG" && $index >= 1<<24)
{
#The pixel is transparent
next;
}
if ($img_type eq "OTHER" && $index == 206)
{
next;
}
@rgb = $image->rgb($index);
$hex = rgbToHex(@rgb);
$data = $data . "PX $new_x $new_y $hex\n";
}
$socket->send($data);
undef($data);
}
}
$socket->close();
sub rgbToHex {
$red=$_[0];
$green=$_[1];
$blue=$_[2];
return sprintf("%2.2X%2.2X%2.2X",$red,$green,$blue);
}