-
Notifications
You must be signed in to change notification settings - Fork 12
Dean's branch #2
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
Open
dravida1
wants to merge
2
commits into
drguthals:master
Choose a base branch
from
dravida1:Dean's-Branch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,7 +62,7 @@ <h1>CSE 190 Blockly Playground: Project 3</h1> | |
| <div style="background-color: #FFFFFF; float: left; width: 49%; height: 800px"> | ||
| <div style="height:53%;width:98%;outline-style: solid;outline-width: 1px;text-align:center;margin-left:5px;margin-top:5px;"> | ||
| <div style="position:absolute;z-index:4;width:45%;height:37%"> | ||
| <canvas id="catAnimation"></canvas> | ||
| <canvas id="spriteAnimation"></canvas> | ||
| </div> | ||
| </div> | ||
| <hr> | ||
|
|
@@ -79,6 +79,17 @@ <h1>CSE 190 Blockly Playground: Project 3</h1> | |
| <img src="images/cat3_numbered.png" style="margin-left:5px;margin-top:5px;outline-style: solid;outline-width: 1px;height:180px;" /> | ||
| </td> | ||
| </tr> | ||
| <tr> | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tests |
||
| <td> | ||
| <img src="images/dog1_numbered.png" style="margin-left:5px;margin-top:5px;outline-style: solid;outline-width: 1px;height:180px;" /> | ||
| </td> | ||
| <td> | ||
| <img src="images/dog2_numbered.png" style="margin-left:5px;margin-top:5px;outline-style: solid;outline-width: 1px;height:180px;" /> | ||
| </td> | ||
| <td> | ||
| <img src="images/dog3_numbered.png" style="margin-left:5px;margin-top:5px;outline-style: solid;outline-width: 1px;height:180px;" /> | ||
| </td> | ||
| </tr> | ||
| </table> | ||
| </div> | ||
| </div> | ||
|
|
@@ -97,10 +108,17 @@ <h1>CSE 190 Blockly Playground: Project 3</h1> | |
| <block type="whenrunclicked"></block> | ||
| <block type="clearscreen"></block> | ||
| </category> | ||
| <category name="cats" colour="175"> | ||
| <block type="catpose"></block> | ||
|
|
||
| <category name="Animals" colour="175"> | ||
| <block type="animalSay"></block> | ||
| <category name="cats" colour="175"> | ||
| <block type="catpose"></block> | ||
| </category> | ||
| <category name="dogs" colour="175"> | ||
| <block type="dogpose"></block> | ||
| </category> | ||
| </category> | ||
|
|
||
| <sep></sep> | ||
|
|
||
| <category name="Logic" colour="210"> | ||
|
|
@@ -139,11 +157,11 @@ <h1>CSE 190 Blockly Playground: Project 3</h1> | |
| /******************** | ||
| * Setup the Canvas * | ||
| ********************/ | ||
| var canvas = document.getElementById("catAnimation"); | ||
| var canvas = document.getElementById("spriteAnimation"); | ||
| canvas.width = 480; | ||
| canvas.height = 480; | ||
|
|
||
| var ctx = document.getElementById('catAnimation').getContext('2d'); | ||
| var ctx = document.getElementById('spriteAnimation').getContext('2d'); | ||
|
|
||
| var animation = true; | ||
|
|
||
|
|
@@ -186,21 +204,48 @@ <h1>CSE 190 Blockly Playground: Project 3</h1> | |
|
|
||
| var cat1 = sprite({ | ||
| context: canvas.getContext("2d"), | ||
| width: 500, | ||
| width: 250, | ||
| height: 500, | ||
| image: catImage, | ||
| x: 0, | ||
| y: 0 | ||
| }); | ||
|
|
||
| /******************** | ||
| * Defining the dog * | ||
| ********************/ | ||
| var dogImage = new Image(); | ||
| dogImage.src = "images/dog1.png"; | ||
|
|
||
| var dog1 = sprite({ | ||
| context: canvas.getContext("2d"), | ||
| width: 250, | ||
| height: 500, | ||
| image: dogImage, | ||
| x: 250, | ||
| y: 0 | ||
| }); | ||
|
|
||
| /****************** | ||
| * Show the cat * | ||
| ******************/ | ||
| cat1.render(); | ||
| cat1.render(); | ||
|
|
||
| /****************** | ||
| * Show the dog * | ||
| *******************/ | ||
| dog1.render(); | ||
|
|
||
| var indexToArrays = 0; | ||
| var numOfInstructions = 0; | ||
| var arrayOfPoses = []; | ||
| var arrayOfCatPoses = []; | ||
| var arrayOfDogPoses = []; | ||
|
|
||
| var arrayOfWords = []; | ||
| var indicesToOutputWords = []; | ||
| var indexToWords = 0; | ||
|
|
||
|
|
||
|
|
||
| /************************************** | ||
| * RUN and STOP buttons on the canvas * | ||
|
|
@@ -227,33 +272,66 @@ <h1>CSE 190 Blockly Playground: Project 3</h1> | |
| window.requestAnimationFrame(animate); | ||
| } | ||
|
|
||
| function updatePose(poseNum){ | ||
| arrayOfPoses.push(poseNum); | ||
|
|
||
| /************************** | ||
| ** update the Cat Pose ** | ||
| **************************/ | ||
| function updateCatPose(catPoseNum){ | ||
| arrayOfCatPoses.push(catPoseNum); | ||
| numOfInstructions++; | ||
| } | ||
| } | ||
|
|
||
| /************************** | ||
| ** update the Dog Pose ** | ||
| **************************/ | ||
| function updateDogPose(dogPoseNum){ | ||
| arrayOfDogPoses.push(dogPoseNum); | ||
| numOfInstructions++; | ||
| } | ||
|
|
||
| /******************* | ||
| ** Say words ****** | ||
| *******************/ | ||
| function say(words) { | ||
| arrayOfWords.push(words); | ||
| indicesToOutputWords.push(numOfInstructions); | ||
| numOfInstructions++; | ||
| } | ||
|
|
||
| function animate() { | ||
| setTimeout(function() { | ||
| setcatImage(arrayOfPoses[indexToArrays]); | ||
|
|
||
| clearCanvas(); | ||
| setcatImage(arrayOfCatPoses[indexToArrays]); | ||
| setDogImage(arrayOfDogPoses[indexToArrays]); | ||
|
|
||
|
|
||
| if(indicesToOutputWords.indexOf(indexToArrays) != -1) { | ||
| setWords(arrayOfWords[indexToWords]); | ||
| indexToWords++; | ||
| } | ||
|
|
||
| indexToArrays++; | ||
|
|
||
| if (indexToArrays == numOfInstructions) | ||
| indexToArrays = 0; | ||
| indexToWords = 0; | ||
|
|
||
| if (animation) { | ||
| window.requestAnimationFrame(animate); | ||
| } | ||
| }, 1000); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| function stopCode() { | ||
| animation = false; | ||
| } | ||
|
|
||
| function resetCanvas(){ | ||
| clearCanvas(); | ||
| setcatImage(1); | ||
| setDogImage(1); | ||
| } | ||
|
|
||
| /************************************* | ||
|
|
@@ -275,13 +353,34 @@ <h1>CSE 190 Blockly Playground: Project 3</h1> | |
| function setcatImage(catIndex){ | ||
| if(!catIndex) | ||
| catIndex = 1; | ||
| clearCanvas(); | ||
| catImage.src = "images/cat"+catIndex+".png"; | ||
| ctx.drawImage(cat1.image, cat1.x, cat1.y); | ||
| ctx.save(); | ||
| ctx.restore(); | ||
| } | ||
|
|
||
| /**************************** | ||
| * Changing the dog's Pose * | ||
| ****************************/ | ||
| function setDogImage(dogIndex){ | ||
| if(!dogIndex) | ||
| dogIndex = 1; | ||
| dogImage.src = "images/dog"+dogIndex+".png"; | ||
| ctx.drawImage(dog1.image, dog1.x, dog1.y); | ||
| ctx.save(); | ||
| ctx.restore(); | ||
| } | ||
|
|
||
| /**************************** | ||
| ** set the word on canvas ** | ||
| ****************************/ | ||
| function setWords(words) { | ||
| ctx.font="30px Arial"; | ||
| ctx.fillText(words, 200, 400); | ||
| ctx.save(); | ||
| ctx.restore(); | ||
| } | ||
|
|
||
| /*********************** | ||
| * Clearing the Canvas * | ||
| ***********************/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ Blockly.Blocks['clearscreen'] = { | |
| Blockly.Blocks['catpose'] = { | ||
| init: function() { | ||
| this.appendDummyInput() | ||
| .appendField("Change Pose") | ||
| .appendField("Change Cat Pose") | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great specification here |
||
| .appendField(new Blockly.FieldDropdown([["1","1"], ["2","2"], ["3","3"]]), "catIndex"); | ||
| this.setPreviousStatement(true, null); | ||
| this.setNextStatement(true, null); | ||
|
|
@@ -41,6 +41,34 @@ Blockly.Blocks['catpose'] = { | |
| } | ||
| }; | ||
|
|
||
| Blockly.Blocks['dogpose'] = { | ||
| init: function() { | ||
| this.appendDummyInput() | ||
| .appendField("Change Dog Pose") | ||
| .appendField(new Blockly.FieldDropdown([["1","1"], ["2", "2"], ["3", "3"]]), "dogIndex"); | ||
| this.setPreviousStatement(true, null); | ||
| this.setNextStatement(true, null); | ||
| this.setColour(120); | ||
| this.setTooltip(""); | ||
| this.setHelpUrl(""); | ||
| } | ||
| }; | ||
|
|
||
| Blockly.Blocks['animalSay'] = { | ||
| init: function() { | ||
| this.appendValueInput('text') | ||
| .setCheck('String') | ||
| .appendField('Say'); | ||
| this.setNextStatement(true); | ||
| this.setPreviousStatement(true); | ||
| this.setInputsInline(true); | ||
| this.setColour(0); | ||
| this.setTooltip('Returns number of letters in the provided text.'); | ||
| this.setHelpUrl('http://www.w3schools.com/jsref/jsref_length_string.asp'); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| Blockly.JavaScript['whenrunclicked'] = function(block) { | ||
| var statements_name = Blockly.JavaScript.statementToCode(block, 'NAME'); | ||
| var blockCode = statements_name; | ||
|
|
@@ -54,6 +82,20 @@ Blockly.JavaScript['clearscreen'] = function(block) { | |
|
|
||
| Blockly.JavaScript['catpose'] = function(block) { | ||
| var dropdown_catindex = block.getFieldValue('catIndex'); | ||
| var blockCode = 'updatePose('+dropdown_catindex+');'; | ||
| var blockCode = 'updateCatPose('+dropdown_catindex+');'; | ||
| return blockCode; | ||
| }; | ||
|
|
||
| Blockly.JavaScript['dogpose'] = function(block) { | ||
| var dropdown_dogIndex = block.getFieldValue('dogIndex'); | ||
| var blockCode = 'updateDogPose('+dropdown_dogIndex+');'; | ||
| return blockCode; | ||
| }; | ||
|
|
||
| Blockly.JavaScript['animalSay'] = function(block) { | ||
| var words = block.getFieldValue('text'); | ||
| var blockCode = 'say('+words+');'; | ||
| return blockCode; | ||
| } | ||
|
|
||
|
|
||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense