Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CI320
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Wellington Gabriel Vicente de Souza
CI320
Commits
d60631f6
Commit
d60631f6
authored
7 years ago
by
Wellington Gabriel Vicente de Souza
Browse files
Options
Downloads
Patches
Plain Diff
[T3] first commit: the two first parts are done
parent
fdbcbe27
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
T3/canvas.css
+14
-0
14 additions, 0 deletions
T3/canvas.css
T3/lines.html
+15
-0
15 additions, 0 deletions
T3/lines.html
T3/lines.js
+187
-0
187 additions, 0 deletions
T3/lines.js
with
216 additions
and
0 deletions
T3/canvas.css
0 → 100644
+
14
−
0
View file @
d60631f6
*
{
margin
:
0
;
padding
:
0
;
}
html
,
body
{
width
:
100%
;
}
canvas
{
display
:
block
;
height
:
100%
;
width
:
100%
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
T3/lines.html
0 → 100644
+
15
−
0
View file @
d60631f6
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
>
<link
rel=
"stylesheet"
href=
"canvas.css"
>
</head>
<body>
<canvas
id=
"canvas"
>
Your browser does not support the HTML5 canvas tag.
</canvas>
<p>
asdsadsa
</p>
</body>
<script
type=
"text/javascript"
src=
"lines.js"
></script>
</html>
This diff is collapsed.
Click to expand it.
T3/lines.js
0 → 100644
+
187
−
0
View file @
d60631f6
class
Line
{
constructor
(
x0
,
y0
,
xf
,
yf
)
{
this
.
x0
=
x0
;
this
.
y0
=
y0
;
this
.
xf
=
xf
;
this
.
yf
=
yf
;
this
.
width
=
Math
.
abs
(
xf
-
x0
);
this
.
height
=
Math
.
abs
(
yf
-
y0
);
this
.
centerX
=
x0
+
this
.
width
/
2
;
this
.
centerY
=
y0
+
this
.
height
/
2
;
}
}
var
canvas
=
document
.
getElementById
(
'
canvas
'
);
var
ctx
=
canvas
.
getContext
(
'
2d
'
);
var
width
=
window
.
innerWidth
;
var
height
=
window
.
innerHeight
;
var
centerX
=
width
/
2
;
var
centerY
=
height
/
2
;
var
mouseX
=
0
;
var
mouseY
=
0
;
var
mouseDown
=
0
;
var
rightClick
=
0
;
var
lines
=
[];
lines
[
0
]
=
new
Line
(
centerX
-
200
,
centerY
,
centerX
+
200
,
centerY
);
canvas
.
width
=
width
;
canvas
.
height
=
height
;
//event listeners
window
.
addEventListener
(
'
resize
'
,
resizeCanvas
,
false
);
window
.
addEventListener
(
'
mousedown
'
,
handleMouseDown
,
false
);
window
.
addEventListener
(
'
mouseup
'
,
handleMouseUp
,
false
);
document
.
addEventListener
(
"
contextmenu
"
,
function
(
e
){
e
.
preventDefault
();
},
false
);
onmousemove
=
function
(
e
){
mouseX
=
e
.
clientX
;
mouseY
=
e
.
clientY
;
}
//event handlers
function
resizeCanvas
()
{
canvas
.
width
=
window
.
innerWidth
;
canvas
.
height
=
window
.
innerHeight
;
width
=
window
.
innerWidth
;
height
=
window
.
innerHeight
;
centerX
=
width
/
2
;
centerY
=
height
/
2
;
drawCurrentCanvas
();
}
function
handleMouseDown
(
e
)
{
rightClick
=
e
.
button
==
2
?
1
:
0
;
if
(
!
rightClick
)
mouseDown
=
1
;
}
function
handleMouseUp
()
{
mouseDown
=
0
;
rightClick
=
0
;
}
function
handleMouse
()
{
for
(
var
i
=
lines
.
length
-
1
;
i
>=
0
;
i
--
)
{
if
(
mouseDown
)
{
if
(
mouseX
>=
lines
[
i
].
centerX
-
40
&&
mouseX
<=
lines
[
i
].
centerX
+
40
&&
mouseY
>=
lines
[
i
].
centerY
-
40
&&
mouseY
<=
lines
[
i
].
centerY
+
40
)
{
console
.
log
(
"
Line
"
+
i
+
"
:
"
+
lines
[
i
].
x0
+
"
"
+
lines
[
i
].
y0
+
"
"
+
lines
[
i
].
xf
+
"
"
+
lines
[
i
].
yf
+
"
"
+
lines
[
i
].
width
+
"
"
+
lines
[
i
].
height
+
"
"
+
lines
[
i
].
centerX
+
"
"
+
lines
[
i
].
centerY
);
if
(
lines
[
i
].
x0
<=
lines
[
i
].
xf
)
{
lines
[
i
].
x0
=
mouseX
-
(
lines
[
i
].
width
/
2
);
lines
[
i
].
xf
=
mouseX
+
(
lines
[
i
].
width
/
2
);
}
else
{
lines
[
i
].
xf
=
mouseX
-
(
lines
[
i
].
width
/
2
);
lines
[
i
].
x0
=
mouseX
+
(
lines
[
i
].
width
/
2
);
}
if
(
lines
[
i
].
y0
<=
lines
[
i
].
yf
)
{
lines
[
i
].
y0
=
mouseY
-
(
lines
[
i
].
height
/
2
);
lines
[
i
].
yf
=
mouseY
+
(
lines
[
i
].
height
/
2
);
}
else
{
lines
[
i
].
yf
=
mouseY
-
(
lines
[
i
].
height
/
2
);
lines
[
i
].
y0
=
mouseY
+
(
lines
[
i
].
height
/
2
);
}
if
(
lines
[
i
].
x0
<=
lines
[
i
].
xf
)
{
lines
[
i
].
centerX
=
lines
[
i
].
x0
+
lines
[
i
].
width
/
2
;
}
else
{
lines
[
i
].
centerX
=
lines
[
i
].
xf
+
lines
[
i
].
width
/
2
;
}
if
(
lines
[
i
].
y0
<=
lines
[
i
].
yf
)
{
lines
[
i
].
centerY
=
lines
[
i
].
y0
+
lines
[
i
].
height
/
2
;
}
else
{
lines
[
i
].
centerY
=
lines
[
i
].
yf
+
lines
[
i
].
height
/
2
;
}
break
;
}
else
if
(
mouseX
>=
lines
[
i
].
x0
-
60
&&
mouseX
<=
lines
[
i
].
x0
+
60
&&
mouseY
>=
lines
[
i
].
y0
-
60
&&
mouseY
<=
lines
[
i
].
y0
+
60
)
{
console
.
log
(
"
Line
"
+
i
+
"
:
"
+
lines
[
i
].
x0
+
"
"
+
lines
[
i
].
y0
+
"
"
+
lines
[
i
].
xf
+
"
"
+
lines
[
i
].
yf
+
"
"
+
lines
[
i
].
width
+
"
"
+
lines
[
i
].
height
+
"
"
+
lines
[
i
].
centerX
+
"
"
+
lines
[
i
].
centerY
);
lines
[
i
].
x0
=
mouseX
;
lines
[
i
].
y0
=
mouseY
;
lines
[
i
].
width
=
Math
.
abs
(
lines
[
i
].
xf
-
lines
[
i
].
x0
);
lines
[
i
].
height
=
Math
.
abs
(
lines
[
i
].
yf
-
lines
[
i
].
y0
);
if
(
lines
[
i
].
x0
<=
lines
[
i
].
xf
)
{
lines
[
i
].
centerX
=
lines
[
i
].
x0
+
lines
[
i
].
width
/
2
;
}
else
{
lines
[
i
].
centerX
=
lines
[
i
].
xf
+
lines
[
i
].
width
/
2
;
}
if
(
lines
[
i
].
y0
<=
lines
[
i
].
yf
)
{
lines
[
i
].
centerY
=
lines
[
i
].
y0
+
lines
[
i
].
height
/
2
;
}
else
{
lines
[
i
].
centerY
=
lines
[
i
].
yf
+
lines
[
i
].
height
/
2
;
}
break
;
}
else
if
(
mouseX
>=
lines
[
i
].
xf
-
60
&&
mouseX
<=
lines
[
i
].
xf
+
60
&&
mouseY
>=
lines
[
i
].
yf
-
60
&&
mouseY
<=
lines
[
i
].
yf
+
60
)
{
console
.
log
(
"
Line
"
+
i
+
"
:
"
+
lines
[
i
].
x0
+
"
"
+
lines
[
i
].
y0
+
"
"
+
lines
[
i
].
xf
+
"
"
+
lines
[
i
].
yf
+
"
"
+
lines
[
i
].
width
+
"
"
+
lines
[
i
].
height
+
"
"
+
lines
[
i
].
centerX
+
"
"
+
lines
[
i
].
centerY
);
lines
[
i
].
xf
=
mouseX
;
lines
[
i
].
yf
=
mouseY
;
lines
[
i
].
width
=
Math
.
abs
(
lines
[
i
].
xf
-
lines
[
i
].
x0
);
lines
[
i
].
height
=
Math
.
abs
(
lines
[
i
].
yf
-
lines
[
i
].
y0
);
if
(
lines
[
i
].
x0
<=
lines
[
i
].
xf
)
{
lines
[
i
].
centerX
=
lines
[
i
].
x0
+
lines
[
i
].
width
/
2
;
}
else
{
lines
[
i
].
centerX
=
lines
[
i
].
xf
+
lines
[
i
].
width
/
2
;
}
if
(
lines
[
i
].
y0
<=
lines
[
i
].
yf
)
{
lines
[
i
].
centerY
=
lines
[
i
].
y0
+
lines
[
i
].
height
/
2
;
}
else
{
lines
[
i
].
centerY
=
lines
[
i
].
yf
+
lines
[
i
].
height
/
2
;
}
break
;
}
}
else
if
(
rightClick
)
{
if
(
mouseX
>=
lines
[
i
].
x0
&&
mouseX
<=
lines
[
i
].
xf
)
{
lines
[
lines
.
length
]
=
new
Line
(
mouseX
,
mouseY
,
lines
[
i
].
xf
,
lines
[
i
].
yf
);
lines
[
i
].
xf
=
mouseX
;
lines
[
i
].
yf
=
mouseY
;
lines
[
i
].
width
=
Math
.
abs
(
lines
[
i
].
xf
-
lines
[
i
].
x0
);
lines
[
i
].
height
=
Math
.
abs
(
lines
[
i
].
yf
-
lines
[
i
].
y0
);
lines
[
i
].
centerX
=
lines
[
i
].
x0
+
lines
[
i
].
width
/
2
;
lines
[
i
].
centerY
=
lines
[
i
].
y0
+
lines
[
i
].
height
/
2
;
rightClick
=
0
;
break
;
}
else
if
(
mouseX
<
lines
[
i
].
x0
&&
mouseX
>
lines
[
i
].
xf
)
{
lines
[
lines
.
length
]
=
new
Line
(
mouseX
,
mouseY
,
lines
[
i
].
x0
,
lines
[
i
].
y0
);
lines
[
i
].
x0
=
mouseX
;
lines
[
i
].
y0
=
mouseY
;
lines
[
i
].
width
=
Math
.
abs
(
lines
[
i
].
xf
-
lines
[
i
].
x0
);
lines
[
i
].
height
=
Math
.
abs
(
lines
[
i
].
yf
-
lines
[
i
].
y0
);
lines
[
i
].
centerX
=
lines
[
i
].
xf
+
lines
[
i
].
width
/
2
;
lines
[
i
].
centerY
=
lines
[
i
].
yf
+
lines
[
i
].
height
/
2
;
rightClick
=
0
;
break
;
}
}
}
}
//function that updates screen
function
drawCurrentCanvas
()
{
drawLines
();
if
(
mouseDown
||
rightClick
)
handleMouse
();
requestAnimationFrame
(
drawCurrentCanvas
);
}
//function that draws all existing lines
function
drawLines
()
{
ctx
.
clearRect
(
0
,
0
,
canvas
.
width
,
canvas
.
height
);
for
(
var
i
=
lines
.
length
-
1
;
i
>=
0
;
i
--
)
{
drawLine
(
lines
[
i
].
x0
,
lines
[
i
].
y0
,
lines
[
i
].
xf
,
lines
[
i
].
yf
);
}
}
//function that draws a line
function
drawLine
(
x0
,
y0
,
xf
,
yf
)
{
ctx
.
beginPath
();
ctx
.
lineWidth
=
3
;
ctx
.
moveTo
(
x0
,
y0
);
ctx
.
lineTo
(
xf
,
yf
);
ctx
.
stroke
();
lineX0
=
x0
;
lineY0
=
y0
;
lineXf
=
xf
;
lineYf
=
yf
;
}
//start
drawCurrentCanvas
();
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment