Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Koroshev Kostya #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Harter–Heighway dragon.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>

<head>
<meta charset=UTF-8">
<title>Harter–Heighway dragon</title>
</head>

<body>
<canvas id="myCanvas" width="1000" height="1000"></canvas>
<script src="Harter–Heighway dragon.js">
</script>
</body>

</html>
23 changes: 23 additions & 0 deletions Harter–Heighway dragon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
window.onload = function() {
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
canvas.width = 1000, canvas.height = 1000;
context.beginPath();
recurs(context, 17, 400, 250, 400, 550, 1); //рекурсивная функция, рисующая фрактальную кривую
context.stroke();
};
var angle = 45 * Math.PI / 180; //переводим углы в радианы
var angle2;

function recurs(context, n, x0, y0, x1, y1, k) { //n итераций, Точки A1(x0,y0) и A2(x1,y1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Задача решена через обычную рекурсию, а требуется решение с помощью IFS

if (n == 0) {
context.moveTo(x0, y0);
context.lineTo(x1, y1);
} else {
angle2 = angle * k;
var xx = Math.cos(angle2) * ((x1 - x0) * Math.cos(angle2) - (y1 - y0) * Math.sin(angle2)) + x0;
var yy = Math.cos(angle2) * ((x1 - x0) * Math.sin(angle2) + (y1 - y0) * Math.cos(angle2)) + y0; //находим точку A3
recurs(context, n - 1, x0, y0, xx, yy, 1); //A1, A3
recurs(context, n - 1, xx, yy, x1, y1, -1); //A3, A2
}
}
Binary file added images/Thumbs.db
Binary file not shown.
110 changes: 0 additions & 110 deletions index.html

This file was deleted.