visual c#のウィンドウプログラミングの質問なんですが
Posted: 2011年1月24日(月) 01:06
初投稿失礼します。
大学講義のアシスタントとして参加することとなったんですが、現在下級生はこの先大学で学ぶことないC#の練習を
受け持ち教授の趣味でやってます。趣味なので、当然私を含めた上級生全員習ってません。
講義本番に向け皆で集まりいろいろと頑張ったんですが、私たちにはどうしても解けない問題が1つ残ってしまいました。
以下のプログラムのMyCircleを中心に改造して同じ感じで三角形が表示できるように
したいんですが、まったく歯が立ちませんでした。
同じサークルの子に「頼りにしてます」などと言われかなり切羽つまってます。
どなたか助けてください。
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
MyCircle mc = new MyCircle();
mc.AddCircles(100, 100, 100, 7);
mc.Draw(e.Graphics);
}
}
class MyCircle
{
Random _rnd;
MyCircle[] _Child;
SolidBrush _opaqueBrush;
int _radius;
double _x;
double _y;
public MyCircle()
{
_rnd = new Random();
}
public void AddCircles( double x, double y, int radius, int num)
{
_x = x;
_y = y;
_radius = radius;
int value = 126 * num / 6;
_opaqueBrush = new SolidBrush(Color.FromArgb(value, 0, 0, 153));
if (num > 1)
{
int branches = _rnd.Next(2, 6);
_Child = new MyCircle[branches];
for (int j = 0; j < branches; j++)
{
double a = _rnd.NextDouble() * 2.0 * Math.PI;
double newx = x + Math.Cos(a) * 6.0 * (num - 1);
double newy = y + Math.Sin(a) * 6.0 * (num - 1);
_Child[j] = new MyCircle();
_Child[j].AddCircles(newx, newy, radius / 2, (num - 1));
}
}
}
public void Draw(Graphics g)
{
g.FillEllipse(_opaqueBrush, (int)_x, (int)_y, _radius * 2, _radius * 2);
if (_Child != null)
{
foreach (MyCircle mc in _Child)
{
mc.Draw(g);
}
}
}
}
}
大学講義のアシスタントとして参加することとなったんですが、現在下級生はこの先大学で学ぶことないC#の練習を
受け持ち教授の趣味でやってます。趣味なので、当然私を含めた上級生全員習ってません。
講義本番に向け皆で集まりいろいろと頑張ったんですが、私たちにはどうしても解けない問題が1つ残ってしまいました。
以下のプログラムのMyCircleを中心に改造して同じ感じで三角形が表示できるように
したいんですが、まったく歯が立ちませんでした。
同じサークルの子に「頼りにしてます」などと言われかなり切羽つまってます。
どなたか助けてください。
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
MyCircle mc = new MyCircle();
mc.AddCircles(100, 100, 100, 7);
mc.Draw(e.Graphics);
}
}
class MyCircle
{
Random _rnd;
MyCircle[] _Child;
SolidBrush _opaqueBrush;
int _radius;
double _x;
double _y;
public MyCircle()
{
_rnd = new Random();
}
public void AddCircles( double x, double y, int radius, int num)
{
_x = x;
_y = y;
_radius = radius;
int value = 126 * num / 6;
_opaqueBrush = new SolidBrush(Color.FromArgb(value, 0, 0, 153));
if (num > 1)
{
int branches = _rnd.Next(2, 6);
_Child = new MyCircle[branches];
for (int j = 0; j < branches; j++)
{
double a = _rnd.NextDouble() * 2.0 * Math.PI;
double newx = x + Math.Cos(a) * 6.0 * (num - 1);
double newy = y + Math.Sin(a) * 6.0 * (num - 1);
_Child[j] = new MyCircle();
_Child[j].AddCircles(newx, newy, radius / 2, (num - 1));
}
}
}
public void Draw(Graphics g)
{
g.FillEllipse(_opaqueBrush, (int)_x, (int)_y, _radius * 2, _radius * 2);
if (_Child != null)
{
foreach (MyCircle mc in _Child)
{
mc.Draw(g);
}
}
}
}
}