forked from trpo-moais-2016/fg01-snowflake
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Koch Added #1
Open
DarkSanny
wants to merge
11
commits into
trpomoais2018:master
Choose a base branch
from
DarkSanny:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Koch Added #1
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fdc79d6
Koch Added
DarkSanny c7366f2
Refactoring
DarkSanny 922d681
Try Add Slyder
DarkSanny d3407f3
Sliders added
DarkSanny c2be113
Slider's descriptions added
DarkSanny 25a122d
Sliders updated to dynamic
DarkSanny 239bad9
Numbers added
DarkSanny 8dc148b
Убрал скроллинг
Deltvenga f23a61e
Merge pull request #1 from Deltvenga/master
DarkSanny fa9eb3b
Fixed code style
b665ae2
Renaming
DarkSanny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<meta http-equiv="Cache-Control" content="no-cache"/> | ||
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> | ||
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> | ||
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> | ||
<script> | ||
var size = 500; | ||
var count = 5; | ||
|
||
$(document).ready(function () { | ||
$("#sizer").slider( | ||
{ | ||
min: 100, | ||
max: 1000, | ||
value: size, | ||
step: 10, | ||
slide: changeSize, | ||
change: changeSize | ||
}); | ||
$("#counter").slider( | ||
{ | ||
min: 0, | ||
max: 7, | ||
value: count, | ||
step: 1, | ||
slide: changeCount, | ||
change: changeCount | ||
}); | ||
}); | ||
|
||
function changeSize(event, ui){ | ||
size = ui.value; | ||
$("#sizeUpdate").html(size); | ||
main(); | ||
} | ||
|
||
function changeCount(event, ui){ | ||
count = ui.value; | ||
$("#countUpdate").html(count); | ||
main(); | ||
} | ||
|
||
function main() { | ||
setDefaultValues(); | ||
var context = getDefaultCanvasContext(); | ||
var triangleHeight = Math.sqrt(3) * size / 2; | ||
var center = { x: window.innerWidth / 2, y: window.innerHeight / 2 }; | ||
var point1 = { x: center.x + size / 2, y: center.y - triangleHeight / 2 }; | ||
var point2 = { x: center.x - size / 2, y: center.y - triangleHeight / 2 }; | ||
var point3 = { x: center.x, y: center.y + triangleHeight / 2 }; | ||
drawKochSnowflake(context, point1, point2, point3, count); | ||
} | ||
|
||
function drawKochSnowflake(context, point1, point2, point3, count){ | ||
fractal(context, point1, point2, count); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drawFractal |
||
fractal(context, point2, point3, count); | ||
fractal(context, point3, point1, count); | ||
} | ||
|
||
function setDefaultValues(){ | ||
$("#sizeUpdate").html(size); | ||
$("#countUpdate").html(count); | ||
} | ||
|
||
function getDefaultCanvasContext(){ | ||
var canvas = document.getElementById("canvas"); | ||
canvas.setAttribute("Width", window.innerWidth); | ||
canvas.setAttribute("Height", window.innerHeight); | ||
var context = canvas.getContext('2d'); | ||
context.lineWidth = "1"; | ||
context.strokeStyle = "#000000"; | ||
context.clearRect(0, 0, window.innerWidth, window.innerHeight); | ||
return context; | ||
} | ||
|
||
function fractal(context, sPoint, fPoint, count) { | ||
if (count === 0) { | ||
drawLineOn(context, sPoint, fPoint); | ||
return; | ||
} | ||
var firstPoint = { x: sPoint.x + (fPoint.x - sPoint.x) / 3, y: sPoint.y + (fPoint.y - sPoint.y) / 3 }; | ||
var secondPoint = { x: sPoint.x + 2 * (fPoint.x - sPoint.x) / 3, y: sPoint.y + 2 * (fPoint.y - sPoint.y) / 3 } | ||
var middlePoint = findMiddlePoint(firstPoint, secondPoint); | ||
fractal(context, sPoint, firstPoint, count - 1); | ||
fractal(context, firstPoint, middlePoint, count - 1); | ||
fractal(context, middlePoint, secondPoint, count - 1); | ||
fractal(context, secondPoint, fPoint, count - 1); | ||
} | ||
|
||
function findMiddlePoint(sPoint, fPoint){ | ||
var vector = { x: fPoint.x - sPoint.x, y: fPoint.y - sPoint.y }; | ||
var angle = Math.atan2(vector.y, vector.x) + Math.PI / 3; | ||
var length = Math.sqrt(vector.x * vector.x + vector.y * vector.y); | ||
return getCartesianPoint(sPoint, length, angle); | ||
} | ||
|
||
function getCartesianPoint(center, length, angle) { | ||
return { x: center.x + (length * Math.cos(angle)), y: center.y + (length * Math.sin(angle)) }; | ||
} | ||
|
||
function drawLineOn(canvasContext, sPoint, fPoint) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. startPoint |
||
canvasContext.beginPath(); | ||
canvasContext.moveTo(sPoint.x, sPoint.y); | ||
canvasContext.lineTo(fPoint.x, fPoint.y); | ||
canvasContext.stroke(); | ||
} | ||
</script> | ||
</head> | ||
<body onload="main()" style="overflow: hidden"> | ||
Size: <span id="sizeUpdate">0</span> | ||
<div id="sizer"></div> | ||
Count: <span id="countUpdate">0</span> | ||
<div id="counter"></div> | ||
<canvas height='2000' width='2000' id='canvas'></canvas> | ||
</body> | ||
</html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Похоже у тебя смесь табов и пробелов. В итоге отступы разъехались