# Help with drawing boundaries on sketchpad

**URL:** <https://forum.kirupa.com/t/help-with-drawing-boundaries-on-sketchpad/315729>\
**Category:** Uncategorized\
**Created:** [November 3, 2010, 12:29am UTC](https://forum.kirupa.com/t/help-with-drawing-boundaries-on-sketchpad/315729 "2010-11-03T00:29:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![acedo](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@acedo](https://forum.kirupa.com/u/acedo)\
**Post date:** [November 3, 2010, 12:29am UTC](https://forum.kirupa.com/t/help-with-drawing-boundaries-on-sketchpad/315729/1 "2010-11-03T00:29:06Z")

</div>

Hey

I would be so happy if anyone could help me out on this one. I have made a sketchpad and want to be able to contain the drawing within some boundaries. So far I’ve managed to set boundaries so that I can’t start to draw outside some x and y values but if I start drawing inside those I can continue to draw all over the stage. So I need something to make it stop drawing when the mouse is going out of the boundary values.

Well here is my code so far:

lineThickness = 3;  
selectedColor = “0xffffff”;  
this.onMouseDown = startDrawing;  
this.onMouseUp = stopDrawing;

function startDrawing() {  
if (\_xmouse\>1 && \_xmouse\<935 && \_ymouse\>0 && \_ymouse\<511) {  
this.lineStyle(lineThickness, selectedColor);  
this.moveTo(this.\_xmouse, this.\_ymouse);  
this.onMouseMove = drawLine;  
}  
}

function drawLine() {  
this.lineTo(this.\_xmouse, this.\_ymouse);  
}  
function stopDrawing() {  
delete this.onMouseMove;  
}  
line0.onPress = function() {  
lineThickness = 0;  
};  
line3.onPress = function() {  
lineThickness = 3;  
};  
line6.onPress = function() {  
lineThickness = 6;  
};  
colorRed.onPress = function() {  
selectedColor = “0xFF0000”;  
};  
colorGreen.onPress = function() {  
selectedColor = “0x00FF00”;  
};
