Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
HiJuwon authored Dec 11, 2023
1 parent 6ad948e commit c2c43ae
Show file tree
Hide file tree
Showing 5 changed files with 558 additions and 0 deletions.
126 changes: 126 additions & 0 deletions js/meta-ball.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Ported from original Metaball script by SATO Hiroyuki
// http://park12.wakwak.com/~shp/lc/et/en_aics_script.html
project.currentStyle = {
fillColor: 'black'
};

var ballPositions = [[464, 202], [1579, 122], [800, 563], [289, 723], [1384, 957]];

var handle_len_rate = 2.4;
var circlePaths = [];
var radius = 40;
for (var i = 0, l = ballPositions.length; i < l; i++) {
var circlePath = new Path.Circle({
center: ballPositions[i],
radius: 140
});
circlePaths.push(circlePath);
}

var connections = new Group();
function generateConnections(paths) {
// Remove the last connection paths:
connections.children = [];

for (var i = 0, l = paths.length; i < l; i++) {
for (var j = i - 1; j >= 0; j--) {
var path = metaball(paths[i], paths[j], 0.5, handle_len_rate, 300);
if (path) {
connections.appendTop(path);
path.removeOnMove();
}
}
}
}

generateConnections(circlePaths);

// ---------------------------------------------
function metaball(ball1, ball2, v, handle_len_rate, maxDistance) {
var center1 = ball1.position;
var center2 = ball2.position;
var radius1 = ball1.bounds.width / 2;
var radius2 = ball2.bounds.width / 2;
var pi2 = Math.PI / 2;
var d = center1.getDistance(center2);
var u1, u2;

if (radius1 == 0 || radius2 == 0)
return;

if (d > maxDistance || d <= Math.abs(radius1 - radius2)) {
return;
} else if (d < radius1 + radius2) { // case circles are overlapping
u1 = Math.acos((radius1 * radius1 + d * d - radius2 * radius2) /
(2 * radius1 * d));
u2 = Math.acos((radius2 * radius2 + d * d - radius1 * radius1) /
(2 * radius2 * d));
} else {
u1 = 0;
u2 = 0;
}

var angle1 = (center2 - center1).getAngleInRadians();
var angle2 = Math.acos((radius1 - radius2) / d);
var angle1a = angle1 + u1 + (angle2 - u1) * v;
var angle1b = angle1 - u1 - (angle2 - u1) * v;
var angle2a = angle1 + Math.PI - u2 - (Math.PI - u2 - angle2) * v;
var angle2b = angle1 - Math.PI + u2 + (Math.PI - u2 - angle2) * v;
var p1a = center1 + getVector(angle1a, radius1);
var p1b = center1 + getVector(angle1b, radius1);
var p2a = center2 + getVector(angle2a, radius2);
var p2b = center2 + getVector(angle2b, radius2);

// define handle length by the distance between
// both ends of the curve to draw
var totalRadius = (radius1 + radius2);
var d2 = Math.min(v * handle_len_rate, (p1a - p2a).length / totalRadius);

// case circles are overlapping:
d2 *= Math.min(1, d / (radius1 + radius2));

radius1 *= d2;
radius2 *= d2;

// 그라데이션 색상 설정
var gradient = new Color({
gradient: {
stops: ['black', 'black', 'black', 'black', 'blue', 'blue', 'blue', 'black', 'black', 'black', 'black']
},
origin: ball1.position,
destination: ball2.position
});

var path = new Path({
segments: [p1a, p2a, p2b, p1b],
closed: true,
fillColor: gradient
});

var segments = path.segments;
segments[0].handleOut = getVector(angle1a - pi2, radius1);
segments[1].handleIn = getVector(angle2a + pi2, radius2);
segments[2].handleOut = getVector(angle2b - pi2, radius2);
segments[3].handleIn = getVector(angle1b + pi2, radius1);
return path;
}

// ------------------------------------------------
function getVector(radians, length) {
return new Point({
// Convert radians to degrees:
angle: radians * 180 / Math.PI,
length: length
});
}

var largeCircle = new Path.Circle({
center: [676, 433],
radius: 150
});
circlePaths.push(largeCircle);

