Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moneppo's assignment #14

Open
wants to merge 4 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,23 @@ module.exports = function(grunt) {
'!node_modules/**/*'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you've found the Gruntfile, mind excluding Zepto and any other 3rd-party libraries from linting? Will make the Travis output more intelligible.

]
}
},
'http-server': {
'dev': {
root: '.',
port: 3000,
host: "127.0.0.1",
cache: 1,
showDir : true,
autoIndex: true,
ext: "html"
}
}
});

grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-html-validation');
grunt.loadNpmTasks('grunt-http-server');

grunt.registerTask('default', ['jshint', 'validation']);
};
Binary file added images/.DS_Store
Binary file not shown.
Binary file added images/arm.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/head.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img-1all.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img-1none.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img-2all.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img-2none.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img0-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img0-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img0all.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img0none.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img1-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img1all.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img1none.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img2-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img2all.jpeg
Binary file added images/img2none.jpeg
Binary file added images/img3-1.png
Binary file added images/img3-2.png
Binary file added images/img30.png
Binary file added images/img31.png
Binary file added images/img32.png
Binary file added images/img4-1.png
Binary file added images/img4-2.png
Binary file added images/img40.png
Binary file added images/img41.png
Binary file added images/img42.png
Binary file added images/leg.jpeg
Binary file added images/pixlr0.pxd
Binary file not shown.
Binary file added images/pxlr-1.pxd
Binary file not shown.
Binary file added images/pxlr1.pxd
Binary file not shown.
Binary file added images/pxlr2.pxd
Binary file not shown.
18 changes: 18 additions & 0 deletions index copy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>moneppo's Instructional Assignment</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<canvas id="canvas" width="400" height="400"></canvas>
<img class="part head" src="images/head.jpeg"></img>
<img class="part arm" src="images/arm.jpeg"></img>
<img class="part arm" src="images/arm.jpeg"></img>
<img class="part leg" src="images/leg.jpeg"></img>
<img class="part leg" src="images/leg.jpeg"></img>
<script src="zepto.min.js"></script>
<script src="zepto.dragdrop.min.js"></script>
<script src="index.js"></script>
</body>
</html>
13 changes: 11 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>So-and-so's Instructional Assignment</title>
<title>moneppo's Instructional Assignment</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
YOUR CODE HERE
<canvas id="canvas" width="400" height="400"></canvas>
<img class="part head" src="images/head.jpeg"></img>
<img class="part arm" src="images/arm.jpeg"></img>
<img class="part arm" src="images/arm.jpeg"></img>
<img class="part leg" src="images/leg.jpeg"></img>
<img class="part leg" src="images/leg.jpeg"></img>
<script src="zepto.js"></script>
<script src="zepto.dragdrop.js"></script>
<script src="index.js"></script>
</body>
</html>
106 changes: 106 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
Zepto(function($){
var $canvas = $('#canvas');
var $parts = $('.part');
var ctx = $canvas[0].getContext('2d');

var none = [];
var parts = [];

var attached = [false,false,false,false,false];

var bucket = 0;
function draw() {
ctx.drawImage(none[bucket], 0, 0);
for (var i = 0; i < attached.length;i++) {
if (attached[i]) {
ctx.drawImage(parts[i][bucket], 0,0);
}
}
}

function mouseMove(e) {
var x = (e.pageX - $canvas.offset().left) / $canvas.width();
bucket = Math.floor(x * 5) - 2;
if (bucket < -2) bucket = -2;
if (bucket > 2) bucket = 2;
draw();
}

function loadImages(update, then) {
var count = 0;
var totalImages = 30;

function imageLoaded() {
count++;
update(count / totalImages);
if (count == totalImages) {
then();
}
}

// Load backgrounds
for (var p = -2; p <= 2; p++) {
var filename = 'images/img' + p + 'none.jpeg';
var img = new Image();
none[p] = img;
img.onload = imageLoaded;
img.src = filename;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a descriptive comment for a section of code like this is usually a sign to move it into a helpfully-named function 😉


for (var i = 0; i < 5; i++) {
parts[i] = [];
for (var p = -2; p <= 2; p++) {
var filename = 'images/img' + i + p + '.png';
var img = new Image();
parts[i][p] = img;
img.onload = imageLoaded;
img.src = filename;
}
}
}

loadImages(
function(amount) {

},
function() {
$canvas.on('mousemove', mouseMove);
draw();

$parts.draggable({
start: function () {
this.css('-webkit-transform', 'scale(2)');
},
stop: function () {
this.css('-webkit-transform', 'scale(1)');
}
});

$canvas.droppable({
drop: function (e, dragEl, dropEl) {
if(dragEl.hasClass('head')) {
attached[0] = true;
}

if(dragEl.hasClass('arm')) {
if (attached[1]) {
attached[2] = true;
} else attached[1] = true;
}

if(dragEl.hasClass('leg')) {
if (attached[3]) {
attached[4] = true;
} else attached[3] = true;
}

dragEl.hide();
draw();

return true;
}
});
}
);
});

17 changes: 17 additions & 0 deletions main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#canvas {
padding-left: 0;
padding-right: 0;
padding-top: 5%;
margin-left: auto;
margin-right: auto;
display: block;
width: 400px;
}

body {
background-color: #AAA;
}

.part {
float: left;
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"devDependencies": {
"grunt": "^0.4.4",
"grunt-contrib-jshint": "^0.10.0",
"grunt-html-validation": "^0.1.15"
"grunt-html-validation": "^0.1.15",
"grunt-http-server": "~1.0.0"
}
}
Loading