Ellipse

lespaul36

Member
Joined
Dec 12, 2007
Messages
7
Programming Experience
3-5
I am working on a icon editing program and want the user to have the ability to make ellipses. I have considered using the graphics drawellipse, but think that it would cause alot of overhead since I am using a grid of pictureboxes (one picturebox per pixel of the image). I would have to loop through all the pixels and reset the grid everytime the mouse moved to a new section of the grid. I was thinking of using a formula to draw it myself on the mouse movements, but haven't found any code to really help me. Any one got some code or ideas?
 
to calculate the points on an ellipse, I used the following code;
VB.NET:
    'calculate the radius for intWidth and intHeight
    intHeight = intHeight / 2
    intWidth = (intWidth / 2) - intHeight
    
    'calculate the starting point of the ellipse
    sngTiltX = Sin(sngTiltAngle * PIdiv180) * intWidth
    sngTiltY = Cos(sngTiltAngle * PIdiv180) * intWidth
    
    'draw the ellipse using one line for every three pixels
    'This will increase drawing speed on small ellipses and produce
    'detailed ones for large ellipses.
    sngNumOfPoints = (2 * PI * (intWidth + intHeight)) / 4 '2.Pi.r = circumfrence, /4=per 4 pixels
    
    'size the array to match the number of points to be calculated
    ReDim udtEllipse(sngNumOfPoints)
    
    'calculate the number of degrees between points
    sngDegPerPoint = (360 / sngNumOfPoints)
    
    For sngCounter = 0 To 360 Step sngDegPerPoint
        sngMoveCenterX = intCenterX + (Cos(sngCounter * PIdiv180) * sngTiltX)
        sngMoveCenterY = intCenterY + (Cos(sngCounter * PIdiv180) * sngTiltY)
        
        'calculate the new position
        sngCircleX = Sin((sngCounter + sngTiltAngle) * PIdiv180) * intHeight
        sngCircleY = Cos((sngCounter + sngTiltAngle) * PIdiv180) * intHeight
        
        'add the points
        udtEllipse(Round(sngCounter / sngDegPerPoint)).X = sngMoveCenterX + sngCircleX
        udtEllipse(Round(sngCounter / sngDegPerPoint)).Y = sngMoveCenterY + sngCircleY
    Next sngCounter
I'd have to ask though, why are you using an entire picture box as a pixel?
 
It seemed like the easies way to get mouse movement and resize pixels for editing. I may end up changing that idea. I have a pretty fast computer and originally wrote this for my own use, but I may end up sharing it. If I do share it then I will have to make it run smoother for those that aren't running dual processors.
 
Back
Top