-
Notifications
You must be signed in to change notification settings - Fork 3
/
HTML5 - Beginners - StringAtModify.html
57 lines (47 loc) · 1.29 KB
/
HTML5 - Beginners - StringAtModify.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html>
<head>
<meta charsetp="UTF-8">
<meta name="viewport" content="width=device-width" />
</head>
<body bgcolor="black">
<style>#myCanvas {touch-action: none;}</style>
<canvas id="myCanvas" width="320" height="240" style="border:0px solid #d3d3d3;">
Use different browser.
</canvas>
<script>
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
gameloop=setInterval(doGameLoop,16);
function doGameLoop(){
myCanvas.height = window.innerHeight*.98;
myCanvas.width = window.innerWidth*.96;
ctx.scale(1,1);
ctx.fillStyle="rgb(0,0,0)";
ctx.fillRect(0,0,c.width,c.height);
ctx.fillStyle="rgb(255,255,255)";
ctx.fillText("a javascript example.",10,10);
// here we create a string
var simba = "I am Simba";
// here we slice a new string
// we take chars from start to
// just before 'a'. Then add
// 'is' and the slice from after
// 'am'
simba = simba.slice(0,2)+"is"+simba.slice(4,simba.length);
// scale up drawing commands
ctx.scale(1.7,2);
// draw our modified string
// to the screen
ctx.fillText("A new string :\""+simba+"\"",10,30);
// note. simba[x] returns the
// character at x in the string. But
// strings are special objects
// that use double space. so
// modifying using [] is not
// possible. use slice! or
// replace commands.
}
</script>
</body>
</html>