Browse Source

added diagonal word stroke

Shikiryu 4 years ago
parent
commit
26494ec902
4 changed files with 33 additions and 6 deletions
  1. 18
    2
      Gruntfile.js
  2. 2
    2
      dist/js/motsmeles.min.js
  3. 1
    0
      package.json
  4. 12
    2
      src/js/script.js

+ 18
- 2
Gruntfile.js View File

@@ -28,10 +28,24 @@ module.exports = function(grunt) {
28 28
                     {expand: true, cwd: 'src/', src: '*.html', dest: 'dist/', filter: 'isFile'},
29 29
                     {expand: true, cwd: 'vendor/', src: '*.min.js', dest: 'dist/js/', filter: 'isFile'}
30 30
                 ]
31
+            },
32
+            dev: {
33
+                files: [
34
+                    {expand: true, cwd: 'src/', src: '*.html', dest: 'dist/', filter: 'isFile'},
35
+                    {expand: true, cwd: 'vendor/', src: '*.min.js', dest: 'dist/js/', filter: 'isFile'},
36
+                    {expand: true, cwd: 'src/js/', src: '*.js', dest: 'dist/js/', filter: 'isFile'},
37
+                    {expand: true, cwd: 'src/css/', src: '*.js', dest: 'dist/js/', filter: 'isFile'}
38
+                ]
39
+            }
40
+        },
41
+        concat: {
42
+            dist: {
43
+                src: ['src/js/*.js'],
44
+                dest: 'dist/js/<%= pkg.name %>.min.js'
31 45
             }
32 46
         },
33 47
         clean: {
34
-            dist: ['dist/']
48
+            dist: ['dist/js','dist/css','index.html']
35 49
         }
36 50
     });
37 51
 
@@ -40,7 +54,9 @@ module.exports = function(grunt) {
40 54
     grunt.loadNpmTasks('grunt-contrib-jshint');
41 55
     grunt.loadNpmTasks('grunt-contrib-cssmin');
42 56
     grunt.loadNpmTasks('grunt-contrib-copy');
57
+    grunt.loadNpmTasks('grunt-contrib-concat');
43 58
 
44
-    grunt.registerTask('default', ['clean', 'jshint', 'uglify', 'cssmin', 'copy']);
59
+    grunt.registerTask('default', ['clean:dist', 'jshint', 'uglify', 'cssmin', 'copy:main']);
60
+    grunt.registerTask('dev', ['clean:dist', 'jshint', 'concat', 'copy:dev']);
45 61
 
46 62
 };

+ 2
- 2
dist/js/motsmeles.min.js
File diff suppressed because it is too large
View File


+ 1
- 0
package.json View File

@@ -5,6 +5,7 @@
5 5
   "author": "Shikiryu",
6 6
   "devDependencies": {
7 7
     "grunt-contrib-clean": "^0.6.0",
8
+    "grunt-contrib-concat": "^0.5.0",
8 9
     "grunt-contrib-copy": "^0.7.0",
9 10
     "grunt-contrib-cssmin": "^0.11.0",
10 11
     "grunt-contrib-jshint": "^0.11.0",

+ 12
- 2
src/js/script.js View File

@@ -33,6 +33,7 @@
33 33
 		var result = -1;
34 34
 		var isHorizontal = origin[0] === end[0];
35 35
 		var isVertical = origin[1] === end[1];
36
+		var isDiagonal = Math.abs(origin[0]-end[0]) === Math.abs(origin[1]-end[1]);
36 37
 		var x;
37 38
 		var first;
38 39
 		var last;
@@ -51,6 +52,15 @@
51 52
 				word += GRID[x][origin[1]];
52 53
 			}
53 54
 			return Math.max(words.indexOf(word), words.indexOf(word.split('').reverse().join('')));
55
+		} else if(isDiagonal) {
56
+			var xRight = origin[0] - end[0] < 0;
57
+			var yDown = origin[1] - end[1] < 0;
58
+			var i = 0;
59
+			var loopTime = Math.abs(origin[0]-end[0]);
60
+			for (;i<=loopTime;i++) {
61
+				word += GRID[xRight ? origin[0] + i : origin[0] - i][yDown ? origin[1] +i : origin[1] - i];
62
+			}
63
+			return Math.max(words.indexOf(word), words.indexOf(word.split('').reverse().join('')));
54 64
 		}
55 65
 		return result;
56 66
 	};
@@ -98,7 +108,7 @@
98 108
 		drawingLine = new fabric.Line(points, {
99 109
 					stroke: 'black',
100 110
 					strokeLineCap: 'round',
101
-					strokeWidth: SIZE/2,
111
+					strokeWidth: SIZE/6,
102 112
 					originX: 'center',
103 113
 					originY: 'center'
104 114
 				});
@@ -128,7 +138,7 @@
128 138
 				var line = new fabric.Line(lineCoord, {
129 139
 					stroke: 'black',
130 140
 					strokeLineCap: 'round',
131
-					strokeWidth: SIZE/2,
141
+					strokeWidth: SIZE/6,
132 142
 					originX: 'center',
133 143
 					originY: 'center',
134 144
 					selectable: false

Loading…
Cancel
Save