SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Downloaden Sie, um offline zu lesen
DRAWING ON CANVAS

     chapter 6
Javascript + canvas

    - Drawing a Logo



    - Graphing Statistics with RGraph
 

The Canvas Element

<canvas id="my_canvas" width="150" height="150"> 
 Fallback content here 
</canvas>

can't use css
 

var canvas = document.getElementById('my_canvas');
if (canvas.getContext){
    var context = canvas.getContext('2d');
}else{

}
canvas_simple_drawing.html

var canvas = document.getElementById('my_canvas'); 
 if (canvas.getContext){ 
 var context = canvas.getContext('2d'); 
  context.fillStyle = "rgb(200,0,0)"; 
  context.fillRect (10, 10, 100, 100); 
  context.fillStyle = "rgb(0,0,200)"; 
  context.fillRect (30, 30, 100, 100); 
  context.strokeStyle = "rgb(200,0,0)"; 
  context.lineWidth = 2; context.beginPath(); context.moveTo
(0, 0); context.lineTo(100, 100); context.stroke(); context.
closePath();}........
Drawing the logo

string of text, an angeld path, a squeare, a triangle

Adding Text 
   c o n t e x t . f o n t = ' i t a l i c 4 0 p x s a n s - s e r i f ' ;
   c o n t e x t . t e x t B a s e l i n e = ' t o p ' ;
   c o n t e x t . f i l l T e x t ( ' A w e s o m e C o ' , 6 0 , 0 ) ;
Drawing the Logo

Drawing lines
    c o n t e x t   .   lineWidth=2;
    c o n t e x t   .   beginPath();
    c o n t e x t   .   moveTo(0,40);
    c o n t e x t   .   lineTo(30,0);
    c o n t e x t   .   lineTo(60,40);
    c o n t e x t   .   lineTo(285,40);
    c o n t e x t   .   stroke();
    c o n t e x t   .   c l o s e P a t h ( ) 
Drawing the Logo

Moving the Origin
    c o n t e x t . s a v e ( ) ;
    c o n t e x t . t r a n s l a t e ( 2 0 , 2 0 ) ;
    c o n t e x t . f i l l R e c t ( 0 , 0 , 2 0 , 2 0 ) ;
Drawing the Logo

Drawing a triangle
    c o n t e x t . f i l l S t y l e = ' # f f f '
    c o n t e x t . s t r o k e S t y l e = ' # f f f ' ;
    c o n t e x t . l i n e W i d t h = 2 ;
    c o n t e x t . b e g i n P a t h ( ) ;
    c o n t e x t . m o v e T o ( 0 , 2 0 ) ;
    c o n t e x t . l i n e T o ( 1 0 , 0 ) ;
    c o n t e x t . l i n e T o ( 2 0 , 2 0 ) ;
    c o n t e x t . l i n e T o ( 0 , 2 0 ) ;
    c o n t e x t . f i l l ( ) ;
    c o n t e x t . c l o s e P a t h ( ) ;
    c o n t e x t . r e s t o r e ( ) ;
Drawing the Logo

AddingColors
// context.fillStyle = "#f00";
// context.strokeStyle = "#f00";
var gradient = context.createLinearGradient(0, 0, 0, 40);
gradient.addColorStop(0, '#a00'); // red
gradient.addColorStop(1, '#f00'); // red
context.fillStyle = gradient;
context.strokeStyle = gradient;
Falling back

Google released a library called ExplorerCanvas

<scriptsrc="javascripts/excanvas.js">
</script>
Graphing Statistics with RGraph




<canvas width="500" height="250" id="test">[no canvas
support]</canvas> 

<script type="text/javascript" charset="utf-8"> 
 var bar = new RGraph.Bar('test', [50,25,15,10]); bar.Set
