Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
66
Task/Yin-and-yang/JavaScript/yin-and-yang-2.js
Normal file
66
Task/Yin-and-yang/JavaScript/yin-and-yang-2.js
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
YinYang = (function () {
|
||||
var scale_x = 2,
|
||||
scale_y = 1,
|
||||
black = "#",
|
||||
white = ".",
|
||||
clear = " ",
|
||||
out = "";
|
||||
|
||||
function draw(radius) {
|
||||
function inCircle(centre_x, centre_y, radius, x, y) {
|
||||
return Math.pow(x - centre_x, 2) + Math.pow(y - centre_y, 2) <= Math.pow(radius, 2)
|
||||
}
|
||||
var bigCircle = function (x, y) {
|
||||
return inCircle(0, 0, radius, x, y)
|
||||
}, whiteSemiCircle = function (x, y) {
|
||||
return inCircle(0, radius / 2, radius / 2, x, y)
|
||||
}, smallBlackCircle = function (x, y) {
|
||||
return inCircle(0, radius / 2, radius / 6, x, y)
|
||||
}, blackSemiCircle = function (x, y) {
|
||||
return inCircle(0, -radius / 2, radius / 2, x, y)
|
||||
}, smallWhiteCircle = function (x, y) {
|
||||
return inCircle(0, -radius / 2, radius / 6, x, y)
|
||||
};
|
||||
i = 0
|
||||
for (var sy = Math.round(radius * scale_y); sy >= -Math.round(radius * scale_y); sy--) {
|
||||
//console.log(sy)
|
||||
for (var sx = -Math.round(radius * scale_x); sx <= Math.round(radius * scale_x); sx++) {
|
||||
|
||||
var x = sx / scale_x,
|
||||
y = sy / scale_y;
|
||||
//out+=sx
|
||||
//console.log(sx,bigCircle(x,y))
|
||||
if (bigCircle(x, y)) {
|
||||
//out+="";
|
||||
if (whiteSemiCircle(x, y)) {
|
||||
//console.log(x,y)
|
||||
if (smallBlackCircle(x, y)) {
|
||||
out += black
|
||||
} else {
|
||||
out += white
|
||||
}
|
||||
} else if (blackSemiCircle(x, y)) {
|
||||
if (smallWhiteCircle(x, y)) {
|
||||
out += white
|
||||
} else {
|
||||
out += black
|
||||
}
|
||||
} else if (x < 0) {
|
||||
out += white
|
||||
} else {
|
||||
out += black
|
||||
}
|
||||
|
||||
} else {
|
||||
out += clear;
|
||||
}
|
||||
|
||||
}
|
||||
out += "\n";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
return draw
|
||||
})()
|
||||
console.log(YinYang(17))
|
||||
console.log(YinYang(8))
|
||||
Loading…
Add table
Add a link
Reference in a new issue