using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
class PictToCircle
{
Random rnd = new Random();
Bitmap b1 = null;
Bitmap b2 = null;
int h;//高さ
int w;//横幅
int max;//横と高さのうちで大きいほう
public PictToCircle(Bitmap bmp1)
{
this.b1 = bmp1;
this.h = bmp1.Height;
this.w = bmp1.Width;
this.max = Math.Max(this.h, this.w);
this.b2 = new Bitmap(b1.Width, b1.Height);
for (int i = 0; i < w; i++)
{
for (int j = 0; j < h; j++)
{
b2.SetPixel(i, j, Color.White);
}
}
}
public void changeCircle()
{
int nowSize = (int)Math.Floor(max / 3.0);
int tUp = 0;
int incK = 1;
while (nowSize > 1)
{
nowSize = (int)(nowSize / 1.717);
for (int i = 0; i < b1.Width / nowSize; i++)
{
for (int j = 0; j < b1.Height / nowSize; j++)
{
if (nowSize > 5)
{
tUp = 8;
}
else
{
tUp = 2;
incK = 2;
}
for (int k = 0; k < tUp; k+=incK)
{
CellToCircle(rnd.Next(4 * nowSize) - 2 * nowSize + i * nowSize, rnd.Next(4 * nowSize) - 2 * nowSize + j * nowSize, nowSize);
}
}
}
}
}
public void CellToCircle(int x, int y, int size)
{
if (rnd.Next(100) > 95)
{
size += rnd.Next(2);
}
int sx = cutNum(0, this.b1.Width - 1, x - size);
int sy = cutNum(0, this.b1.Height - 1, y - size);
int ex = cutNum(1, this.b1.Width, x + size);
int ey = cutNum(1, this.b1.Height, y + size);
int checkR = 1600;
if (size > 4)
{
checkR = 2500;
}
else
{
checkR = 4900;
}
float aveR = 0;
float aveG = 0;
float aveB = 0;
Color c1;
int th = (int)Math.Floor((Math.Sqrt(size * 3)));
int tw = th;
int t1 = ((ex - sx) / tw + 1) * ((ey - sy) / tw + 1);
for (int i = sx; i < ex; i += tw)
{
for (int j = sy; j < ey; j += th)
{
//各色の平均をとる
c1 = b1.GetPixel(i, j);
aveR += c1.R;
aveG += c1.G;
aveB += c1.B;
}
}