SlideShare uma empresa Scribd logo
1 de 15
Animation
Codin9 café fifth html5 canvas
HTML5Canvas
leesanghun
Lee sang hun
lsh00124@naver.com
애니메이션이란 무엇일까?
애니메이션은 연속된 장면을 화면에 빠르게 표시해 움직임을 나타낸다
단일화된 렌더링 파이프라인을 이용해 초당 60번 등록된 객체를 그린다
function draw() {
// 지우기
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
// 등록된 객체를 그리기
for (var i = 0; i < list.length; i++) {
list[i].drawEachObject();
}
};
// 초당 60번 반복
setInterval(draw, 1000 / 60);
눈에 보이지는 않지만 화면을 매번 다시 그린다
draw draw draw draw draw
초당 60번 반복한다
시스템의 리소스 낭비를 초래하여, 불필요한 전력을 소모하게 만든다. 또한, 디스플레이 갱신 전에 캔버스를 여러 번 고치
더라도 디스플레이 갱신 바로 직전의 캔버스 상태만 적용이 되기 때문에, 프레임 손실이 발생할 수도 있다.
requestAnimationFrame을 사용하면
좀 더 자연스러운 애니메이션이 된다
function draw() {
requestAnimationFrame(draw);
// ...
}
requestAnimationFrame(draw);
requestAnimationFrame() 함수는 브라우저가 화면을 업데이트 해야하는 경우에만 콜백함수를 호출한다. 이는 브라우저가 최소화되었
다던가, 다른 탭이 선택된 경우에는 콜백함수를 호출하지 않는다는 것을 의미한다. 또한 콜백함수 호출 주기(DOMHighRestTimeStamp
라고 하는데, )는 브라우저에서 관리되기 때문에 fps 값 설정 없이도 최적화된 (부드러운) 애니메이션 구현이 가능하다.
움직이는 동작은 지난 시간에 배웠던 스프라이트를 이용한다
캔버스에서는 drawImage를 이용해
간단하게 구현할 수 있다
원본 x,y,width,height
drawImage
대상 x,y,width,height
var ctx = elCanvas.getContext("2d");
ctx.drawImage(대상이미지, 원본x, 원본y, 원본너비, 원본높이,
대상x, 대상y, 대상너비, 대상높이);
좀 더 나아가 보자
마시마로처럼 몇 백 번을 볼지라도 같은 그림이 같은 위치에 같은 시간에 나타난다.
이런 것을 정적 애니메이션이라고 한다.
동적 애니메이션이란?
Draw = function () {
context.fillStyle = this.color;
context.beginPath();
context.arc(this.x, this.y, 5, 0, Math.PI * 2, true);
context.fill();
}
Move = function () {
this.x = this.x+this.vX;
this.y = this.y+this.vY;
}
Bounce = function () {
var X = this.x + this.vX;
var Y = this.y + this.vY;
if (X < 0 || X >canvas.width) {
this.vX = -this.vX;
}
if (lY < 0 || Y > canvas.height) {
this.vY = -this.vY;
}
}
동적 애니메이션이란 그때 그때 결과가 다른 애니메이션을 의미하고, 사
용자와 반응하는 애니메이션이다. 간단하게 말하면 게임이 될 수 있다.
이미지를 넣고, 그림을 그리고, 색깔을 입히는 등 간단한 그림판 제작하기
Creating a drawing app with HTML5 Canvas and Javascript

Mais conteúdo relacionado

Mais procurados

문디 14주차 발제 scatter plot
문디 14주차 발제 scatter plot문디 14주차 발제 scatter plot
문디 14주차 발제 scatter plot
Min Jeong Cho
 
글꼴 렌더링 이야기
글꼴 렌더링 이야기글꼴 렌더링 이야기
글꼴 렌더링 이야기
Young-jun Jeong
 
[1106 조진현] if you( batch rendering )
[1106 조진현] if you( batch rendering )[1106 조진현] if you( batch rendering )
[1106 조진현] if you( batch rendering )
진현 조
 
Shaderstudy Motion Blur
Shaderstudy Motion BlurShaderstudy Motion Blur
Shaderstudy Motion Blur
yong gyun im
 
