Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function painting(){
- canvas.addEventListener('mousedown', down)
- canvas.addEventListener('mouseup', toggledraw)
- canvas.addEventListener('mousemove',
- function(evt){
- var mosuePos = getMousePos(canvas, evt)
- var posx =mosuePos.x
- var posy =mosuePos.y
- var tryb = "kółko" //1
- draw(canvas, posx, posy, tryb) //2
- })
- function down(){
- md = true
- }
- function toggledraw(){
- md = false
- }
- function getMousePos(canvas, evt){
- var rect = canvas.getBoundingClientRect()
- return{
- x:evt.clientX - rect.left,
- y:evt.clientY - rect.top
- }
- }
- function draw(canvas, posx, posy, tryb){ //3
- var context = canvas.getContext('2d')
- if(md){
- if (tryb == "kwadrat") //4
- context.fillRect(posx, posy, 10, 10)
- else if (tryb == "kółko")
- alert("rysowanie koła")
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement