Suche senden
Hochladen
javascript Model- Render & canvas sample
•
Als PPTX, PDF herunterladen
•
2 gefällt mir
•
636 views
Hika Maeng
Folgen
Technologie
Melden
Teilen
Melden
Teilen
1 von 8
Jetzt herunterladen
Empfohlen
Django 1.4-cheatsheet
Django 1.4-cheatsheet
Daniel Pimenta
究極のコントローラを目指す
究極のコントローラを目指す
Yasuo Harada
Prototype UI Intro
Prototype UI Intro
Juriy Zaytsev
Fabric.js @ Falsy Values
Fabric.js @ Falsy Values
Juriy Zaytsev
BEAR DI
BEAR DI
Akihito Koriyama
Beautiful Development ブレイクスルー体験記
Beautiful Development ブレイクスルー体験記
kentaro watanabe
FrOScamp Zurich: Introducing JCR - 2010
FrOScamp Zurich: Introducing JCR - 2010
David Nuescheler
"Coffee Script" in Brief
"Coffee Script" in Brief
Nat Weerawan
Empfohlen
Django 1.4-cheatsheet
Django 1.4-cheatsheet
Daniel Pimenta
究極のコントローラを目指す
究極のコントローラを目指す
Yasuo Harada
Prototype UI Intro
Prototype UI Intro
Juriy Zaytsev
Fabric.js @ Falsy Values
Fabric.js @ Falsy Values
Juriy Zaytsev
BEAR DI
BEAR DI
Akihito Koriyama
Beautiful Development ブレイクスルー体験記
Beautiful Development ブレイクスルー体験記
kentaro watanabe
FrOScamp Zurich: Introducing JCR - 2010
FrOScamp Zurich: Introducing JCR - 2010
David Nuescheler
"Coffee Script" in Brief
"Coffee Script" in Brief
Nat Weerawan
The Canvas API for Rubyists
The Canvas API for Rubyists
deanhudson
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)
Leonardo Soto
Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)
Leonardo Soto
20160227 Granma
20160227 Granma
Sharon Liu
J slider
J slider
Sesum Dragomir
Bindings: the zen of montage
Bindings: the zen of montage
Kris Kowal
React Native - Workshop
React Native - Workshop
Fellipe Chagas
ddd+scala
ddd+scala
潤一 加藤
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
whitneyleman54422
Exploring Canvas
Exploring Canvas
Kevin Hoyt
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Bin Shao
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
Divante
Virtual Madness @ Etsy
Virtual Madness @ Etsy
Nishan Subedi
Bacbkone js
Bacbkone js
Артём Курапов
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnCon
Rafael Dohms
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
DroidConTLV
CoffeeScript
CoffeeScript
None
Webgl para JavaScripters
Webgl para JavaScripters
gerbille
ES6 Overview
ES6 Overview
Bruno Scopelliti
Building mobile web apps with Mobello
Building mobile web apps with Mobello
Jeong-Geun Kim
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
Michael W. Hawkins
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
The Digital Insurer
Weitere ähnliche Inhalte
Ähnlich wie javascript Model- Render & canvas sample
The Canvas API for Rubyists
The Canvas API for Rubyists
deanhudson
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)
Leonardo Soto
Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)
Leonardo Soto
20160227 Granma
20160227 Granma
Sharon Liu
J slider
J slider
Sesum Dragomir
Bindings: the zen of montage
Bindings: the zen of montage
Kris Kowal
React Native - Workshop
React Native - Workshop
Fellipe Chagas
ddd+scala
ddd+scala
潤一 加藤
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
whitneyleman54422
Exploring Canvas
Exploring Canvas
Kevin Hoyt
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Bin Shao
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
Divante
Virtual Madness @ Etsy
Virtual Madness @ Etsy
Nishan Subedi
Bacbkone js
Bacbkone js
Артём Курапов
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnCon
Rafael Dohms
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
DroidConTLV
CoffeeScript
CoffeeScript
None
Webgl para JavaScripters
Webgl para JavaScripters
gerbille
ES6 Overview
ES6 Overview
Bruno Scopelliti
Building mobile web apps with Mobello
Building mobile web apps with Mobello
Jeong-Geun Kim
Ähnlich wie javascript Model- Render & canvas sample
(20)
The Canvas API for Rubyists
The Canvas API for Rubyists
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)
20160227 Granma
20160227 Granma
J slider
J slider
Bindings: the zen of montage
Bindings: the zen of montage
React Native - Workshop
React Native - Workshop
ddd+scala
ddd+scala
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
Exploring Canvas
Exploring Canvas
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
Virtual Madness @ Etsy
Virtual Madness @ Etsy
Bacbkone js
Bacbkone js
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnCon
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
CoffeeScript
CoffeeScript
Webgl para JavaScripters
Webgl para JavaScripters
ES6 Overview
ES6 Overview
Building mobile web apps with Mobello
Building mobile web apps with Mobello
Kürzlich hochgeladen
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
Michael W. Hawkins
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
The Digital Insurer
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Igalia
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
Malak Abu Hammad
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
Radu Cotescu
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
Enterprise Knowledge
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Rafal Los
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
naman860154
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
The Digital Insurer
Slack Application Development 101 Slides
Slack Application Development 101 Slides
praypatel2
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
Principled Technologies
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Neo4j
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
Delhi Call girls
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
apidays
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
Pixlogix Infotech
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
sudhanshuwaghmare1
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Miguel Araújo
Kürzlich hochgeladen
(20)
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
Slack Application Development 101 Slides
Slack Application Development 101 Slides
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
javascript Model- Render & canvas sample
1.
S53 #3 3-1 MVC, Model
- Render 3-2 Canvas 3-3 Model 3-4 Render 3-5 Child 3-6 Event 2012.10.31 20:30 ~ 22:30
2.
Model, View, Controller
Model - Render Model Model Data, Business Logic Data, Business Logic Render Controller Handler, Adapter View View Controller UI, Present
3.
Canvas #1
PixelMap Array = [r,g,b,a, r,g,b,a, ...] context.fillRect( 0, 0, 2, 1 ); [0,0,0,0xff, 0,0,0,0xff, ...] context.lineTo( 2, 0 ); context.stroke(); [0,0,0,0xff, 0,0,0,0xff, ...]
4.
Canvas #2
State 1 State 2 State 3 lineWidth lineWidth lineWidth lineCap context.save() lineCap context.save() lineCap strokeStyle strokeStyle strokeStyle fillStyle fillStyle fillStyle font font font textBaseline textBaseline textBaseline textAlign textAlign textAlign translate translate translate context.restore() context.restore() . . . . . . . . .
5.
Model
Canvas Children context child 1 child 2 child 3 state state state width, height ... draw draw draw isUpdated etc etc etc function Model( $width, $height ){ Model.prototype.update = function(){ var canvas, context; this.isUpdated = false; canvas = document.createElement( 'canvas' ); }; canvas.width = $width; Model.prototype.setSize = function( $width, $height ){ canvas.height = $height; this.canvas.width = this.width = $width; context = canvas.getContext( '2d' ); this.canvas.height = this.height = $height; this.canvas = canvas; }; this.width = $width; Model.prototype.addChild = function( $child ){ this.height = $height; $child.parent = this; this.context = context; this.children.push( $child ); this.children = []; }; this.isUpdated = true; Model.prototype.removeChild = function( $child ){ } this.children.splice( this.children.indexOf( $child ), 1 ); }; Model.prototype.getIndex = function( $child ){ var model = new Model( 500, 500 ); return this.children.indexOf( $child ); var stage = document.getElementById('stage'); }; stage.appendChild( model.canvas ); Model.prototype.swapIndex = function( $from, $to ){ var to = this.children[$to]; model.addChild( new Child(...) ); this.children[$to] = this.children[$from]; this.children[$from] = to; setInterval( model.render, 17 ); }
6.
Render
! isUpdated Model.prototype.render = function(){ context.clearRect(); var i, j; if( this.isUpdated ) return; Loop Children this.context.clearRect( 0, 0, this.width, this.height ); for( i = 0, j = this.children.length ; i < j ; i++ ){ context.save(); this.context.save(); this.children[i].render( this.context ); children[i].render( context ); this.context.restore(); } context.restore(); this.isUpdated = true; } isUpdated = true;
7.
Child function Child( $image
){ Child.prototype.setAttribute = function( $attr, $val ){ this.image = $image; if( this[$attr] === undefined ) return; this.width = image.width; this[$attr] = $val; this.height = image.height; this.parent.update(); this.x = 0; }; this.y = 0; Child.prototype.render = function( $context ){ this.rotation = 0; $context.translate( this.x, this.y ); this.parent = null; if( this.rotation ){ } $context.rotate( toRadian * this.rotation ); } var img, child; $context.drawImage( img = new Image; this.image, 0, 0, this.width, this.height img.src = 'test.png'; ); img.onload = function(){ }; child = new Child( img ); child.setAttribute( 'x', 30 ); //toRadian = 2 * pi / 360 child.setAttribute( 'y', 30 ); child.setAttribute( 'rotation', 90 ); model.addChild( child ); };
8.
Event canvas.addEventListener( 'click', controller
) function Child( $image ){ ... function controller( $e ){ this.click = []; var i, j; } for( i = 0, j = model.children ; i < j ; i++ ){ model.children[i].click( $e ); Child.prototype.addEventListener = function( $type, $listener ){ } if( this[$type] === undefined ) return; } this[$attr].push( $listener ); }; Child.prototype.click = function( $e ){ var i, j, x, y; if( this.x < $e.localX && $e. localX < this.x + this.width && this.y < $e.localY && $e. localY < this.y + this.height ){ $e.localX -= this.x; $e.localY -= this.y; for( i = 0, j = this.click ; i < j ; i++ ){ this.chick[i]( $e ); } child.addEventListener( 'click', function( $e ){ } alert( $e.localX + ":" + $e.localY ); }; };
Jetzt herunterladen