├── LICENSE
├── README.md
├── TODO.md
├── build.sh
├── characters.coffee
├── css
├── isoblocks.css
└── style.css
├── index.html
├── isoblocks.coffee
└── js
├── characters.js
└── isoblocks.js
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | Copyright (c) 2012 Kushagra Gour
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
5 | and associated documentation files (the "Software"), to deal in the Software without restriction,
6 | including without limitation the rights to use, copy, modify, merge, publish, distribute,
7 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
14 | LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
15 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
16 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
17 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | IsoBlocks
2 | =========
3 |
4 | What is it?
5 | -----------
6 |
7 | IsoBlocks is an experimental library to create eye-candy isometric texts. It is written in **coffeescript**, uses **CSS3 transforms** for creating the cubes and **CSS3 transitions** for the animation.
8 |
9 | How to use
10 | -----
11 |
12 | To use the library, you need to include the following files:
13 | * js/characters.js
14 | * js/isoblocks.js
15 | * css/isoblocks.css
16 |
17 | Put the following in your HTML:
18 | ```
19 |
20 | ```
21 |
22 |
23 | Then in your code create an instance of **IsoBlocks** class and call the **generate** method to create the text you want:
24 |
25 | **NOTE:** IsoBlocks requires jQuery to be included before it.
26 |
27 | ```
28 | var iso = new IsoBlocks(400); // pass the number of blocks to pre-generate
29 | iso.generate('Your Text Here'); // By Default starts from lower left of the screen
30 | ```
31 |
32 | Position it:
33 | ```
34 | iso.generate('Your Text Here', {x: 320, y: 600});
35 | ```
36 |
37 | Colorize it (Presently supports- green, red, pink, blue, yellow only):
38 | ```
39 | iso.generate('Your Text Here', {x: 320, y: 600, colors: 'green'}); // Pass a color using 'colors' option
40 | ```
41 |
42 | Use multiple colors:
43 | ```
44 | iso.generate('Your Text Here', {x: 320, y: 600, colors: ['green', 'yellow']}); // Pass an array of colors in 'colors'
45 | ```
46 |
47 | Try it out
48 | ------------
49 | Demo: [http://kushagragour.in/lab/isoblocks/](http://kushagragour.in/lab/isoblocks/)
50 |
51 | [Works best in Google Chrome]
52 |
53 |
54 | License
55 | -------
56 |
57 | Licensed under The MIT License
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/TODO.md:
--------------------------------------------------------------------------------
1 | TODO List
2 | --------
3 |
4 | * Add numbers and some more special characters
5 | * Lowercase support
6 | * Multiple word support
7 | * Different font-sizes
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | coffee -b -o js/ -c *.coffee
4 |
--------------------------------------------------------------------------------
/characters.coffee:
--------------------------------------------------------------------------------
1 | ###
2 | characters.coffee
3 |
4 | version 1.0
5 | Author Kushagra Gour a.k.a. chinchang (chinchang457@gmail.com)
6 | Licensed under The MIT License
7 |
8 | Description:
9 | Defines the shape of characters. Has all static members.
10 | ###
11 |
12 | class Characters
13 | @a: [
14 | [1,1,1,1]
15 | [1,0,0,1]
16 | [1,1,1,1]
17 | [1,0,0,1]
18 | [1,0,0,1]
19 | ]
20 |
21 | @b: [
22 | [1,1,1,0]
23 | [1,0,1,0]
24 | [1,1,1,1]
25 | [1,0,0,1]
26 | [1,1,1,1]
27 | ]
28 |
29 | @c: [
30 | [1,1,1,1]
31 | [1,0,0,0]
32 | [1,0,0,0]
33 | [1,0,0,0]
34 | [1,1,1,1]
35 | ]
36 |
37 | @d: [
38 | [1,1,1,0]
39 | [1,0,0,1]
40 | [1,0,0,1]
41 | [1,0,0,1]
42 | [1,1,1,0]
43 | ]
44 |
45 | @e: [
46 | [1,1,1,1]
47 | [1,0,0,0]
48 | [1,1,1,0]
49 | [1,0,0,0]
50 | [1,1,1,1]
51 | ]
52 |
53 | @f: [
54 | [1,1,1,1]
55 | [1,0,0,0]
56 | [1,1,1,0]
57 | [1,0,0,0]
58 | [1,0,0,0]
59 | ]
60 |
61 | @g: [
62 | [1,1,1,1]
63 | [1,0,0,0]
64 | [1,0,1,1]
65 | [1,0,0,1]
66 | [1,1,1,1]
67 | ]
68 |
69 | @h: [
70 | [1,0,0,1]
71 | [1,0,0,1]
72 | [1,1,1,1]
73 | [1,0,0,1]
74 | [1,0,0,1]
75 | ]
76 |
77 | @i: [
78 | [1,1,1,1,1]
79 | [0,0,1,0,0]
80 | [0,0,1,0,0]
81 | [0,0,1,0,0]
82 | [1,1,1,1,1]
83 | ]
84 |
85 | @j: [
86 | [1,1,1,1,1]
87 | [0,0,1,0,0]
88 | [0,0,1,0,0]
89 | [1,0,1,0,0]
90 | [1,1,1,0,0]
91 | ]
92 |
93 | @k: [
94 | [1,0,0,1]
95 | [1,0,1,0]
96 | [1,1,0,0]
97 | [1,0,1,0]
98 | [1,0,0,1]
99 | ]
100 |
101 | @l: [
102 | [1,0,0,0]
103 | [1,0,0,0]
104 | [1,0,0,0]
105 | [1,0,0,0]
106 | [1,1,1,1]
107 | ]
108 |
109 | @m: [
110 | [1,0,0,0,1]
111 | [1,1,0,1,1]
112 | [1,0,1,0,1]
113 | [1,0,0,0,1]
114 | [1,0,0,0,1]
115 | ]
116 |
117 | @n: [
118 | [1,0,0,0,1]
119 | [1,1,0,0,1]
120 | [1,0,1,0,1]
121 | [1,0,0,1,1]
122 | [1,0,0,0,1]
123 | ]
124 |
125 | @o: [
126 | [1,1,1,1]
127 | [1,0,0,1]
128 | [1,0,0,1]
129 | [1,0,0,1]
130 | [1,1,1,1]
131 | ]
132 |
133 | @p: [
134 | [1,1,1,1]
135 | [1,0,0,1]
136 | [1,1,1,1]
137 | [1,0,0,0]
138 | [1,0,0,0]
139 | ]
140 |
141 | @q: [
142 | [0,1,1,1,0]
143 | [1,0,0,0,1]
144 | [1,0,1,0,1]
145 | [1,0,0,1,0]
146 | [0,1,1,0,1]
147 | ]
148 |
149 | @r: [
150 | [1,1,1,1]
151 | [1,0,0,1]
152 | [1,1,1,1]
153 | [1,0,1,0]
154 | [1,0,0,1]
155 | ]
156 |
157 | @s: [
158 | [0,1,1,1]
159 | [1,0,0,0]
160 | [1,1,1,1]
161 | [0,0,0,1]
162 | [1,1,1,0]
163 | ]
164 |
165 | @t: [
166 | [1,1,1,1,1]
167 | [0,0,1,0,0]
168 | [0,0,1,0,0]
169 | [0,0,1,0,0]
170 | [0,0,1,0,0]
171 | ]
172 |
173 | @u: [
174 | [1,0,0,1]
175 | [1,0,0,1]
176 | [1,0,0,1]
177 | [1,0,0,1]
178 | [1,1,1,1]
179 | ]
180 |
181 | @v: [
182 | [1,0,0,0,1]
183 | [1,0,0,0,1]
184 | [1,0,0,0,1]
185 | [0,1,0,1,0]
186 | [0,0,1,0,0]
187 | ]
188 |
189 | @w: [
190 | [1,0,0,0,1]
191 | [1,0,0,0,1]
192 | [1,0,1,0,1]
193 | [1,0,1,0,1]
194 | [1,1,1,1,1]
195 | ]
196 |
197 |
198 | @x: [
199 | [1,0,0,0,1]
200 | [0,1,0,1,0]
201 | [0,0,1,0,0]
202 | [0,1,0,1,0]
203 | [1,0,0,0,1]
204 | ]
205 |
206 | @y: [
207 | [1,0,0,0,1]
208 | [0,1,0,1,0]
209 | [0,0,1,0,0]
210 | [0,0,1,0,0]
211 | [0,0,1,0,0]
212 | ]
213 |
214 | @z: [
215 | [1,1,1,1,1]
216 | [0,0,0,1,0]
217 | [0,0,1,0,0]
218 | [0,1,0,0,0]
219 | [1,1,1,1,1]
220 | ]
221 |
222 | @fill: [
223 | [1,1,1,1,1]
224 | [1,1,1,1,1]
225 | [1,1,1,1,1]
226 | [1,1,1,1,1]
227 | [1,1,1,1,1]
228 | ]
229 |
230 | @exclamation: [
231 | [1]
232 | [1]
233 | [1]
234 | [0]
235 | [1]
236 | ]
237 |
238 | @question: [
239 | [0,1,1,1]
240 | [1,0,0,1]
241 | [0,0,1,0]
242 | [0,0,0,0]
243 | [0,0,1,0]
244 | ]
245 |
246 | @comma: [
247 | [0,0]
248 | [0,0]
249 | [0,0]
250 | [0,1]
251 | [1,0]
252 | ]
253 |
254 | @fullstop: [
255 | [0]
256 | [0]
257 | [0]
258 | [0]
259 | [1]
260 | ]
261 |
262 | @dash: [
263 | [0,0,0]
264 | [0,0,0]
265 | [1,1,1]
266 | [0,0,0]
267 | [0,0,0]
268 | ]
269 |
270 | @colon: [
271 | [0]
272 | [1]
273 | [0]
274 | [1]
275 | [0]
276 | ]
277 |
278 | @semicolon: [
279 | [0,0]
280 | [0,1]
281 | [0,0]
282 | [0,1]
283 | [1,0]
284 | ]
285 |
286 | @f_slash: [
287 | [0,0,0,0,1]
288 | [0,0,0,1,0]
289 | [0,0,1,0,0]
290 | [0,1,0,0,0]
291 | [1,0,0,0,0]
292 | ]
293 |
294 | @l_square_bracket: [
295 | [1,1,1]
296 | [1,0,0]
297 | [1,0,0]
298 | [1,0,0]
299 | [1,1,1]
300 | ]
301 |
302 | @r_square_bracket: [
303 | [1,1,1]
304 | [0,0,1]
305 | [0,0,1]
306 | [0,0,1]
307 | [1,1,1]
308 | ]
--------------------------------------------------------------------------------
/css/isoblocks.css:
--------------------------------------------------------------------------------
1 | .iso_block{
2 | position: absolute;
3 | height: 15px;
4 | width: 15px;
5 | background-color: #CCC;
6 | -webkit-transform: scaleY(0.5)rotate(-45deg);
7 | -moz-transform: scaleY(0.5)rotate(-45deg);
8 | -o-transform: scaleY(0.5)rotate(-45deg);
9 |
10 | -webkit-transition-property: top, left, opacity, background-color;
11 | -moz-transition-property: top, left, opacity, background-color;
12 | -o-transition-property: top, left, opacity, background-color;
13 |
14 | -webkit-transition-timing-function: ease;
15 | -moz-transition-timing-function: ease;
16 | -o-transition-timing-function: ease;
17 |
18 | -webkit-transition-duration: 500ms;
19 | -moz-transition-duration: 500ms;
20 | -o-transition-duration: 500ms;
21 | }
22 |
23 | .iso_block.move{
24 | margin-top: 132px;
25 | }
26 |
27 | .iso_block:before, .iso_block:after{
28 | content: '';
29 | position: absolute;
30 | height: 15px;
31 | width: 15px;
32 | }
33 |
34 | .iso_block:before{
35 | top: 9px;
36 | left: -16px;
37 | background-color: #AAA;
38 | -webkit-transform: skew(-15deg,-15deg)rotate(45deg)skewY(30deg)scale(1,1.3);
39 | -moz-transform: skew(-15deg,-15deg)rotate(45deg)skewY(30deg)scale(1,1.3);
40 | -o-transform: skew(-15deg,-15deg)rotate(45deg)skewY(30deg)scale(1,1.3);
41 | }
42 |
43 | .iso_block:after{
44 | top: 16px;
45 | left: -9px;
46 | background-color: #888;
47 | -webkit-transform: skew(-15deg,-15deg)rotate(45deg)skewY(-30deg)scale(1,1.3);
48 | -moz-transform: skew(-15deg,-15deg)rotate(45deg)skewY(-30deg)scale(1,1.3);
49 | -o-transform: skew(-15deg,-15deg)rotate(45deg)skewY(-30deg)scale(1,1.3);
50 | }
51 |
52 | /* Color schemes */
53 | .iso_block.iso_color_yellow { background-color: #FAE163; }
54 | .iso_block.iso_color_yellow:before { background-color: #f8d421; }
55 | .iso_block.iso_color_yellow:after { background-color: #cfad07; }
56 |
57 | .iso_block.iso_color_green { background-color: #6ec276; }
58 | .iso_block.iso_color_green:before { background-color: #4bb255; }
59 | .iso_block.iso_color_green:after { background-color: #2d6a33; }
60 |
61 | .iso_block.iso_color_pink { background-color: #f1708c; }
62 | .iso_block.iso_color_pink:before { background-color: #ee5173; }
63 | .iso_block.iso_color_pink:after { background-color: #e9234e; }
64 |
65 | .iso_block.iso_color_red { background-color: #f33; }
66 | .iso_block.iso_color_red:before { background-color: #f00; }
67 | .iso_block.iso_color_red:after { background-color: #b00; }
68 |
69 | .iso_block.iso_color_blue { background-color: #00a7e0; }
70 | .iso_block.iso_color_blue:before { background-color: #008dbe; }
71 | .iso_block.iso_color_blue:after { background-color: #00749C; }
72 |
73 |
74 | .iso_block.unused{
75 | opacity: 0;
76 | }
77 |
--------------------------------------------------------------------------------
/css/style.css:
--------------------------------------------------------------------------------
1 | .hidden{
2 | display: none;
3 | }
4 |
5 | body{
6 | background: #EEE -webkit-radial-gradient(50% 70%,cover,rgba(255, 255, 255, 0.65) 0,rgba(255, 255, 255, 0) 82%);
7 | background: #EEE -moz-radial-gradient(50% 70%,cover,rgba(255, 255, 255, 0.65) 0,rgba(255, 255, 255, 0) 82%);
8 | background: #EEE -o-radial-gradient(50% 70%,cover,rgba(255, 255, 255, 0.65) 0,rgba(255, 255, 255, 0) 82%);
9 | background: #EEE -ms-radial-gradient(50% 70%,cover,rgba(255, 255, 255, 0.65) 0,rgba(255, 255, 255, 0) 82%);
10 | font-family: Arial;
11 | min-height: 600px;
12 | }
13 |
14 |
15 | input{
16 | border: 1px solid #CCC;
17 | padding: 5px;
18 | outline: none;
19 | border-radius: 3px;
20 | font-size: 30px;
21 | color: #888;
22 | }
23 |
24 | p{
25 | font-size: 12px;
26 | }
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ISO-BLOCKS - An eye-candy CSS3 isometric text library.
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | ISOBLOCKS
17 | Created by Kushagra Gour .
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | Green
46 | Yellow
47 | Pink
48 | Red
49 | Blue
50 |
51 |
52 | [Works best in Chrome]
53 |
54 |
55 |
56 |
57 | More cool experiments!
58 |
59 |
60 |
61 |
62 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/isoblocks.coffee:
--------------------------------------------------------------------------------
1 | ###
2 | isoblocks.coffee
3 |
4 | version 1.0
5 | Author Kushagra Gour a.k.a. chinchang (chinchang457@gmail.com)
6 | Licensed under The MIT License
7 |
8 | Description:
9 | IsoBlocks is a library to create eye candy isometric texts.
10 |
11 | Usage:
12 |
13 | var iso = new IsoBlocks(400); // pass the number of blocks to pre-generate
14 | iso.generate('Your Text Here'); // By Default starts from the lower left of the screen
15 |
16 | Position it:
17 | iso.generate('Your Text Here', {x: 320, y: 600});
18 |
19 | Colorize it (Presently supports- green, red, pink, blue, yellow only):
20 | iso.generate('Your Text Here', {x: 320, y: 600, colors: 'green'}); // Pass a color using 'colors' option
21 |
22 | Use multiple colors:
23 | iso.generate('Your Text Here', {x: 320, y: 600, colors: ['green', 'yellow']}); // Pass an array of colors in 'colors'
24 |
25 | ###
26 |
27 | $(->
28 | $('#iso_input').bind 'keydown', onKeyPress
29 | )
30 |
31 | onKeyPress = (e) ->
32 | if e.key is 13 or e.keyCode is 13
33 | if iso then iso.generate $(e.target).val(), {x: 320, y: 500, colors: $("input[name=color]:checked").map( -> return this.value; ).get()}
34 |
35 | ###
36 | Cube class
37 | ###
38 | class Cube
39 | constructor: ->
40 |
41 | @width: 15
42 | @height: 15
43 |
44 |
45 | ###
46 | IsoBlocks class
47 | ###
48 | class IsoBlocks
49 |
50 | # Array of pre-generated cubes which are used throughout.
51 | cubes: []
52 |
53 | # Current cube index in the @cubes array to be used for drawing
54 | current_cube_index: 0
55 |
56 | # An HTML string template for a block
57 | cube_template: '
'
58 |
59 | # Default Configuration Object
60 | default_config: {}
61 |
62 | # Current Configuration Object
63 | config: {}
64 |
65 | ###
66 | Constructor
67 | @param num_cubes Number Number of cubes to pre-generate. Default is 450.
68 | ###
69 | constructor: (num_cubes = 450) ->
70 | @default_config =
71 | # Colors to use for the text blocks
72 | colors: []
73 |
74 | # Starting x cordinate on the screen
75 | x: 30
76 |
77 | # Starting y cordinate on the screen
78 | y: window.innerHeight - 100
79 |
80 | # Spacing between 2 characters in terms of number of blocks. Default is 1.
81 | character_spacing: 1
82 |
83 | @preGenerateCubes num_cubes
84 |
85 | ###
86 | @params s string String to draw
87 | @param config Object Configuration object.
88 | ###
89 | generate: (s, config = {}) ->
90 | $.extend @config, @default_config, config
91 | colors = []
92 | # Append iso_color prefix to colors
93 | if config.colors
94 | if typeof config.colors is 'string'
95 | config.colors = [config.colors]
96 | colors = (color.toLowerCase().replace(/^/,' iso_color_') for color in config.colors)
97 | @config.colors = colors
98 |
99 | # Initialize the @current_cube_index to start using the cubes from end for current string
100 | @current_cube_index = @cubes.length - 1
101 |
102 | # Hide all cubes
103 | for cube in @cubes
104 | $(cube).addClass('unused')
105 |
106 | current_row = 0
107 | current_col = 0
108 |
109 | # Loop throught the characters and keep drawing them
110 | for ch, index in s
111 | current_col += @drawCharacter ch, current_row, current_col
112 |
113 | # Give some space between 2 characters
114 | current_col += @config.character_spacing
115 |
116 | ###
117 | It draws a character at given row and column
118 | Returns the width of the character in number of blocks
119 | @param ch String A character to draw
120 | @param row Number Current character's row
121 | @param col Number Current character's column
122 | ###
123 | drawCharacter: (ch, row, col) ->
124 | # Lowercase the character
125 | ch = ch.toLowerCase()
126 |
127 | # Handle special characters
128 | if ch is ' ' then return 1
129 | else if ch is '#' then ch = 'fill'
130 | else if ch is '!' then ch = 'exclamation'
131 | else if ch is '?' then ch = 'question'
132 | else if ch is '.' then ch = 'fullstop'
133 | else if ch is ',' then ch = 'comma'
134 | else if ch is '-' then ch = 'dash'
135 | else if ch is ';' then ch = 'semicolon'
136 | else if ch is ':' then ch = 'colon'
137 | else if ch is '/' then ch = 'f_slash'
138 | else if ch is '[' then ch = 'l_square_bracket'
139 | else if ch is ']' then ch = 'r_square_bracket'
140 |
141 | # Skip if character matrix not found
142 | if not current_ch = Characters[ch] then return 0
143 | for arr, i in current_ch
144 | for val, j in arr
145 | if val
146 | # Calulate isometric position of the cube
147 | pos_x = (row+i+col+j) * Cube.width * 0.8 + @config.x
148 | pos_y = (row+i-(col+j)) * Cube.height / 2 * 0.8 + @config.y
149 |
150 | # Calculate z-index according to the cube's position
151 | z = parseInt 100 * pos_y - 40 * pos_x + 2000, 10
152 |
153 | ###
154 | If its not the first time, we have already generated cubes.
155 | So no need of dom manipulation again and again.
156 | Else if we do not have some cubes, we generate them. This happens for the first time only.
157 | ###
158 | if @current_cube_index >= 0
159 | cube = @cubes[@current_cube_index]
160 | cube.style.left = pos_x + 'px'
161 | cube.style.top = pos_y + 'px'
162 | # Remove previous color class, pick a new random color class and add it
163 | class_string = $(cube).attr 'class'
164 | class_string = class_string.replace(/iso_color_\w+/g, '')
165 | if @config.colors.length
166 | new_color = @config.colors[Math.floor Math.random() * @config.colors.length]
167 | class_string = class_string.concat(" #{new_color}")
168 | $(cube).removeClass().addClass class_string
169 | cube.style.zIndex = z
170 | $(cube).removeClass 'unused'
171 | @current_cube_index--
172 | else
173 | console.warn 'Cubes got Over!'
174 | return
175 | # Return the character width
176 | current_ch[0].length
177 |
178 | ###
179 | @param cube_count Number Number of cubes to pre-generate
180 | ###
181 | preGenerateCubes: (cube_count) ->
182 | html_string = ''
183 | for i in [1...cube_count]
184 | current_cube = @cube_template
185 |
186 | current_cube = current_cube.replace '@left', (150 + Math.random() * (window.screen.width-400))
187 | current_cube = current_cube.replace '@top', (200 + Math.random() * (window.screen.height - 500))
188 | html_string += current_cube
189 |
190 | # Insert the cubes into the DOM. Uses innerHTML for faster DOM Insertion.
191 | if html_string then $('#iso_container').get(0).innerHTML += html_string
192 |
193 | # Get the cube references
194 | @cubes = document.getElementsByClassName('iso_block')
195 |
196 | # IsoBlocks end
--------------------------------------------------------------------------------
/js/characters.js:
--------------------------------------------------------------------------------
1 | /*
2 | characters.coffee
3 |
4 | version 1.0
5 | Author Kushagra Gour a.k.a. chinchang (chinchang457@gmail.com)
6 | Licensed under The MIT License
7 |
8 | Description:
9 | Defines the shape of characters. Has all static members.
10 | */
11 | var Characters;
12 |
13 | Characters = (function() {
14 |
15 | function Characters() {}
16 |
17 | Characters.a = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1]];
18 |
19 | Characters.b = [[1, 1, 1, 0], [1, 0, 1, 0], [1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 1, 1]];
20 |
21 | Characters.c = [[1, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 1, 1, 1]];
22 |
23 | Characters.d = [[1, 1, 1, 0], [1, 0, 0, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 0]];
24 |
25 | Characters.e = [[1, 1, 1, 1], [1, 0, 0, 0], [1, 1, 1, 0], [1, 0, 0, 0], [1, 1, 1, 1]];
26 |
27 | Characters.f = [[1, 1, 1, 1], [1, 0, 0, 0], [1, 1, 1, 0], [1, 0, 0, 0], [1, 0, 0, 0]];
28 |
29 | Characters.g = [[1, 1, 1, 1], [1, 0, 0, 0], [1, 0, 1, 1], [1, 0, 0, 1], [1, 1, 1, 1]];
30 |
31 | Characters.h = [[1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1]];
32 |
33 | Characters.i = [[1, 1, 1, 1, 1], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [1, 1, 1, 1, 1]];
34 |
35 | Characters.j = [[1, 1, 1, 1, 1], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [1, 0, 1, 0, 0], [1, 1, 1, 0, 0]];
36 |
37 | Characters.k = [[1, 0, 0, 1], [1, 0, 1, 0], [1, 1, 0, 0], [1, 0, 1, 0], [1, 0, 0, 1]];
38 |
39 | Characters.l = [[1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 1, 1, 1]];
40 |
41 | Characters.m = [[1, 0, 0, 0, 1], [1, 1, 0, 1, 1], [1, 0, 1, 0, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1]];
42 |
43 | Characters.n = [[1, 0, 0, 0, 1], [1, 1, 0, 0, 1], [1, 0, 1, 0, 1], [1, 0, 0, 1, 1], [1, 0, 0, 0, 1]];
44 |
45 | Characters.o = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 1]];
46 |
47 | Characters.p = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0]];
48 |
49 | Characters.q = [[0, 1, 1, 1, 0], [1, 0, 0, 0, 1], [1, 0, 1, 0, 1], [1, 0, 0, 1, 0], [0, 1, 1, 0, 1]];
50 |
51 | Characters.r = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 1, 1], [1, 0, 1, 0], [1, 0, 0, 1]];
52 |
53 | Characters.s = [[0, 1, 1, 1], [1, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 1], [1, 1, 1, 0]];
54 |
55 | Characters.t = [[1, 1, 1, 1, 1], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0]];
56 |
57 | Characters.u = [[1, 0, 0, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 1]];
58 |
59 | Characters.v = [[1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0]];
60 |
61 | Characters.w = [[1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 0, 1, 0, 1], [1, 0, 1, 0, 1], [1, 1, 1, 1, 1]];
62 |
63 | Characters.x = [[1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 0, 0, 1]];
64 |
65 | Characters.y = [[1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0]];
66 |
67 | Characters.z = [[1, 1, 1, 1, 1], [0, 0, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 0, 0, 0], [1, 1, 1, 1, 1]];
68 |
69 | Characters.fill = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]];
70 |
71 | Characters.exclamation = [[1], [1], [1], [0], [1]];
72 |
73 | Characters.question = [[0, 1, 1, 1], [1, 0, 0, 1], [0, 0, 1, 0], [0, 0, 0, 0], [0, 0, 1, 0]];
74 |
75 | Characters.comma = [[0, 0], [0, 0], [0, 0], [0, 1], [1, 0]];
76 |
77 | Characters.fullstop = [[0], [0], [0], [0], [1]];
78 |
79 | Characters.dash = [[0, 0, 0], [0, 0, 0], [1, 1, 1], [0, 0, 0], [0, 0, 0]];
80 |
81 | Characters.colon = [[0], [1], [0], [1], [0]];
82 |
83 | Characters.semicolon = [[0, 0], [0, 1], [0, 0], [0, 1], [1, 0]];
84 |
85 | Characters.f_slash = [[0, 0, 0, 0, 1], [0, 0, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 0, 0, 0], [1, 0, 0, 0, 0]];
86 |
87 | Characters.l_square_bracket = [[1, 1, 1], [1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 1, 1]];
88 |
89 | Characters.r_square_bracket = [[1, 1, 1], [0, 0, 1], [0, 0, 1], [0, 0, 1], [1, 1, 1]];
90 |
91 | return Characters;
92 |
93 | })();
94 |
--------------------------------------------------------------------------------
/js/isoblocks.js:
--------------------------------------------------------------------------------
1 | /*
2 | isoblocks.coffee
3 |
4 | version 1.0
5 | Author Kushagra Gour a.k.a. chinchang (chinchang457@gmail.com)
6 | Licensed under The MIT License
7 |
8 | Description:
9 | IsoBlocks is a library to create eye candy isometric texts.
10 |
11 | Usage:
12 |
13 | var iso = new IsoBlocks(400); // pass the number of blocks to pre-generate
14 | iso.generate('Your Text Here'); // By Default starts from the lower left of the screen
15 |
16 | Position it:
17 | iso.generate('Your Text Here', {x: 320, y: 600});
18 |
19 | Colorize it (Presently supports- green, red, pink, blue, yellow only):
20 | iso.generate('Your Text Here', {x: 320, y: 600, colors: 'green'}); // Pass a color using 'colors' option
21 |
22 | Use multiple colors:
23 | iso.generate('Your Text Here', {x: 320, y: 600, colors: ['green', 'yellow']}); // Pass an array of colors in 'colors'
24 | */
25 | var Cube, IsoBlocks, onKeyPress;
26 |
27 | $(function() {
28 | return $('#iso_input').bind('keydown', onKeyPress);
29 | });
30 |
31 | onKeyPress = function(e) {
32 | if (e.key === 13 || e.keyCode === 13) {
33 | if (iso) {
34 | return iso.generate($(e.target).val(), {
35 | x: 320,
36 | y: 500,
37 | colors: $("input[name=color]:checked").map(function() {
38 | return this.value;
39 | }).get()
40 | });
41 | }
42 | }
43 | };
44 |
45 | /*
46 | Cube class
47 | */
48 |
49 | Cube = (function() {
50 |
51 | function Cube() {}
52 |
53 | Cube.width = 15;
54 |
55 | Cube.height = 15;
56 |
57 | return Cube;
58 |
59 | })();
60 |
61 | /*
62 | IsoBlocks class
63 | */
64 |
65 | IsoBlocks = (function() {
66 |
67 | IsoBlocks.prototype.cubes = [];
68 |
69 | IsoBlocks.prototype.current_cube_index = 0;
70 |
71 | IsoBlocks.prototype.cube_template = '
';
72 |
73 | IsoBlocks.prototype.default_config = {};
74 |
75 | IsoBlocks.prototype.config = {};
76 |
77 | /*
78 | Constructor
79 | @param num_cubes Number Number of cubes to pre-generate. Default is 450.
80 | */
81 |
82 | function IsoBlocks(num_cubes) {
83 | if (num_cubes == null) num_cubes = 450;
84 | this.default_config = {
85 | colors: [],
86 | x: 30,
87 | y: window.innerHeight - 100,
88 | character_spacing: 1
89 | };
90 | this.preGenerateCubes(num_cubes);
91 | }
92 |
93 | /*
94 | @params s string String to draw
95 | @param config Object Configuration object.
96 | */
97 |
98 | IsoBlocks.prototype.generate = function(s, config) {
99 | var ch, color, colors, cube, current_col, current_row, index, _i, _len, _len2, _ref, _results;
100 | if (config == null) config = {};
101 | $.extend(this.config, this.default_config, config);
102 | colors = [];
103 | if (config.colors) {
104 | if (typeof config.colors === 'string') config.colors = [config.colors];
105 | colors = (function() {
106 | var _i, _len, _ref, _results;
107 | _ref = config.colors;
108 | _results = [];
109 | for (_i = 0, _len = _ref.length; _i < _len; _i++) {
110 | color = _ref[_i];
111 | _results.push(color.toLowerCase().replace(/^/, ' iso_color_'));
112 | }
113 | return _results;
114 | })();
115 | this.config.colors = colors;
116 | }
117 | this.current_cube_index = this.cubes.length - 1;
118 | _ref = this.cubes;
119 | for (_i = 0, _len = _ref.length; _i < _len; _i++) {
120 | cube = _ref[_i];
121 | $(cube).addClass('unused');
122 | }
123 | current_row = 0;
124 | current_col = 0;
125 | _results = [];
126 | for (index = 0, _len2 = s.length; index < _len2; index++) {
127 | ch = s[index];
128 | current_col += this.drawCharacter(ch, current_row, current_col);
129 | _results.push(current_col += this.config.character_spacing);
130 | }
131 | return _results;
132 | };
133 |
134 | /*
135 | It draws a character at given row and column
136 | Returns the width of the character in number of blocks
137 | @param ch String A character to draw
138 | @param row Number Current character's row
139 | @param col Number Current character's column
140 | */
141 |
142 | IsoBlocks.prototype.drawCharacter = function(ch, row, col) {
143 | var arr, class_string, cube, current_ch, i, j, new_color, pos_x, pos_y, val, z, _len, _len2;
144 | ch = ch.toLowerCase();
145 | if (ch === ' ') {
146 | return 1;
147 | } else if (ch === '#') {
148 | ch = 'fill';
149 | } else if (ch === '!') {
150 | ch = 'exclamation';
151 | } else if (ch === '?') {
152 | ch = 'question';
153 | } else if (ch === '.') {
154 | ch = 'fullstop';
155 | } else if (ch === ',') {
156 | ch = 'comma';
157 | } else if (ch === '-') {
158 | ch = 'dash';
159 | } else if (ch === ';') {
160 | ch = 'semicolon';
161 | } else if (ch === ':') {
162 | ch = 'colon';
163 | } else if (ch === '/') {
164 | ch = 'f_slash';
165 | } else if (ch === '[') {
166 | ch = 'l_square_bracket';
167 | } else if (ch === ']') {
168 | ch = 'r_square_bracket';
169 | }
170 | if (!(current_ch = Characters[ch])) return 0;
171 | for (i = 0, _len = current_ch.length; i < _len; i++) {
172 | arr = current_ch[i];
173 | for (j = 0, _len2 = arr.length; j < _len2; j++) {
174 | val = arr[j];
175 | if (val) {
176 | pos_x = (row + i + col + j) * Cube.width * 0.8 + this.config.x;
177 | pos_y = (row + i - (col + j)) * Cube.height / 2 * 0.8 + this.config.y;
178 | z = parseInt(100 * pos_y - 40 * pos_x + 2000, 10);
179 | /*
180 | If its not the first time, we have already generated cubes.
181 | So no need of dom manipulation again and again.
182 | Else if we do not have some cubes, we generate them. This happens for the first time only.
183 | */
184 | if (this.current_cube_index >= 0) {
185 | cube = this.cubes[this.current_cube_index];
186 | cube.style.left = pos_x + 'px';
187 | cube.style.top = pos_y + 'px';
188 | class_string = $(cube).attr('class');
189 | class_string = class_string.replace(/iso_color_\w+/g, '');
190 | if (this.config.colors.length) {
191 | new_color = this.config.colors[Math.floor(Math.random() * this.config.colors.length)];
192 | class_string = class_string.concat(" " + new_color);
193 | }
194 | $(cube).removeClass().addClass(class_string);
195 | cube.style.zIndex = z;
196 | $(cube).removeClass('unused');
197 | this.current_cube_index--;
198 | } else {
199 | console.warn('Cubes got Over!');
200 | return;
201 | }
202 | }
203 | }
204 | }
205 | return current_ch[0].length;
206 | };
207 |
208 | /*
209 | @param cube_count Number Number of cubes to pre-generate
210 | */
211 |
212 | IsoBlocks.prototype.preGenerateCubes = function(cube_count) {
213 | var current_cube, html_string, i;
214 | html_string = '';
215 | for (i = 1; 1 <= cube_count ? i < cube_count : i > cube_count; 1 <= cube_count ? i++ : i--) {
216 | current_cube = this.cube_template;
217 | current_cube = current_cube.replace('@left', 150 + Math.random() * (window.screen.width - 400));
218 | current_cube = current_cube.replace('@top', 200 + Math.random() * (window.screen.height - 500));
219 | html_string += current_cube;
220 | }
221 | if (html_string) $('#iso_container').get(0).innerHTML += html_string;
222 | return this.cubes = document.getElementsByClassName('iso_block');
223 | };
224 |
225 | return IsoBlocks;
226 |
227 | })();
228 |
--------------------------------------------------------------------------------