Compare commits
2 Commits
4bd2a92a0e
...
sem2-lab2-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
757d60e2d3 | ||
|
|
ed21fb4694 |
@@ -34,7 +34,7 @@ html(lang="ru")
|
|||||||
option(value="1") По кругу
|
option(value="1") По кругу
|
||||||
option(value="2") Спиралью
|
option(value="2") Спиралью
|
||||||
|
|
||||||
p.path-anim-related-inverse
|
p
|
||||||
| Масштаб
|
| Масштаб
|
||||||
br
|
br
|
||||||
label(for="sx") по x:
|
label(for="sx") по x:
|
||||||
@@ -47,7 +47,7 @@ html(lang="ru")
|
|||||||
label.anim-related(for="sy_finish") до:
|
label.anim-related(for="sy_finish") до:
|
||||||
input#sy_finish.anim-related(type="number", value="1.5", max="100", min="-100")
|
input#sy_finish.anim-related(type="number", value="1.5", max="100", min="-100")
|
||||||
|
|
||||||
p.path-anim-related-inverse
|
p
|
||||||
| Поворот
|
| Поворот
|
||||||
br
|
br
|
||||||
label(for="r") x:
|
label(for="r") x:
|
||||||
@@ -55,6 +55,12 @@ html(lang="ru")
|
|||||||
label.anim-related(for="r_finish") до:
|
label.anim-related(for="r_finish") до:
|
||||||
input#r_finish.anim-related(type="number", value="360", max="360", min="-360")
|
input#r_finish.anim-related(type="number", value="360", max="360", min="-360")
|
||||||
|
|
||||||
|
p.anim-related
|
||||||
|
| Время анамации (мс)
|
||||||
|
br
|
||||||
|
label(for="duration") x:
|
||||||
|
input#duration(type="number", value="2000", max="10000", min="1")
|
||||||
|
|
||||||
p
|
p
|
||||||
input#applyButton.anim-related-inverse(type="button", value="Нарисовать")
|
input#applyButton.anim-related-inverse(type="button", value="Нарисовать")
|
||||||
input#clearButton(type="button", value="Отчистить")
|
input#clearButton(type="button", value="Отчистить")
|
||||||
|
|||||||
@@ -3,31 +3,31 @@
|
|||||||
function drawSmile(svg) {
|
function drawSmile(svg) {
|
||||||
let smile = svg.append("g")
|
let smile = svg.append("g")
|
||||||
.style("stroke", "brown")
|
.style("stroke", "brown")
|
||||||
.style("stroke-width", 2)
|
.style("stroke-width", 0)
|
||||||
.style("fill", "brown");
|
.style("fill", "brown");
|
||||||
//лицо
|
|
||||||
smile.append("circle")
|
|
||||||
.attr("cx", 0)
|
|
||||||
.attr("cy", 0)
|
|
||||||
.attr("r", 50)
|
|
||||||
.style("fill", "yellow");
|
|
||||||
//левый глаз
|
|
||||||
smile.append("circle")
|
|
||||||
.attr("cx", -20)
|
|
||||||
.attr("cy", -10)
|
|
||||||
.attr("r", 5);
|
|
||||||
//правый глаз
|
|
||||||
smile.append("circle")
|
|
||||||
.attr("cx", 20)
|
|
||||||
.attr("cy", -10)
|
|
||||||
.attr("r", 5);
|
|
||||||
// улыбка
|
|
||||||
let arc = d3.arc()
|
|
||||||
.innerRadius(35)
|
|
||||||
.outerRadius(35);
|
|
||||||
smile.append("path")
|
|
||||||
.attr("d", arc({startAngle: Math.PI /3 * 2, endAngle: Math.PI/3 * 4}))
|
|
||||||
.style("stroke", "brown")
|
|
||||||
|
|
||||||
|
for (let t = 0; t <= Math.PI * 6; t += .8) {
|
||||||
|
let cords = {
|
||||||
|
x: 50 / 3 * (1 - (t / (Math.PI * 6))) * -Math.sin(t),
|
||||||
|
y: 50 / 3 * (1 - (t / (Math.PI * 6))) * Math.cos(t)
|
||||||
|
}
|
||||||
|
smile.append("circle")
|
||||||
|
.attr("cx", cords["x"])
|
||||||
|
.attr("cy", cords["y"])
|
||||||
|
.attr("r", (1 - (t / (Math.PI * 6))))
|
||||||
|
.style("fill", "red");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let t = .4; t <= Math.PI * 6; t += .8) {
|
||||||
|
let cords = {
|
||||||
|
x: 50 / 3 * (1 - (t / (Math.PI * 6))) * -Math.sin(t),
|
||||||
|
y: 50 / 3 * (1 - (t / (Math.PI * 6))) *Math.cos(t)
|
||||||
|
}
|
||||||
|
smile.append("circle")
|
||||||
|
.attr("cx", cords["x"])
|
||||||
|
.attr("cy", cords["y"])
|
||||||
|
.attr("r", (1 - (t / (Math.PI * 6))))
|
||||||
|
.style("fill", "green");
|
||||||
|
}
|
||||||
return smile
|
return smile
|
||||||
}
|
}
|
||||||
@@ -57,10 +57,15 @@ const animRouter = (dataForm) => {
|
|||||||
let path = drawPath(Number(dataForm.pathSelect.value));
|
let path = drawPath(Number(dataForm.pathSelect.value));
|
||||||
const svg = d3.select("svg")
|
const svg = d3.select("svg")
|
||||||
let pict = drawSmile(svg);
|
let pict = drawSmile(svg);
|
||||||
|
const parameters = {
|
||||||
|
sx:[Number(dataForm.sx.value),Number(dataForm.sx_finish.value)],
|
||||||
|
sy:[Number(dataForm.sy.value),Number(dataForm.sy_finish.value)],
|
||||||
|
r:[Number(dataForm.r.value),Number(dataForm.r_finish.value)],
|
||||||
|
};
|
||||||
pict.transition()
|
pict.transition()
|
||||||
.ease([d3.easeLinear, d3.easeElastic, d3.easeBounce][Number(animTypeSelect.value)])
|
.ease([d3.easeLinear, d3.easeElastic, d3.easeBounce][Number(animTypeSelect.value)])
|
||||||
.duration(6000)
|
.duration(Number(duration.value))
|
||||||
.attrTween('transform', translateAlong(path.node()));
|
.attrTween('transform', translateAlong(path.node(),parameters));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
runAnimation(dataForm)
|
runAnimation(dataForm)
|
||||||
@@ -77,7 +82,7 @@ const runAnimation = (dataForm) => {
|
|||||||
${dataForm.sy.value})
|
${dataForm.sy.value})
|
||||||
rotate(${dataForm.r.value})`)
|
rotate(${dataForm.r.value})`)
|
||||||
.transition()
|
.transition()
|
||||||
.duration(6000)
|
.duration(Number(duration.value))
|
||||||
.ease([d3.easeLinear, d3.easeElastic, d3.easeBounce][Number(animTypeSelect.value)])
|
.ease([d3.easeLinear, d3.easeElastic, d3.easeBounce][Number(animTypeSelect.value)])
|
||||||
.attr("transform", `
|
.attr("transform", `
|
||||||
translate(${dataForm.cx_finish.value},
|
translate(${dataForm.cx_finish.value},
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ function createPathG() {
|
|||||||
const h = 5;
|
const h = 5;
|
||||||
// координаты y - уменьшаются, x - постоянны
|
// координаты y - уменьшаются, x - постоянны
|
||||||
while (posY > padding) {
|
while (posY > padding) {
|
||||||
data.push( {x: posX, y: posY});
|
data.push({ x: posX, y: posY });
|
||||||
posY -= h;
|
posY -= h;
|
||||||
}
|
}
|
||||||
// координаты y - постоянны, x - увеличиваются
|
// координаты y - постоянны, x - увеличиваются
|
||||||
while (posX < width - padding) {
|
while (posX < width - padding) {
|
||||||
data.push( {x: posX, y: posY});
|
data.push({ x: posX, y: posY });
|
||||||
posX += h;
|
posX += h;
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
@@ -38,10 +38,12 @@ function createPathCircle() {
|
|||||||
let data = [];
|
let data = [];
|
||||||
// используем параметрическую форму описания круга
|
// используем параметрическую форму описания круга
|
||||||
// центр расположен в центре svg-элемента, а радиус равен трети высоты/ширины
|
// центр расположен в центре svg-элемента, а радиус равен трети высоты/ширины
|
||||||
for (let t = 0 ; t <= Math.PI * 2; t += 0.1) {
|
for (let t = 0; t <= Math.PI * 2; t += 0.1) {
|
||||||
data.push(
|
data.push(
|
||||||
{x: width / 2 + width / 3 * Math.sin(t),
|
{
|
||||||
y: height / 2 + height / 3* Math.cos(t)}
|
x: width / 2 + width / 3 * Math.sin(t),
|
||||||
|
y: height / 2 + height / 3 * Math.cos(t)
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
@@ -53,17 +55,19 @@ function createPathSpiral() {
|
|||||||
let data = [];
|
let data = [];
|
||||||
// используем параметрическую форму описания круга
|
// используем параметрическую форму описания круга
|
||||||
// центр расположен в центре svg-элемента, а радиус равен трети высоты/ширины
|
// центр расположен в центре svg-элемента, а радиус равен трети высоты/ширины
|
||||||
for (let t = 0 ; t <= Math.PI * 6; t += 0.1) {
|
for (let t = 0; t <= Math.PI * 6; t += 0.1) {
|
||||||
data.push(
|
data.push(
|
||||||
{x: width / 2 + width / 3 *(1-(t/(Math.PI * 6))) * -Math.sin(t),
|
{
|
||||||
y: height / 2 + height / 3*(1-(t/(Math.PI * 6))) * Math.cos(t)}
|
x: width / 2 + width / 3 * (1 - (t / (Math.PI * 6))) * -Math.sin(t),
|
||||||
|
y: height / 2 + height / 3 * (1 - (t / (Math.PI * 6))) * Math.cos(t)
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
const drawPath =(typePath) => {
|
const drawPath = (typePath) => {
|
||||||
// создаем массив точек
|
// создаем массив точек
|
||||||
const dataPoints = [ createPathG, createPathCircle,createPathSpiral][Number(typePath)]()
|
const dataPoints = [createPathG, createPathCircle, createPathSpiral][Number(typePath)]()
|
||||||
|
|
||||||
const line = d3.line()
|
const line = d3.line()
|
||||||
.x((d) => d.x)
|
.x((d) => d.x)
|
||||||
@@ -78,12 +82,18 @@ const drawPath =(typePath) => {
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
function translateAlong(path) {
|
function translateAlong(path, params) {
|
||||||
const length = path.getTotalLength();
|
const length = path.getTotalLength();
|
||||||
return function() {
|
|
||||||
return function(t) {
|
return function () {
|
||||||
const {x, y} = path.getPointAtLength(t * length);
|
return function (t) {
|
||||||
return `translate(${x},${y})`;
|
const { x, y } = path.getPointAtLength(t * length);
|
||||||
|
return `
|
||||||
|
translate(${x},${y})
|
||||||
|
scale(${params.sx[0] +(params.sx[1] - params.sx[0])*t},
|
||||||
|
${params.sy[0] +(params.sy[1] - params.sy[0])*t})
|
||||||
|
rotate(${params.r[0] +(params.r[1] - params.r[0])*t})
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user