File: theme_editor.html

package info (click to toggle)
hedgewars 0.9.17-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 174,720 kB
  • sloc: ansic: 120,489; pascal: 32,908; cpp: 15,824; python: 6,243; haskell: 2,984; xml: 1,173; sh: 679; objc: 327; makefile: 144; awk: 142; sed: 3
file content (159 lines) | stat: -rw-r--r-- 7,028 bytes parent folder | download | duplicates (3)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!doctype html>
<html>
    <head>
        <title>Hedgewars Theme Editor</title>
        <script type="text/javascript">
            var sky, clouds, horizont, water, land, border;
            var skyColor, waterTopColor, waterBottomColor;
            var elements = 7;
            var landArray;
            
            function landFunction(x){
                return 384 - 192 * Math.sin(x * Math.PI/512);
            }
            
            function tryToDraw(){
                if (--elements <= 0) {
                    draw();
                }
            }
        
            function load(){
                    var canvas = document.getElementById('preview');
                    if (canvas.getContext){
                        var ctx = canvas.getContext('2d');
                    
                        ctx.fillStyle = '#0b294b';
                        ctx.fillRect(0, 0, 512, 384);
                        
                        ctx.font = "40pt Arial";
                        ctx.fillStyle = '#2b7bd5';
                        ctx.fillText('Loading Images...', 32, 212);
                    }
                    
                    sky = new Image();
                    sky.onload = tryToDraw;
                    sky.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Themes/Nature/Sky.png';
          
                    clouds = new Image();
                    clouds.onload = tryToDraw;
                    clouds.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Graphics/Clouds.png';
          
                    horizont = new Image();
                    horizont.onload = tryToDraw;
                    horizont.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Themes/Nature/horizont.png';
          
                    land = new Image();
                    land.onload = tryToDraw;
                    land.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Themes/Nature/LandTex.png';
          
                    border = new Image();
                    border.onload = tryToDraw;
                    border.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Themes/Nature/Border.png';
          
                    water = new Image();
                    water.onload = tryToDraw;
                    water.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Graphics/BlueWater.png';
                    
                    landArray = new Array(512);
                    for (var x = 0; x < landArray.length; x++)
                        landArray[x] = landFunction(x);
                    
                    skyColor = '#131252';
                    document.getElementById('skyColor').value = skyColor;
                    
                    waterTopColor = '#555C9D';
                    document.getElementById('waterTopColor').value = waterTopColor;
                    
                    waterBottomColor = '#343C7D';
                    document.getElementById('waterBottomColor').value = waterBottomColor;
                    
                    tryToDraw();
            }
            
            function draw(){
                var canvas = document.getElementById('preview');
                if (canvas.getContext){
                    var ctx = canvas.getContext('2d');
                    
                    ctx.fillStyle = skyColor;
                    ctx.fillRect(0, 0, 512, 384);
                    
                    ctx.drawImage(sky, 0, 64, 512, 256);
          
                    for (var i = 0; i < 4; i++)
                        ctx.drawImage(clouds, 0, i * 128, 256, 128, i * 128, 64, 128, 64);
          
                    ctx.drawImage(horizont, 0, 192, 512, 128);
                    
                    ctx.save();
                    
                    ctx.beginPath();
                    ctx.moveTo(0, 384);
                    for (var x = 0; x < landArray.length; x++)
                        ctx.lineTo(x, landArray[x]);
                    ctx.clip();
                    
                    for (var i = 0; i < 2; i++)
                    	for (var k = 0; k < 2; k++)
                    		ctx.drawImage(land, i * 320, k * 240, 320, 240);
                    
                    ctx.restore();
                    
                    var k = 0;
                    for (var x = 0; x < landArray.length; x++) {
                        if (++k == 64)
                            k = 0;
                        ctx.drawImage(border, k, 0, 2, 16, x, landArray[x] - 4, 1, 8);
                    }
                        
                    
                    var gradient = ctx.createLinearGradient(0, 320, 0, 384);
                    gradient.addColorStop(0, waterTopColor);
                    gradient.addColorStop(1, waterBottomColor);
                    ctx.fillStyle = gradient;
                    ctx.fillRect(0, 320, 512, 384);
          
                    for (var i = 0; i < 8; i++)
                        ctx.drawImage(water, i * 64, 308, 64, 24);
                }
            }
        </script>
        <style type="text/css">
            canvas { border: 1px solid black; }
        </style>
    </head>
    <body onload="load();">
        <h1>Hedgewars Theme editor</h1>
        <canvas id="preview" width="512" height="384">Sorry, your browser does not support Canvas.</canvas><br>
        <table>
        <tr><td>Sky:</td><td>
        <input id="sky" type="file" accept="image/png" onchange="sky.src = window.URL.createObjectURL(this.files[0])"></input>
        </td></tr>
        <tr><td>Sky Color:</td><td>
        <input id="skyColor" type="color" onchange="skyColor = this.value; draw()"></input>
        </td></tr>
        <tr><td>Clouds:</td><td>
        <input id="clouds" type="file" accept="image/png" onchange="clouds.src = window.URL.createObjectURL(this.files[0])"></input>
        </td></tr>
        <tr><td>Horizont:</td><td>
        <input id="horizont" type="file" accept="image/png" onchange="horizont.src = window.URL.createObjectURL(this.files[0])"></input>
        </td></tr>
        <tr><td>Land:</td><td>
        <input id="land" type="file" accept="image/png" onchange="land.src = window.URL.createObjectURL(this.files[0])"></input>
        </td></tr>
        <tr><td>Border:</td><td>
        <input id="border" type="file" accept="image/png" onchange="border.src = window.URL.createObjectURL(this.files[0])"></input>
        </td></tr>
        <tr><td>Water:</td><td>
        <input id="water" type="file" accept="image/png" onchange="water.src = window.URL.createObjectURL(this.files[0])"></input>
        </td></tr>
        <tr><td>Water Top Color:</td><td>
        <input id="waterTopColor" type="color" onchange="waterTopColor = this.value; draw()"></input>
        </td></tr>
        <tr><td>Water Bottom Color:</td><td>
        <input id="waterBottomColor" type="color" onchange="waterBottomColor = this.value; draw()"></input>
        </td></tr>
        </table>
    </body>
</html>