Wiki source code of Nixie Spritesheet
Last modified by Victor Zhang on 00:34, 22/07/2020
Hide last authors
![]() |
3.1 | 1 | * During the development of the GDice app ( the log will be posted soon ), I was experimenting ways to display numbers |
2 | * One particular way interested me that has the nostalgic feeling, called [[Nixie Tube>>https://en.wikipedia.org/wiki/Nixie_tube]] | ||
3 | ** End up not using it, but it's a good test | ||
4 | ** Built using [[Autodesk Fusion 360>>https://www.autodesk.com/products/fusion-360/students-teachers-educators]] | ||
5 | *** Solid modeling , will not be polygon efficient for game rendering | ||
6 | *** Rendered as spritesheet, as f360 has a pretty easy to tune rendering system that's almost photo realistic | ||
7 | ** Result put in : [[Nixie Tube Spritesheet>>https://opengameart.org/content/nixie-digits-spritesheet]] | ||
![]() |
5.1 | 8 | ** Packed using [[Texturepacker's free version>>https://www.codeandweb.com/texturepacker]]((( |
![]() |
3.1 | 9 | (% border="1" class="table-bordered" %) |
10 | |Rendered using Orthogonal Camera|[[image:NixieOrth.png]] | ||
11 | |Rendered using Perspective Camera|[[image:NixiePers.png]] | ||
12 | ))) | ||
![]() |
70.1 | 13 | * Phaser P5 not working somehow needs investigate |
![]() |
78.1 | 14 | * Somehow can only use raw API |
![]() |
5.1 | 15 | |
![]() |
30.1 | 16 | {{html clean="false"}} |
![]() |
76.1 | 17 | <div id="canvasparent"> |
![]() |
78.1 | 18 | <canvas id="mycanvas" width="600" height="300"> |
![]() |
74.1 | 19 | </canvas> |
20 | </div> | ||
![]() |
6.1 | 21 | <script> |
![]() |
89.1 | 22 | let windowurl = window.location.href; |
![]() |
93.1 | 23 | let attachurl = windowurl.substring(0, 41) + 'download' + windowurl.substring(45); |
![]() |
74.1 | 24 | setTimeout( () => { |
![]() |
77.1 | 25 | let c = document.getElementById("mycanvas"); |
![]() |
76.1 | 26 | let ctx = c.getContext("2d"); |
27 | |||
![]() |
91.1 | 28 | let imgurls = [attachurl+'WebHome/NixieOrth.png', attachurl+'WebHome/NixiePers.png']; |
![]() |
81.1 | 29 | |
![]() |
102.1 | 30 | // console.log( "Load image:", JSON.stringify(imgurls) ); |
31 | // console.log( "canvas size:",c.width, ",", c.height ); | ||
![]() |
79.1 | 32 | let scrwidth = c.width; |
33 | let scrheight = c.height; | ||
34 | let borderwidth = 2; | ||
35 | |||
36 | // Draw a border | ||
37 | ctx.beginPath(); | ||
38 | ctx.lineWidth = ""+borderwidth; | ||
39 | ctx.strokeStyle = "#ffffff"; | ||
![]() |
80.1 | 40 | ctx.rect(borderwidth / 2, borderwidth / 2, scrwidth - borderwidth, scrheight - borderwidth); |
![]() |
79.1 | 41 | ctx.stroke(); |
![]() |
94.1 | 42 | |
43 | // create images | ||
44 | imgloads = []; | ||
45 | imgurls.forEach( (item, ids) => { | ||
46 | let thisimg = document.createElement("img"); | ||
47 | thisimg.src = item; | ||
48 | imgloads.push( thisimg ); | ||
49 | }); | ||
![]() |
102.1 | 50 | // console.log( imgloads ); |
![]() |
95.1 | 51 | |
52 | var currentidx = 0; | ||
53 | setInterval( () => { | ||
![]() |
97.1 | 54 | // redraw static |
55 | ctx.clearRect(0, 0, scrwidth , scrheight); | ||
56 | // Draw a border | ||
57 | ctx.beginPath(); | ||
58 | ctx.lineWidth = ""+borderwidth; | ||
59 | ctx.strokeStyle = "#ffffff"; | ||
60 | ctx.rect(borderwidth / 2, borderwidth / 2, scrwidth - borderwidth, scrheight - borderwidth); | ||
61 | ctx.stroke(); | ||
62 | |||
![]() |
102.1 | 63 | // console.log( "Drawing frame:" + currentidx ); |
![]() |
101.1 | 64 | ctx.drawImage(imgloads[0], 76 * currentidx, 0, 76, 157, 112, 72, 76, 157); |
65 | ctx.drawImage(imgloads[1], 76 * currentidx, 0, 76, 162, 412, 69, 76, 162); | ||
![]() |
95.1 | 66 | currentidx++; |
![]() |
96.1 | 67 | currentidx %= 10; |
![]() |
95.1 | 68 | } , 500 ); |
![]() |
74.1 | 69 | }, 1000 ); |
![]() |
6.1 | 70 | </script> |
![]() |
5.1 | 71 | {{/html}} |