[NDC14] 라이브중인 2D게임에 시스템 변경 없이 본 애니메이션 도입하기[던전앤파이터]
[NDC14] 라이브중인 2D게임에 시스템 변경 없이 본 애니메이션 도입하기[던전앤파이터][NDC14] 라이브중인 2D게임에 시스템 변경 없이 본 애니메이션 도입하기[던전앤파이터]
[NDC14] 라이브중인 2D게임에 시스템 변경 없이 본 애니메이션 도입하기[던전앤파이터]
SeungWon Lee
 
CSS3 text-shadow
CSS3 text-shadowCSS3 text-shadow
CSS3 text-shadow
Toby Yun
 

Mais procurados (19)

Picking
PickingPicking
Picking
 
[Week8]R_ggplot2
[Week8]R_ggplot2[Week8]R_ggplot2
[Week8]R_ggplot2
 
[Week15] D3.js_Scatter_Chart
[Week15] D3.js_Scatter_Chart[Week15] D3.js_Scatter_Chart
[Week15] D3.js_Scatter_Chart
 
문디 14주차 발제 scatter plot
문디 14주차 발제 scatter plot문디 14주차 발제 scatter plot
문디 14주차 발제 scatter plot
 
투명화 처리로 살펴 본 한층 고급화된 모바일 UX
투명화 처리로 살펴 본 한층 고급화된 모바일 UX투명화 처리로 살펴 본 한층 고급화된 모바일 UX
투명화 처리로 살펴 본 한층 고급화된 모바일 UX
 
Api더블버퍼링
Api더블버퍼링Api더블버퍼링
Api더블버퍼링
 
[week11] R_ggmap, leaflet
[week11] R_ggmap, leaflet[week11] R_ggmap, leaflet
[week11] R_ggmap, leaflet
 
글꼴 렌더링 이야기
글꼴 렌더링 이야기글꼴 렌더링 이야기
글꼴 렌더링 이야기
 
Drawing with data
Drawing with dataDrawing with data
Drawing with data
 
Doing math with python.ch06
Doing math with python.ch06Doing math with python.ch06
Doing math with python.ch06
 
[1106 조진현] if you( batch rendering )
[1106 조진현] if you( batch rendering )[1106 조진현] if you( batch rendering )
[1106 조진현] if you( batch rendering )
 
Rhr
RhrRhr
Rhr
 
6 tips to supercharge c++11 vector performance
6 tips to supercharge c++11 vector performance6 tips to supercharge c++11 vector performance
6 tips to supercharge c++11 vector performance
 
Open gl
Open glOpen gl
Open gl
 
Shaderstudy Motion Blur
Shaderstudy Motion BlurShaderstudy Motion Blur
Shaderstudy Motion Blur
 
[NDC14] 라이브중인 2D게임에 시스템 변경 없이 본 애니메이션 도입하기[던전앤파이터]
[NDC14] 라이브중인 2D게임에 시스템 변경 없이 본 애니메이션 도입하기[던전앤파이터][NDC14] 라이브중인 2D게임에 시스템 변경 없이 본 애니메이션 도입하기[던전앤파이터]
[NDC14] 라이브중인 2D게임에 시스템 변경 없이 본 애니메이션 도입하기[던전앤파이터]
 
Butter android views
Butter android viewsButter android views
Butter android views
 
CSS3 text-shadow
CSS3 text-shadowCSS3 text-shadow
CSS3 text-shadow
 
[week6]R_Wrangling
[week6]R_Wrangling[week6]R_Wrangling
[week6]R_Wrangling
 

Semelhante a Html5 canvas animation

제2회 hello world 오픈세미나 collie html5-animationlibrary
제2회 hello world 오픈세미나 collie html5-animationlibrary제2회 hello world 오픈세미나 collie html5-animationlibrary
제2회 hello world 오픈세미나 collie html5-animationlibrary
NAVER D2
 
[C3]collie deview2012
[C3]collie deview2012[C3]collie deview2012
[C3]collie deview2012
NAVER D2
 

Semelhante a Html5 canvas animation (10)

제2회 hello world 오픈세미나 collie html5-animationlibrary
제2회 hello world 오픈세미나 collie html5-animationlibrary제2회 hello world 오픈세미나 collie html5-animationlibrary
제2회 hello world 오픈세미나 collie html5-animationlibrary
 
