Add project files.

This commit is contained in:
Persephone Bubblegum-Holiday 2025-02-11 12:32:22 -07:00
parent 3dbd19281e
commit 2b6f1aad8f
11 changed files with 743 additions and 0 deletions

99
networkPaint/MainForm.cs Normal file
View file

@ -0,0 +1,99 @@
using System;
using System.Collections.Specialized;
using System.Drawing;
using System.Net;
using System.Windows.Forms;
namespace networkPaint
{
public partial class MainForm : Form
{
Color color;
Random r = new Random();
WebClient client = new WebClient();
Bitmap bitmap;
Graphics graphics;
string url = "http://kawaiizenbo.me/toys/networkpaint/";
public MainForm()
{
InitializeComponent();
color = intToRGB(r.Next(0, 0xFFFFFF));
bitmap = new Bitmap(640, 480);
paintArea.Image = bitmap;
graphics = Graphics.FromImage(bitmap);
}
private void paintArea_Click(object sender, EventArgs e)
{
MouseEventArgs em = (MouseEventArgs)e;
NameValueCollection values = new NameValueCollection();
values["color"] = rgbToInt(color).ToString();
values["x"] = em.X.ToString();
values["y"] = em.Y.ToString();
values["size"] = brushSizeNumericUpDown.Value.ToString();
client.UploadValues(url + "post.php", values);
}
private void MainForm_Load(object sender, EventArgs e)
{
timer.Start();
}
private void timer_Tick(object sender, EventArgs e)
{
string responseString = client.DownloadString(url + "data.ppf");
client.Dispose();
if (responseString.Trim() == "") return;
foreach (string packet in responseString.Split(';'))
{
try
{
if (packet.Trim() == "") continue;
int color = int.Parse(packet.Split(',')[0]);
int x = int.Parse(packet.Split(',')[1]);
int y = int.Parse(packet.Split(',')[2]);
int size = int.Parse(packet.Split(',')[3]);
graphics.FillEllipse(new SolidBrush(intToRGB(color)), new Rectangle(x - size / 2, y - size / 2, size, size));
}
catch (Exception)
{
continue;
}
}
paintArea.Image = bitmap;
}
public static int rgbToInt(Color color)
{
return ((255 & 0x0ff) << 24) | ((color.R & 0x0ff) << 16) | ((color.G & 0x0ff) << 8) | (color.B & 0x0ff);
}
public static Color intToRGB(int color)
{
return Color.FromArgb(0xFF, (color & 0x00FF0000) >> 16, (color & 0x0000FF00) >> 8, color & 0x000000FF);
}
private void changeColorButton_Click(object sender, EventArgs e)
{
colorDialog.ShowDialog();
color = colorDialog.Color;
}
private void setUrlButton_Click(object sender, EventArgs e)
{
try
{
if (client.DownloadString(urlTextBox.Text + "/valid.txt").Trim() != "networkPaint") throw new Exception();
}
catch (Exception)
{
MessageBox.Show("This is not a valid networkPaint endpoint.");
urlTextBox.Text = url;
return;
}
string tempURL = urlTextBox.Text;
if (!tempURL.EndsWith("")) tempURL += "/";
url = tempURL;
}
}
}