Browse Source

added diagonal word stroke

diagonal_detection
Shikiryu 7 years ago
parent
commit
26494ec902
  1. 20
      Gruntfile.js
  2. 4
      dist/js/motsmeles.min.js
  3. 1
      package.json
  4. 14
      src/js/script.js

20
Gruntfile.js

@ -28,10 +28,24 @@ module.exports = function(grunt) {
{expand: true, cwd: 'src/', src: '*.html', dest: 'dist/', filter: 'isFile'},
{expand: true, cwd: 'vendor/', src: '*.min.js', dest: 'dist/js/', filter: 'isFile'}
]
},
dev: {
files: [
{expand: true, cwd: 'src/', src: '*.html', dest: 'dist/', filter: 'isFile'},
{expand: true, cwd: 'vendor/', src: '*.min.js', dest: 'dist/js/', filter: 'isFile'},
{expand: true, cwd: 'src/js/', src: '*.js', dest: 'dist/js/', filter: 'isFile'},
{expand: true, cwd: 'src/css/', src: '*.js', dest: 'dist/js/', filter: 'isFile'}
]
}
},
concat: {
dist: {
src: ['src/js/*.js'],
dest: 'dist/js/<%= pkg.name %>.min.js'
}
},
clean: {
dist: ['dist/']
dist: ['dist/js','dist/css','index.html']
}
});
@ -40,7 +54,9 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.registerTask('default', ['clean', 'jshint', 'uglify', 'cssmin', 'copy']);
grunt.registerTask('default', ['clean:dist', 'jshint', 'uglify', 'cssmin', 'copy:main']);
grunt.registerTask('dev', ['clean:dist', 'jshint', 'concat', 'copy:dev']);
};

4
dist/js/motsmeles.min.js

File diff suppressed because one or more lines are too long

1
package.json

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

14
src/js/script.js

@ -33,6 +33,7 @@
var result = -1;
var isHorizontal = origin[0] === end[0];
var isVertical = origin[1] === end[1];
var isDiagonal = Math.abs(origin[0]-end[0]) === Math.abs(origin[1]-end[1]);
var x;
var first;
var last;
@ -51,6 +52,15 @@
word += GRID[x][origin[1]];
}
return Math.max(words.indexOf(word), words.indexOf(word.split('').reverse().join('')));
} else if(isDiagonal) {
var xRight = origin[0] - end[0] < 0;
var yDown = origin[1] - end[1] < 0;
var i = 0;
var loopTime = Math.abs(origin[0]-end[0]);
for (;i<=loopTime;i++) {
word += GRID[xRight ? origin[0] + i : origin[0] - i][yDown ? origin[1] +i : origin[1] - i];
}
return Math.max(words.indexOf(word), words.indexOf(word.split('').reverse().join('')));
}
return result;
};
@ -98,7 +108,7 @@
drawingLine = new fabric.Line(points, {
stroke: 'black',
strokeLineCap: 'round',
strokeWidth: SIZE/2,
strokeWidth: SIZE/6,
originX: 'center',
originY: 'center'
});
@ -128,7 +138,7 @@
var line = new fabric.Line(lineCoord, {
stroke: 'black',
strokeLineCap: 'round',
strokeWidth: SIZE/2,
strokeWidth: SIZE/6,
originX: 'center',
originY: 'center',
selectable: false

Loading…
Cancel
Save