Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drawing-app
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
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
sweng-group-15
drawing-app
Commits
21d7ebc8
Commit
21d7ebc8
authored
5 years ago
by
Yuriy Maksymets
Browse files
Options
Downloads
Patches
Plain Diff
WIP: intuitive erasing
parent
22531aba
No related branches found
No related tags found
2 merge requests
!57
Erasure intervals
,
!48
Intuitive erasing
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
public/cursor.svg
+3
-0
3 additions, 0 deletions
public/cursor.svg
public/styles.css
+1
-0
1 addition, 0 deletions
public/styles.css
src/app.js
+55
-12
55 additions, 12 deletions
src/app.js
src/room.js
+12
-0
12 additions, 0 deletions
src/room.js
with
71 additions
and
12 deletions
public/cursor.svg
0 → 100644
+
3
−
0
View file @
21d7ebc8
<svg
viewBox=
"-2 -2 6 6"
xmlns=
"http://www.w3.org/2000/svg"
>
<circle
cx=
"2"
cy=
"2"
r=
"2"
/>
</svg>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
public/styles.css
+
1
−
0
View file @
21d7ebc8
html
,
html
,
body
{
body
{
height
:
100%
;
height
:
100%
;
cursor
:
crosshair
;
}
}
body
{
body
{
...
...
This diff is collapsed.
Click to expand it.
src/app.js
+
55
−
12
View file @
21d7ebc8
...
@@ -18,7 +18,53 @@ const tools = {
...
@@ -18,7 +18,53 @@ const tools = {
const
STROKECOLOUR
=
"
blue
"
const
STROKECOLOUR
=
"
blue
"
const
STROKERADIUS
=
2
const
STROKERADIUS
=
2
const
ERASERRADIUS
=
STROKERADIUS
*
2
const
ERASERRADIUS
=
STROKERADIUS
*
5
function
interpolatedCoordinate
(
start
,
end
,
length
)
{
const
dx
=
end
[
0
]
-
start
[
0
]
const
dy
=
end
[
1
]
-
start
[
1
]
const
dist
=
getDistance
(
start
,
end
)
const
ratio
=
length
/
dist
return
[
start
[
0
]
+
dx
*
ratio
,
start
[
1
]
+
dy
*
ratio
]
}
function
eraseAt
(
x
,
y
,
room
)
{
let
mousePos
=
[
x
,
y
]
room
.
getPaths
().
forEach
((
points
,
pathID
)
=>
{
points
.
forEach
((
point
,
i
)
=>
{
const
distanceToPoint
=
getDistance
(
mousePos
,
point
)
if
(
distanceToPoint
<=
ERASERRADIUS
)
{
room
.
erasePoint
(
pathID
,
i
)
let
prev
,
next
if
(
i
>
0
)
{
prev
=
i
-
1
}
if
(
i
<
points
.
length
-
1
)
{
next
=
i
+
1
}
if
(
prev
!==
undefined
)
{
const
interpolatedPoint
=
interpolatedCoordinate
(
point
,
points
[
prev
],
ERASERRADIUS
,
)
room
.
insertIntoPath
(
pathID
,
prev
,
interpolatedPoint
)
}
if
(
next
!==
undefined
)
{
const
interpolatedPoint
=
interpolatedCoordinate
(
point
,
points
[
next
],
ERASERRADIUS
,
)
room
.
insertIntoPath
(
pathID
,
next
,
interpolatedPoint
)
}
}
})
})
}
const
addOrUpdatePathElem
=
(
pathElems
,
id
,
points
)
=>
{
const
addOrUpdatePathElem
=
(
pathElems
,
id
,
points
)
=>
{
let
pathElem
=
pathElems
.
get
(
id
)
let
pathElem
=
pathElems
.
get
(
id
)
...
@@ -90,9 +136,7 @@ const addOrUpdatePathElem = (pathElems, id, points) => {
...
@@ -90,9 +136,7 @@ const addOrUpdatePathElem = (pathElems, id, points) => {
}
}
const
getDistance
=
(
a
,
b
)
=>
{
const
getDistance
=
(
a
,
b
)
=>
{
return
Math
.
sqrt
(
return
Math
.
sqrt
((
a
[
0
]
-
b
[
0
])
**
2
+
(
a
[
1
]
-
b
[
1
])
**
2
)
(
a
[
0
]
-
b
[
0
])
*
(
a
[
0
]
-
b
[
0
])
+
(
a
[
1
]
-
b
[
1
])
*
(
a
[
1
]
-
b
[
1
]),
)
}
}
function
setElemVisible
(
elem
,
visible
=
true
)
{
function
setElemVisible
(
elem
,
visible
=
true
)
{
...
@@ -158,7 +202,7 @@ function handleRoomConnectionEstablished(room) {
...
@@ -158,7 +202,7 @@ function handleRoomConnectionEstablished(room) {
addOrUpdatePathElem
(
pathElems
,
id
,
points
)
addOrUpdatePathElem
(
pathElems
,
id
,
points
)
})
})
let
currentTool
=
tools
.
PEN
let
currentTool
=
tools
.
ERASER
const
pathIDsByPointerID
=
new
Map
()
const
pathIDsByPointerID
=
new
Map
()
const
canvasOnPointerEnter
=
(
e
)
=>
{
const
canvasOnPointerEnter
=
(
e
)
=>
{
...
@@ -171,13 +215,7 @@ function handleRoomConnectionEstablished(room) {
...
@@ -171,13 +215,7 @@ function handleRoomConnectionEstablished(room) {
if
(
currentTool
==
tools
.
PEN
)
{
if
(
currentTool
==
tools
.
PEN
)
{
pathIDsByPointerID
.
set
(
e
.
pointerId
,
room
.
addPath
(
mousePos
))
pathIDsByPointerID
.
set
(
e
.
pointerId
,
room
.
addPath
(
mousePos
))
}
else
if
(
currentTool
==
tools
.
ERASER
)
{
}
else
if
(
currentTool
==
tools
.
ERASER
)
{
room
.
getPaths
().
forEach
((
points
,
pathID
)
=>
{
eraseAt
(
mousePos
[
0
],
mousePos
[
1
],
room
)
points
.
forEach
((
point
,
i
)
=>
{
if
(
getDistance
(
mousePos
,
point
)
<=
ERASERRADIUS
)
{
room
.
erasePoint
(
pathID
,
i
)
}
})
})
}
}
}
}
...
@@ -263,6 +301,11 @@ function handleRoomConnectionEstablished(room) {
...
@@ -263,6 +301,11 @@ function handleRoomConnectionEstablished(room) {
handleRoomConnectClick
()
handleRoomConnectClick
()
}
}
HTML
.
roomConnectButton
.
addEventListener
(
"
click
"
,
roomConnectButtonOnClick
)
HTML
.
roomConnectButton
.
addEventListener
(
"
click
"
,
roomConnectButtonOnClick
)
let
pid
=
room
.
addPath
([
100
,
100
])
room
.
extendPath
(
pid
,
[
100
,
100
])
room
.
extendPath
(
pid
,
[
150
,
150
])
room
.
extendPath
(
pid
,
[
100
,
200
])
}
}
function
handleRoomConnectionError
(
err
)
{
function
handleRoomConnectionError
(
err
)
{
...
...
This diff is collapsed.
Click to expand it.
src/room.js
+
12
−
0
View file @
21d7ebc8
...
@@ -29,7 +29,19 @@ class Room extends EventTarget {
...
@@ -29,7 +29,19 @@ class Room extends EventTarget {
return
id
return
id
}
}
insertIntoPath
(
id
,
index
,
[
x
,
y
])
{
console
.
log
(
"
Inserting path with
"
,
index
,
[
x
,
y
])
console
.
log
(
this
.
_y
.
share
.
strokeAdd
.
get
(
id
))
this
.
_y
.
share
.
strokeAdd
.
get
(
id
).
insert
(
index
,
[[
x
,
y
]])
}
extendPath
(
id
,
[
x
,
y
])
{
extendPath
(
id
,
[
x
,
y
])
{
console
.
log
(
"
Extending path with
"
,
[
x
,
y
])
console
.
log
(
this
.
_y
.
share
.
strokeAdd
.
get
(
id
))
this
.
_y
.
share
.
strokeAdd
.
get
(
id
).
push
([[
x
,
y
]])
this
.
_y
.
share
.
strokeAdd
.
get
(
id
).
push
([[
x
,
y
]])
}
}
...
...
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