('chart.gutter', 50); bar.Set('chart.colors', ['red']); bar.Set
('chart.title', "A bar graph of my favorite pies"); bar.Set('chart.
labels', ["Banana Creme", "Pumpkin", "Apple", "Cherry"]); 
 bar.Draw(); 
 </script>
 

Describing Data with HTML

<div id="graph_data"> <h1>Browser share for this site</h1>
<ul> <li> <p data-name="Safari 4" data-percent="15"> Safari 4 -
15% </p> </li> <li> <p data-name="Internet Explorer" data-
percent="55"> Internet Explorer - 55% </p> </li> <li> <p data-
name="Firefox" data-percent="14"> Firefox - 14% </p> </li>
<li> <p data-name="Google Chrome" data-percent="16">
Google Chrome - 16% </p> </li> </ul> </div>
 

load libraries
<script type="text/javascript" charset="utf-8" src="http:
//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
> </script> 
<script src="javascripts/RGraph.common.js" ></script> <script
src="javascripts/RGraph.bar.js" ></script>
 

Turning Our HTML into a Bar Graph

function canvasGraph(){ var title = $('#graph_data h1').text();
var labels = $("#graph_data>ul>li>p[data-name]").map
(function(){ return $(this).attr("data-name"); });
var percents = $("#graph_data>ul>li>p[data-percent]").map
(function(){ return parseInt($(this).attr("data-percent")); });
var bar = new RGraph.Bar('browsers', percents); bar.Set
('chart.gutter', 50); bar.Set('chart.colors', ['red']); bar.Set
('chart.title', title); bar.Set('chart.labels', labels); bar.Draw();
}
Displaying Alternative Content


var canvas = document.getElementById('browsers'); 
 if (canvas.getContext)
{ 
 $('#graph_data').hide(); 
 canvasGraph(); 
 }
Falling back

function divGraph(barColor, textColor, width, spacer,
lblHeight)
{ 
 $('#graph_data ul').hide(); 
 var container = $("#graph_data"); 
 container.css( { "display" : "block", "position" : "relative",
"height": "300px"} );
$("#graph_data>ul>li>p").each(function(i){ 
    var bar = $("<div>" + $(this).attr("data-percent") + "%
</div>"); 
   var label = $("<div>" + $(this).attr("data-name") +
"</div>");               var commonCSS = { "width": width + "px",
"position" : "absolute", "left" : i * (width + spacer) + "px"}; var
barCSS = { "background-color" : barColor, "color" : textColor,
The Future

 

Weitere ähnliche Inhalte

Was ist angesagt?

Programa expresiones regulares
Programa expresiones regularesPrograma expresiones regulares
Programa expresiones regularesAnel Sosa
 
Worth the hype - styled components
Worth the hype - styled componentsWorth the hype - styled components
Worth the hype - styled componentskathrinholzmann
 
Perlで実装されたLINE NEWSの裏側
Perlで実装されたLINE NEWSの裏側Perlで実装されたLINE NEWSの裏側
Perlで実装されたLINE NEWSの裏側LINE Corporation
 
Paperjs presentation
Paperjs presentationPaperjs presentation
Paperjs presentationsharp-blade
 
Random. Kinda.
Random. Kinda.Random. Kinda.
Random. Kinda.awwaiid
 
Plot3D Package and Example in R.-Data visualizat,on
Plot3D Package and Example in R.-Data visualizat,onPlot3D Package and Example in R.-Data visualizat,on
Plot3D Package and Example in R.-Data visualizat,onDr. Volkan OBAN
 
Paperjs presentation
Paperjs presentationPaperjs presentation
Paperjs presentationsharp-blade
 
Processing資料(8) 文字
Processing資料(8) 文字Processing資料(8) 文字
Processing資料(8) 文字reona396
 
Tablas relaciones proyecto Laravel
Tablas relaciones proyecto LaravelTablas relaciones proyecto Laravel
Tablas relaciones proyecto LaravelFUNDET ECUADOR
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207Syed Tanveer
 
Oh, you’re the NY times guy
Oh, you’re the NY times guyOh, you’re the NY times guy
Oh, you’re the NY times guyDavid Hayes
 
Perl使いの国のRubyist
Perl使いの国のRubyistPerl使いの国のRubyist
Perl使いの国のRubyistTakafumi ONAKA
 

Was ist angesagt? (19)

Programa expresiones regulares
Programa expresiones regularesPrograma expresiones regulares
Programa expresiones regulares
 
Worth the hype - styled components
Worth the hype - styled componentsWorth the hype - styled components
Worth the hype - styled components
 
Perlで実装されたLINE NEWSの裏側
Perlで実装されたLINE NEWSの裏側Perlで実装されたLINE NEWSの裏側
Perlで実装されたLINE NEWSの裏側
 
C code
C codeC code
C code
 
Paperjs presentation
Paperjs presentationPaperjs presentation
Paperjs presentation
 
Random. Kinda.
Random. Kinda.Random. Kinda.
Random. Kinda.
 
Plot3D Package and Example in R.-Data visualizat,on
Plot3D Package and Example in R.-Data visualizat,onPlot3D Package and Example in R.-Data visualizat,on
Plot3D Package and Example in R.-Data visualizat,on
 
Zebra
ZebraZebra
Zebra
 
Paperjs presentation
Paperjs presentationPaperjs presentation
Paperjs presentation
 
Processing資料(8) 文字
Processing資料(8) 文字Processing資料(8) 文字
Processing資料(8) 文字
 
Pointer level 2
Pointer   level 2Pointer   level 2
Pointer level 2
 
Tablas relaciones proyecto Laravel
Tablas relaciones proyecto LaravelTablas relaciones proyecto Laravel
Tablas relaciones proyecto Laravel
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
 
Oh, you’re the NY times guy
Oh, you’re the NY times guyOh, you’re the NY times guy
Oh, you’re the NY times guy
 
Formato encuesta
Formato encuestaFormato encuesta
Formato encuesta
 
Include
IncludeInclude
Include
 
Perl使いの国のRubyist
Perl使いの国のRubyistPerl使いの国のRubyist
Perl使いの国のRubyist
 
画像Hacks
画像Hacks画像Hacks
画像Hacks
 

Andere mochten auch

2.2.4 순환목록
2.2.4 순환목록2.2.4 순환목록
2.2.4 순환목록suitzero
 
1.4.2 코루틴연습문제
1.4.2 코루틴연습문제1.4.2 코루틴연습문제
1.4.2 코루틴연습문제suitzero
 
Clojure in the Wild
Clojure in the WildClojure in the Wild
Clojure in the Wildsuitzero
 
클로저
클로저클로저
클로저dagri82
 

Andere mochten auch (7)

7장매크로
7장매크로7장매크로
7장매크로
 
2.2.4 순환목록
2.2.4 순환목록2.2.4 순환목록
2.2.4 순환목록
 
1.4.2 코루틴연습문제
1.4.2 코루틴연습문제1.4.2 코루틴연습문제
1.4.2 코루틴연습문제
 
Clojure in the Wild
Clojure in the WildClojure in the Wild
Clojure in the Wild
 
클로저
클로저클로저
클로저
 
8.다중메서드
8.다중메서드8.다중메서드
8.다중메서드
 
Clojure Chapter.6
Clojure Chapter.6Clojure Chapter.6
Clojure Chapter.6
 

Ähnlich wie Drawing on canvas

Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
Bubble archery game(c program)
Bubble archery game(c program)Bubble archery game(c program)
Bubble archery game(c program)SETYA HADI
 
Bubble archery game(c program)
Bubble archery game(c program)Bubble archery game(c program)
Bubble archery game(c program)SETYA HADI
 
How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1Bitla Software
 
Wynn Netherland: Accelerating Titanium Development with CoffeeScript, Compass...
Wynn Netherland: Accelerating Titanium Development with CoffeeScript, Compass...Wynn Netherland: Accelerating Titanium Development with CoffeeScript, Compass...
Wynn Netherland: Accelerating Titanium Development with CoffeeScript, Compass...Axway Appcelerator
 
JavaOne 2009 - 2d Vector Graphics in the browser with Canvas and SVG
JavaOne 2009 -  2d Vector Graphics in the browser with Canvas and SVGJavaOne 2009 -  2d Vector Graphics in the browser with Canvas and SVG
JavaOne 2009 - 2d Vector Graphics in the browser with Canvas and SVGPatrick Chanezon
 
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfbfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfshehabhamad_90
 
Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)zahid-mian
 
Google Visualization API
Google  Visualization  APIGoogle  Visualization  API
Google Visualization APIJason Young
 
Будь первым
Будь первымБудь первым
Будь первымFDConf
 
CSS3 Takes on the World
CSS3 Takes on the WorldCSS3 Takes on the World
CSS3 Takes on the WorldJonathan Snook
 
JSinSA - JS Visualisation APIs
JSinSA - JS Visualisation APIsJSinSA - JS Visualisation APIs
JSinSA - JS Visualisation APIsBrendon McLean
 
Canvas
CanvasCanvas
CanvasRajon
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! aleks-f
 

Ähnlich wie Drawing on canvas (20)

Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Bubble archery game(c program)
Bubble archery game(c program)Bubble archery game(c program)
Bubble archery game(c program)
 
Bubble archery game(c program)
Bubble archery game(c program)Bubble archery game(c program)
Bubble archery game(c program)
 
How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1
 
Graphical representation of Stack
Graphical representation of StackGraphical representation of Stack
Graphical representation of Stack
 
Canvas - The Cure
Canvas - The CureCanvas - The Cure
Canvas - The Cure
 
Wynn Netherland: Accelerating Titanium Development with CoffeeScript, Compass...
Wynn Netherland: Accelerating Titanium Development with CoffeeScript, Compass...Wynn Netherland: Accelerating Titanium Development with CoffeeScript, Compass...
Wynn Netherland: Accelerating Titanium Development with CoffeeScript, Compass...
 
JavaOne 2009 - 2d Vector Graphics in the browser with Canvas and SVG
JavaOne 2009 -  2d Vector Graphics in the browser with Canvas and SVGJavaOne 2009 -  2d Vector Graphics in the browser with Canvas and SVG
JavaOne 2009 - 2d Vector Graphics in the browser with Canvas and SVG
 
Css5 canvas
Css5 canvasCss5 canvas
Css5 canvas
 
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfbfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
 
Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)
 
Google Visualization API
Google  Visualization  APIGoogle  Visualization  API
Google Visualization API
 
Будь первым
Будь первымБудь первым
Будь первым
 
Borrador del blog
Borrador del blogBorrador del blog
Borrador del blog
 
CSS3 Takes on the World
CSS3 Takes on the WorldCSS3 Takes on the World
CSS3 Takes on the World
 
JSinSA - JS Visualisation APIs
JSinSA - JS Visualisation APIsJSinSA - JS Visualisation APIs
JSinSA - JS Visualisation APIs
 
Proga 0608
Proga 0608Proga 0608
Proga 0608
 
Canvas
CanvasCanvas
Canvas
 
Raphaël
RaphaëlRaphaël
Raphaël
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! 
 

Mehr von suitzero

The gravitational N -body pro
The gravitational N -body proThe gravitational N -body pro
The gravitational N -body prosuitzero
 
xUnitTestPattern/chapter16
xUnitTestPattern/chapter16xUnitTestPattern/chapter16
xUnitTestPattern/chapter16suitzero
 
HolubOnPatterns/chapter3_3
HolubOnPatterns/chapter3_3HolubOnPatterns/chapter3_3
HolubOnPatterns/chapter3_3suitzero
 
3장 자동적으로 움직이는 게임 에이전트 생성법_2
3장 자동적으로 움직이는 게임 에이전트 생성법_23장 자동적으로 움직이는 게임 에이전트 생성법_2
3장 자동적으로 움직이는 게임 에이전트 생성법_2suitzero
 
3장 자동적으로 움직이는 게임 에이전트 생성법
3장 자동적으로 움직이는 게임 에이전트 생성법3장 자동적으로 움직이는 게임 에이전트 생성법
3장 자동적으로 움직이는 게임 에이전트 생성법suitzero
 
부울 대수와 컴퓨터 논리
부울 대수와 컴퓨터 논리부울 대수와 컴퓨터 논리
부울 대수와 컴퓨터 논리suitzero
 
프리젠테이션-제목없음
프리젠테이션-제목없음프리젠테이션-제목없음
프리젠테이션-제목없음suitzero
 

Mehr von suitzero (7)

The gravitational N -body pro
The gravitational N -body proThe gravitational N -body pro
The gravitational N -body pro
 
xUnitTestPattern/chapter16
xUnitTestPattern/chapter16xUnitTestPattern/chapter16
xUnitTestPattern/chapter16
 
HolubOnPatterns/chapter3_3
HolubOnPatterns/chapter3_3HolubOnPatterns/chapter3_3
HolubOnPatterns/chapter3_3
 
3장 자동적으로 움직이는 게임 에이전트 생성법_2
3장 자동적으로 움직이는 게임 에이전트 생성법_23장 자동적으로 움직이는 게임 에이전트 생성법_2
3장 자동적으로 움직이는 게임 에이전트 생성법_2
 
3장 자동적으로 움직이는 게임 에이전트 생성법
3장 자동적으로 움직이는 게임 에이전트 생성법3장 자동적으로 움직이는 게임 에이전트 생성법
3장 자동적으로 움직이는 게임 에이전트 생성법
 
부울 대수와 컴퓨터 논리
부울 대수와 컴퓨터 논리부울 대수와 컴퓨터 논리
부울 대수와 컴퓨터 논리
 
프리젠테이션-제목없음
프리젠테이션-제목없음프리젠테이션-제목없음
프리젠테이션-제목없음
 

Kürzlich hochgeladen

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Kürzlich hochgeladen (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

Drawing on canvas

  • 1. DRAWING ON CANVAS chapter 6
  • 2. Javascript + canvas     - Drawing a Logo     - Graphing Statistics with RGraph
  • 3.   The Canvas Element <canvas id="my_canvas" width="150" height="150">   Fallback content here  </canvas> can't use css
  • 4.   var canvas = document.getElementById('my_canvas'); if (canvas.getContext){     var context = canvas.getContext('2d'); }else{ }
  • 5. canvas_simple_drawing.html var canvas = document.getElementById('my_canvas');   if (canvas.getContext){   var context = canvas.getContext('2d');    context.fillStyle = "rgb(200,0,0)";    context.fillRect (10, 10, 100, 100);    context.fillStyle = "rgb(0,0,200)";    context.fillRect (30, 30, 100, 100);    context.strokeStyle = "rgb(200,0,0)";    context.lineWidth = 2; context.beginPath(); context.moveTo (0, 0); context.lineTo(100, 100); context.stroke(); context. closePath();}........
  • 6. Drawing the logo string of text, an angeld path, a squeare, a triangle Adding Text     c o n t e x t . f o n t = ' i t a l i c 4 0 p x s a n s - s e r i f ' ;    c o n t e x t . t e x t B a s e l i n e = ' t o p ' ;    c o n t e x t . f i l l T e x t ( ' A w e s o m e C o ' , 6 0 , 0 ) ;
  • 7. Drawing the Logo Drawing lines     c o n t e x t . lineWidth=2;     c o n t e x t . beginPath();     c o n t e x t . moveTo(0,40);     c o n t e x t . lineTo(30,0);     c o n t e x t . lineTo(60,40);     c o n t e x t . lineTo(285,40);     c o n t e x t . stroke();     c o n t e x t . c l o s e P a t h ( ) 
  • 8. Drawing the Logo Moving the Origin     c o n t e x t . s a v e ( ) ;     c o n t e x t . t r a n s l a t e ( 2 0 , 2 0 ) ;     c o n t e x t . f i l l R e c t ( 0 , 0 , 2 0 , 2 0 ) ;
  • 9. Drawing the Logo Drawing a triangle     c o n t e x t . f i l l S t y l e = ' # f f f '     c o n t e x t . s t r o k e S t y l e = ' # f f f ' ;     c o n t e x t . l i n e W i d t h = 2 ;     c o n t e x t . b e g i n P a t h ( ) ;     c o n t e x t . m o v e T o ( 0 , 2 0 ) ;     c o n t e x t . l i n e T o ( 1 0 , 0 ) ;     c o n t e x t . l i n e T o ( 2 0 , 2 0 ) ;     c o n t e x t . l i n e T o ( 0 , 2 0 ) ;     c o n t e x t . f i l l ( ) ;     c o n t e x t . c l o s e P a t h ( ) ;     c o n t e x t . r e s t o r e ( ) ;
  • 10. Drawing the Logo AddingColors // context.fillStyle = "#f00"; // context.strokeStyle = "#f00"; var gradient = context.createLinearGradient(0, 0, 0, 40); gradient.addColorStop(0, '#a00'); // red gradient.addColorStop(1, '#f00'); // red context.fillStyle = gradient; context.strokeStyle = gradient;
  • 11. Falling back Google released a library called ExplorerCanvas <scriptsrc="javascripts/excanvas.js"> </script>
  • 12. Graphing Statistics with RGraph <canvas width="500" height="250" id="test">[no canvas support]</canvas>  <script type="text/javascript" charset="utf-8">   var bar = new RGraph.Bar('test', [50,25,15,10]); bar.Set ('chart.gutter', 50); bar.Set('chart.colors', ['red']); bar.Set ('chart.title', "A bar graph of my favorite pies"); bar.Set('chart. labels', ["Banana Creme", "Pumpkin", "Apple", "Cherry"]);   bar.Draw();   </script>
  • 13.   Describing Data with HTML <div id="graph_data"> <h1>Browser share for this site</h1> <ul> <li> <p data-name="Safari 4" data-percent="15"> Safari 4 - 15% </p> </li> <li> <p data-name="Internet Explorer" data- percent="55"> Internet Explorer - 55% </p> </li> <li> <p data- name="Firefox" data-percent="14"> Firefox - 14% </p> </li> <li> <p data-name="Google Chrome" data-percent="16"> Google Chrome - 16% </p> </li> </ul> </div>
  • 14.   load libraries <script type="text/javascript" charset="utf-8" src="http: //ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" > </script>  <script src="javascripts/RGraph.common.js" ></script> <script src="javascripts/RGraph.bar.js" ></script>
  • 15.   Turning Our HTML into a Bar Graph function canvasGraph(){ var title = $('#graph_data h1').text(); var labels = $("#graph_data>ul>li>p[data-name]").map (function(){ return $(this).attr("data-name"); }); var percents = $("#graph_data>ul>li>p[data-percent]").map (function(){ return parseInt($(this).attr("data-percent")); }); var bar = new RGraph.Bar('browsers', percents); bar.Set ('chart.gutter', 50); bar.Set('chart.colors', ['red']); bar.Set ('chart.title', title); bar.Set('chart.labels', labels); bar.Draw(); }
  • 16. Displaying Alternative Content var canvas = document.getElementById('browsers');   if (canvas.getContext) {   $('#graph_data').hide();   canvasGraph();   }
  • 17. Falling back function divGraph(barColor, textColor, width, spacer, lblHeight) {   $('#graph_data ul').hide();   var container = $("#graph_data");   container.css( { "display" : "block", "position" : "relative", "height": "300px"} ); $("#graph_data>ul>li>p").each(function(i){      var bar = $("<div>" + $(this).attr("data-percent") + "% </div>");     var label = $("<div>" + $(this).attr("data-name") + "</div>");               var commonCSS = { "width": width + "px", "position" : "absolute", "left" : i * (width + spacer) + "px"}; var barCSS = { "background-color" : barColor, "color" : textColor,