Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
MAC_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
오윤석
2021-05-01 05:10:33 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
48976748ddde840525c3635504f887216d968327
48976748
1 parent
2555eaf5
gif render
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
27 deletions
gif-generator/src/index.js
gif-generator/src/index.js
View file @
4897674
...
...
@@ -7,12 +7,16 @@ class GifGenerator {
this
.
canvas
=
canvas
;
this
.
width
=
canvas
.
getWidth
();
this
.
height
=
canvas
.
getHeight
();
this
.
gif
=
new
GIF
(
this
.
width
,
this
.
height
);
this
.
gif
.
start
();
this
.
_initializeGif
();
}
_initializeGif
()
{
this
.
gif
=
new
GIF
(
this
.
width
,
this
.
height
);
this
.
gif
.
setTransparent
(
null
);
this
.
gif
.
setRepeat
(
0
);
this
.
gif
.
setQuality
(
10
);
this
.
gif
.
start
();
}
_addFrame
(
delay
=
0
)
{
...
...
@@ -28,6 +32,8 @@ class GifGenerator {
}
make
()
{
this
.
_initializeGif
();
const
fabricObjs
=
this
.
canvas
.
getObjects
();
const
objs
=
[];
...
...
@@ -41,33 +47,41 @@ class GifGenerator {
}
});
if
(
objs
.
length
>
0
)
{
let
objIdx
=
0
;
let
isAddMode
=
true
;
const
draw
=
()
=>
{
const
obj
=
objs
[
objIdx
];
if
(
isAddMode
)
{
const
fabricObj
=
obj
.
getCurrentFabricObject
();
obj
.
next
();
if
(
obj
.
end
())
{
if
(
objIdx
<
objs
.
length
-
1
)
objIdx
++
;
else
this
.
canvas
.
off
(
"after:render"
,
draw
);
}
else
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
objs
.
length
>
0
)
{
let
objIdx
=
0
;
let
isAddMode
=
true
;
const
draw
=
()
=>
{
const
obj
=
objs
[
objIdx
];
if
(
isAddMode
)
{
const
fabricObj
=
obj
.
getCurrentFabricObject
();
obj
.
next
();
isAddMode
=
false
;
this
.
canvas
.
add
(
fabricObj
);
}
else
{
this
.
_addFrame
(
1
);
isAddMode
=
true
;
if
(
obj
.
end
())
{
if
(
objIdx
<
objs
.
length
-
1
)
{
objIdx
++
;
draw
();
}
else
{
this
.
canvas
.
off
(
"after:render"
,
draw
);
resolve
(
this
.
_render
());
}
}
else
{
this
.
canvas
.
remove
(
this
.
canvas
.
_objects
[
this
.
canvas
.
_objects
.
length
-
1
]
);
}
}
this
.
canvas
.
add
(
fabricObj
);
}
else
{
this
.
canvas
.
remove
(
this
.
canvas
.
_objects
[
this
.
canvas
.
_objects
.
length
-
1
]
);
isAddMode
=
true
;
}
};
this
.
canvas
.
on
(
"after:render"
,
draw
);
draw
();
}
console
.
log
(
objs
);
};
this
.
canvas
.
on
(
"after:render"
,
draw
);
draw
();
}
else
{
reject
(
new
Error
(
"no objects"
));
}
});
}
}
...
...
Please
register
or
login
to post a comment