-
Notifications
You must be signed in to change notification settings - Fork 133
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
Vickymin #35
Open
vickymin
wants to merge
10
commits into
qianxueseng-com:master
Choose a base branch
from
vickymin:vickymin
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
Vickymin #35
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
726aae0
create files
vickymin dcf643c
add html
vickymin 12179f4
add one feature:judge number range
vickymin 186acd0
update margin
vickymin bdafcda
update col
vickymin 241ddb8
finish basic features
vickymin 389f30f
update js file
vickymin a122ebb
rename html
vickymin 87a1b28
fix error
vickymin 0c1fbe9
update css
vickymin 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
body{ | ||
background-color: #CCC; | ||
} | ||
#box{ | ||
width:650px; | ||
height:700px; | ||
margin:0px auto; | ||
} | ||
form{ | ||
width:550px; | ||
height:40px; | ||
margin-top:20px; | ||
margin-left:80px; | ||
} | ||
#generate, #clear{ | ||
background-color:#777; | ||
color:#EEE; | ||
width:80px; | ||
margin-right:15px; | ||
} | ||
#generate:hover,#clear:hover{ | ||
background-color:#555; | ||
width:80px; | ||
box-shadow: 3px 3px 5px #555; | ||
} | ||
#main{ | ||
border:2px solid #999; | ||
margin-top:5px; | ||
margin-left: 20px; | ||
background-color:#92A8D1; | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<head> | ||
<meta name="author" content="minjiepei"> | ||
<meta charset="utf-8"> | ||
<link rel="stylesheet" href="bootstrap.min.css"> | ||
<link rel="stylesheet" href="grid.css"> | ||
</head> | ||
|
||
<body> | ||
<div id="box"> | ||
<form role="form"> | ||
<div class="col-sm-7"> | ||
<div class="input-group-md"> | ||
<input type="text" class="form-control" id="integer" placeholder="select an integer between 1 to 20"> | ||
</div> | ||
</div> | ||
<div class="col-sm-5"> | ||
<button type="button" id="generate" class="btn btn-md">Generate</button> | ||
<button type="reset" id="clear" class="btn btn-md">Clear</button> | ||
</div> | ||
</form> | ||
<canvas id="main" width="600" height="600">Please upgrade your browser!</canvas> | ||
</div> | ||
<script src="grid.js"></script> | ||
|
||
</body> |
This file contains 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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
var canvas = document.getElementById("main"); | ||
var context = canvas.getContext("2d"); | ||
|
||
var number; //用户输入的数字 | ||
var w; //方格边长 | ||
var space; //方格之间空隙 | ||
|
||
window.onload = function(){ | ||
//点击“Generate”按钮 | ||
var gen_button = document.getElementById("generate"); | ||
gen_button.onclick = generateHandler; | ||
//点击“Clear”按钮 | ||
var clear_button = document.getElementById("clear"); | ||
clear_button.onclick = function(){clearCanvas(context,canvas);} | ||
} | ||
|
||
//处理“Generate”按钮 | ||
var generateHandler = function(){ | ||
clearCanvas(context,canvas); | ||
number = parseInt(document.getElementById("integer").value); | ||
w = Math.floor(canvas.width / number) /1.03; | ||
space = (canvas.width-number*w)/(number+1); | ||
//判断用户输入数字是否在范围内 | ||
if (0 < number && number < 27){ | ||
drawGrid(context); | ||
} | ||
else{ | ||
alert("Plese enter an integer between 1 to 20!"); | ||
} | ||
//监听用户点击方格的位置 | ||
canvas.addEventListener("mousedown", showPosition, false); | ||
} | ||
|
||
//清空canvas | ||
var clearCanvas = function(context,canvas){ | ||
context.fillStyle = "#92A8D1"; | ||
context.fillRect(0,0,canvas.width,canvas.height); | ||
} | ||
|
||
//在canvas上画出方格及相应数字 | ||
var drawGrid = function(context){ | ||
var i,j; | ||
for(i=0; i<number; i++){ | ||
for(j=0; j<number; j++){ | ||
//画方格 | ||
context.fillStyle = "#F5B1B1"; | ||
context.fillRect(i*w+(i+1)*space, j*w+(j+1)*space, w, w); | ||
//画数字 | ||
context.fillStyle = "#92A8D1"; | ||
context.textAlign = "center"; | ||
context.font = (w/3).toString() + "px" + " Arial"; | ||
context.fillText(number*j+i+1, i*w+(i+1)*space+w/2, j*w+(j+1)*space+w/1.6); | ||
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. 像1.6这种东西都是最好写成一个constant 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. 好的 |
||
} | ||
} | ||
} | ||
|
||
//找到用户点击方格的位置 | ||
var showPosition = function(event){ | ||
var x = event.clientX - canvas.offsetLeft; | ||
var y = event.clientY - canvas.offsetTop; | ||
var i,j; | ||
for(i=0; i<=number; i++){ | ||
for(j=0; j<=number; j++){ | ||
if(x>=i*space+i*w && x<=i*space+(i+1)*w){ | ||
if(y>=j*space+j*w && y<=j*space+(j+1)*w){ | ||
console.log(number*j+i+1); | ||
} | ||
} | ||
} | ||
} | ||
} |
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.
都用camelCase,例如clearButton
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.
好的,谢谢老师!