[C3]collie deview2012
[C3]collie deview2012[C3]collie deview2012
[C3]collie deview2012
 
Html5 canvas sprite animation
Html5 canvas sprite animationHtml5 canvas sprite animation
Html5 canvas sprite animation
 
[122]책에서는 맛볼 수 없는 HTML5 Canvas 이야기
[122]책에서는 맛볼 수 없는 HTML5 Canvas 이야기 [122]책에서는 맛볼 수 없는 HTML5 Canvas 이야기
[122]책에서는 맛볼 수 없는 HTML5 Canvas 이야기
 
5-1. html5 graphics
5-1. html5 graphics5-1. html5 graphics
5-1. html5 graphics
 
[Naver d2]html5 canvas overview
[Naver d2]html5 canvas overview[Naver d2]html5 canvas overview
[Naver d2]html5 canvas overview
 
스키닝 애니메이션
스키닝 애니메이션스키닝 애니메이션
스키닝 애니메이션
 
[WEB UI BASIC] WEB Animation 1탄
[WEB UI BASIC] WEB Animation 1탄[WEB UI BASIC] WEB Animation 1탄
[WEB UI BASIC] WEB Animation 1탄
 
02 조건문과 반복문
02 조건문과 반복문02 조건문과 반복문
02 조건문과 반복문
 
Deep Learning Into Advance - 1. Image, ConvNet
Deep Learning Into Advance - 1. Image, ConvNetDeep Learning Into Advance - 1. Image, ConvNet
Deep Learning Into Advance - 1. Image, ConvNet
 

Mais de SangHun Lee

Eclipse rcp 정리(enabled when, contextmenu)
Eclipse rcp 정리(enabled when, contextmenu)Eclipse rcp 정리(enabled when, contextmenu)
Eclipse rcp 정리(enabled when, contextmenu)
SangHun Lee
 

Mais de SangHun Lee (20)

PWA 파헤치기
PWA 파헤치기PWA 파헤치기
PWA 파헤치기
 
Angular Library
Angular LibraryAngular Library
Angular Library
 
Angular CodeLab 두번째
Angular CodeLab 두번째Angular CodeLab 두번째
Angular CodeLab 두번째
 
Angular CodeLab 첫번째
Angular CodeLab 첫번째Angular CodeLab 첫번째
Angular CodeLab 첫번째
 
Angular Popular Tools
Angular Popular ToolsAngular Popular Tools
Angular Popular Tools
 
Chrome 69 updates
Chrome 69 updatesChrome 69 updates
Chrome 69 updates
 
Angular Component Interaction
Angular Component InteractionAngular Component Interaction
Angular Component Interaction
 
Chrome 68 updates
Chrome 68 updatesChrome 68 updates
Chrome 68 updates
 
Reactive Programming with Rxjs
Reactive Programming with RxjsReactive Programming with Rxjs
Reactive Programming with Rxjs
 
Angular Features and New Things
Angular Features and New ThingsAngular Features and New Things
Angular Features and New Things
 
SSG광고의 오마주_에드워드 호퍼
SSG광고의 오마주_에드워드 호퍼SSG광고의 오마주_에드워드 호퍼
SSG광고의 오마주_에드워드 호퍼
 
[IOS말고 Android] Inflation을 이용하여 부분 Activity 띄우기
[IOS말고 Android] Inflation을 이용하여 부분 Activity 띄우기[IOS말고 Android] Inflation을 이용하여 부분 Activity 띄우기
[IOS말고 Android] Inflation을 이용하여 부분 Activity 띄우기
 
Ror 4주차(루비맛보기, form 태그)
Ror 4주차(루비맛보기, form 태그)Ror 4주차(루비맛보기, form 태그)
Ror 4주차(루비맛보기, form 태그)
 
Ror 2주차(컨트롤러 생성)
Ror 2주차(컨트롤러 생성)Ror 2주차(컨트롤러 생성)
Ror 2주차(컨트롤러 생성)
 