function onMouseMove(event) {
largeCircle.position = event.point;
generateConnections(circlePaths);
}
136 changes: 136 additions & 0 deletions js/meta-ball2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// Ported from original Metaball script by SATO Hiroyuki
// http://park12.wakwak.com/~shp/lc/et/en_aics_script.html
var rect = new Path.Rectangle({
point: [0, 0],
size: [view.size.width, view.size.height],
strokeColor: 'white',
selected: true
});
rect.sendToBack();
rect.fillColor = '#000000';

project.currentStyle = {
fillColor: 'white'
};

var ballPositions = [[217, 101], [97, 394], [700, 214], [760, 1006], [1180, 34], [508, 616], [146, 946], [1060, 756], [1700, 394], [1540, 816], [1060, 420]];

var handle_len_rate = 2.4;
var circlePaths = [];
var radius = 40;
for (var i = 0, l = ballPositions.length; i < l; i++) {
var circlePath = new Path.Circle({
center: ballPositions[i],
radius: 80
});
circlePaths.push(circlePath);
}

var connections = new Group();
function generateConnections(paths) {
// Remove the last connection paths:
connections.children = [];

for (var i = 0, l = paths.length; i < l; i++) {
for (var j = i - 1; j >= 0; j--) {
var path = metaball(paths[i], paths[j], 0.5, handle_len_rate, 500);
if (path) {
connections.appendTop(path);
path.removeOnMove();
}
}
}
}

generateConnections(circlePaths);

// ---------------------------------------------
function metaball(ball1, ball2, v, handle_len_rate, maxDistance) {
var center1 = ball1.position;
var center2 = ball2.position;
var radius1 = ball1.bounds.width / 2;
var radius2 = ball2.bounds.width / 2;
var pi2 = Math.PI / 2;
var d = center1.getDistance(center2);
var u1, u2;

if (radius1 == 0 || radius2 == 0)
return;

if (d > maxDistance || d <= Math.abs(radius1 - radius2)) {
return;
} else if (d < radius1 + radius2) { // case circles are overlapping
u1 = Math.acos((radius1 * radius1 + d * d - radius2 * radius2) /
(2 * radius1 * d));
u2 = Math.acos((radius2 * radius2 + d * d - radius1 * radius1) /
(2 * radius2 * d));
} else {
u1 = 0;
u2 = 0;
}

var angle1 = (center2 - center1).getAngleInRadians();
var angle2 = Math.acos((radius1 - radius2) / d);
var angle1a = angle1 + u1 + (angle2 - u1) * v;
var angle1b = angle1 - u1 - (angle2 - u1) * v;
var angle2a = angle1 + Math.PI - u2 - (Math.PI - u2 - angle2) * v;
var angle2b = angle1 - Math.PI + u2 + (Math.PI - u2 - angle2) * v;
var p1a = center1 + getVector(angle1a, radius1);
var p1b = center1 + getVector(angle1b, radius1);
var p2a = center2 + getVector(angle2a, radius2);
var p2b = center2 + getVector(angle2b, radius2);

// define handle length by the distance between
// both ends of the curve to draw
var totalRadius = (radius1 + radius2);
var d2 = Math.min(v * handle_len_rate, (p1a - p2a).length / totalRadius);

// case circles are overlapping:
d2 *= Math.min(1, d / (radius1 + radius2));

radius1 *= d2;
radius2 *= d2;

// 그라데이션 색상 설정
var gradient = new Color({
gradient: {
stops: ['white', 'white', 'white', 'white', 'red', 'red', 'red', 'white', 'white', 'white', 'white']
},
origin: ball1.position,
destination: ball2.position
});

var path = new Path({
segments: [p1a, p2a, p2b, p1b],
closed: true,
fillColor: gradient
});

var segments = path.segments;
segments[0].handleOut = getVector(angle1a - pi2, radius1);
segments[1].handleIn = getVector(angle2a + pi2, radius2);
segments[2].handleOut = getVector(angle2b - pi2, radius2);
segments[3].handleIn = getVector(angle1b + pi2, radius1);
return path;
}

// ------------------------------------------------
function getVector(radians, length) {
return new Point({
// Convert radians to degrees:
angle: radians * 180 / Math.PI,
length: length
});
}

var largeCircle = new Path.Circle({
center: [676, 433],
radius: 190,
fillColor: 'red'
});
circlePaths.push(largeCircle);

function onMouseMove(event) {
largeCircle.position = event.point;
generateConnections(circlePaths);
}
127 changes: 127 additions & 0 deletions js/meta-ball3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// Ported from original Metaball script by SATO Hiroyuki
// http://park12.wakwak.com/~shp/lc/et/en_aics_script.html
project.currentStyle = {
fillColor: 'black'
};

