0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

cscの作法 その23 コッホ曲線

Last updated at Posted at 2020-01-03

概要

cscの作法、調べてみた。
練習問題やってみた。

練習問題

コッホ曲線を表示せよ。

写真

image.png

サンプルコード

using System;
using System.Windows.Forms;
using System.Drawing;

class form1: Form {
	double ANGLE = 0;
	double LX = 20.0;
	double LY = 150.0;
	Graphics g;
	form1() {
		Text = "koch";
		ClientSize = new Size(450, 200);
	}
	protected override void OnPaint(PaintEventArgs e) {
		g = e.Graphics;
		koch(5, 60);
		base.OnPaint(e);
	}
	double fmod(double a, double b) {
		double x = Math.Floor(a / b);
		return a - b * x;
	}
	void turn(double a) {
		ANGLE = fmod(ANGLE + a, 360.0);
	}
	void gmove(double l) {
		Pen pen = new Pen(Color.Red);
		double rd = 3.14159265359 / 180.0;
		double x = l * Math.Cos(rd * ANGLE);
		double y = -l * Math.Sin(rd * ANGLE);
		int px = (int) LX;
		int py = (int) LY;
		LX += x;
		LY += y;
		g.DrawLine(pen, px, py, (int) LX, (int) LY);
	}
	void koch(int i, int j) {
		if (i <= 1)
		{
			gmove(5.0);
			return;
		}
		koch(i - 1, j);
		turn(j);
		koch(i - 1, j);
		turn(-2 * j);
		koch(i - 1, j);
		turn(j);
		koch(i - 1, j);
	}
	[STAThread]
	public static void Main() {
		Application.Run(new form1());
	}
}





以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?