루비온레일즈_01_간단한 정적인 홈페이지 제작
루비온레일즈_01_간단한 정적인 홈페이지 제작루비온레일즈_01_간단한 정적인 홈페이지 제작
루비온레일즈_01_간단한 정적인 홈페이지 제작
 
Basic of web ref.웹을지탱하는기술_02
Basic of web ref.웹을지탱하는기술_02Basic of web ref.웹을지탱하는기술_02
Basic of web ref.웹을지탱하는기술_02
 
Eclipse gef
Eclipse gefEclipse gef
Eclipse gef
 
Gef 정리
Gef 정리Gef 정리
Gef 정리
 
Eclipse rcp 정리(enabled when, contextmenu)
Eclipse rcp 정리(enabled when, contextmenu)Eclipse rcp 정리(enabled when, contextmenu)
Eclipse rcp 정리(enabled when, contextmenu)
 
2015.07.01
2015.07.012015.07.01
2015.07.01
 

Html5 canvas animation

  • 1. Animation Codin9 café fifth html5 canvas HTML5Canvas leesanghun Lee sang hun lsh00124@naver.com
  • 3. 애니메이션은 연속된 장면을 화면에 빠르게 표시해 움직임을 나타낸다
  • 4. 단일화된 렌더링 파이프라인을 이용해 초당 60번 등록된 객체를 그린다 function draw() { // 지우기 ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); // 등록된 객체를 그리기 for (var i = 0; i < list.length; i++) { list[i].drawEachObject(); } }; // 초당 60번 반복 setInterval(draw, 1000 / 60);
  • 5. 눈에 보이지는 않지만 화면을 매번 다시 그린다 draw draw draw draw draw 초당 60번 반복한다 시스템의 리소스 낭비를 초래하여, 불필요한 전력을 소모하게 만든다. 또한, 디스플레이 갱신 전에 캔버스를 여러 번 고치 더라도 디스플레이 갱신 바로 직전의 캔버스 상태만 적용이 되기 때문에, 프레임 손실이 발생할 수도 있다.
  • 6. requestAnimationFrame을 사용하면 좀 더 자연스러운 애니메이션이 된다 function draw() { requestAnimationFrame(draw); // ... } requestAnimationFrame(draw); requestAnimationFrame() 함수는 브라우저가 화면을 업데이트 해야하는 경우에만 콜백함수를 호출한다. 이는 브라우저가 최소화되었 다던가, 다른 탭이 선택된 경우에는 콜백함수를 호출하지 않는다는 것을 의미한다. 또한 콜백함수 호출 주기(DOMHighRestTimeStamp 라고 하는데, )는 브라우저에서 관리되기 때문에 fps 값 설정 없이도 최적화된 (부드러운) 애니메이션 구현이 가능하다.
  • 7. 움직이는 동작은 지난 시간에 배웠던 스프라이트를 이용한다
  • 8. 캔버스에서는 drawImage를 이용해 간단하게 구현할 수 있다 원본 x,y,width,height drawImage 대상 x,y,width,height var ctx = elCanvas.getContext("2d"); ctx.drawImage(대상이미지, 원본x, 원본y, 원본너비, 원본높이, 대상x, 대상y, 대상너비, 대상높이);
  • 10.
  • 11. 마시마로처럼 몇 백 번을 볼지라도 같은 그림이 같은 위치에 같은 시간에 나타난다. 이런 것을 정적 애니메이션이라고 한다.
  • 13. Draw = function () { context.fillStyle = this.color; context.beginPath(); context.arc(this.x, this.y, 5, 0, Math.PI * 2, true); context.fill(); } Move = function () { this.x = this.x+this.vX; this.y = this.y+this.vY; } Bounce = function () { var X = this.x + this.vX; var Y = this.y + this.vY; if (X < 0 || X >canvas.width) { this.vX = -this.vX; } if (lY < 0 || Y > canvas.height) { this.vY = -this.vY; } }
  • 14. 동적 애니메이션이란 그때 그때 결과가 다른 애니메이션을 의미하고, 사 용자와 반응하는 애니메이션이다. 간단하게 말하면 게임이 될 수 있다.
  • 15. 이미지를 넣고, 그림을 그리고, 색깔을 입히는 등 간단한 그림판 제작하기 Creating a drawing app with HTML5 Canvas and Javascript