var ballPositions = [[161, 126], [384, -9], [-30, 330], [474, 202], [311, 360], [101, 525], [311, 694], [101, 923], [444, 963], [534, 713], [649, 540], [696, 221], [841, 51], [811, 825], [1021, 953], [1129, 713], [1021, 450], [1159, 172], [1311, 390],[1341, 0], [1465, 202], [1657, 281], [1773, 126], [1525, 495], [1755, 480], [1422, 694], [1627, 754], [1341, 963], [1743, 993]];

var handle_len_rate = 2.4;
var circlePaths = [];
var radius = 40;
for (var i = 0, l = ballPositions.length; i < l; i++) {
var circlePath = new Path.Circle({
center: ballPositions[i],
radius: 50
});
circlePaths.push(circlePath);
}

var connections = new Group();
function generateConnections(paths) {
// Remove the last connection paths:
connections.children = [];

for (var i = 0, l = paths.length; i < l; i++) {
for (var j = i - 1; j >= 0; j--) {
var path = metaball(paths[i], paths[j], 0.5, handle_len_rate, 300);
if (path) {
connections.appendTop(path);
path.removeOnMove();
}
}
}
}

generateConnections(circlePaths);

// ---------------------------------------------
function metaball(ball1, ball2, v, handle_len_rate, maxDistance) {
var center1 = ball1.position;
var center2 = ball2.position;
var radius1 = ball1.bounds.width / 2;
var radius2 = ball2.bounds.width / 2;
var pi2 = Math.PI / 2;
var d = center1.getDistance(center2);
var u1, u2;

if (radius1 == 0 || radius2 == 0)
return;

if (d > maxDistance || d <= Math.abs(radius1 - radius2)) {
return;
} else if (d < radius1 + radius2) { // case circles are overlapping
u1 = Math.acos((radius1 * radius1 + d * d - radius2 * radius2) /
(2 * radius1 * d));
u2 = Math.acos((radius2 * radius2 + d * d - radius1 * radius1) /
(2 * radius2 * d));
} else {
u1 = 0;
u2 = 0;
}

var angle1 = (center2 - center1).getAngleInRadians();
var angle2 = Math.acos((radius1 - radius2) / d);
var angle1a = angle1 + u1 + (angle2 - u1) * v;
var angle1b = angle1 - u1 - (angle2 - u1) * v;
var angle2a = angle1 + Math.PI - u2 - (Math.PI - u2 - angle2) * v;
var angle2b = angle1 - Math.PI + u2 + (Math.PI - u2 - angle2) * v;
var p1a = center1 + getVector(angle1a, radius1);
var p1b = center1 + getVector(angle1b, radius1);
var p2a = center2 + getVector(angle2a, radius2);
var p2b = center2 + getVector(angle2b, radius2);

// define handle length by the distance between
// both ends of the curve to draw
var totalRadius = (radius1 + radius2);
var d2 = Math.min(v * handle_len_rate, (p1a - p2a).length / totalRadius);

// case circles are overlapping:
d2 *= Math.min(1, d / (radius1 + radius2));

radius1 *= d2;
radius2 *= d2;

// 그라데이션 색상 설정
var gradient = new Color({
gradient: {
stops: ['black', 'black', 'black', 'black', 'blue', 'blue', 'blue', 'black', 'black', 'black', 'black']
},
origin: ball1.position,
destination: ball2.position
});

var path = new Path({
segments: [p1a, p2a, p2b, p1b],
closed: true,
fillColor: gradient
});

var segments = path.segments;
segments[0].handleOut = getVector(angle1a - pi2, radius1);
segments[1].handleIn = getVector(angle2a + pi2, radius2);
segments[2].handleOut = getVector(angle2b - pi2, radius2);
segments[3].handleIn = getVector(angle1b + pi2, radius1);
return path;
}

// ------------------------------------------------
function getVector(radians, length) {
return new Point({
// Convert radians to degrees:
angle: radians * 180 / Math.PI,
length: length
});
}

var largeCircle = new Path.Circle({
center: [676, 433],
radius: 120,
fillColor: 'blue'
});
circlePaths.push(largeCircle);

function onMouseMove(event) {
largeCircle.position = event.point;
generateConnections(circlePaths);
}
Loading

0 comments on commit c2c43ae

Please sign in to comment.