Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Drawing a circle with the mouse
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Insectoid




PostPosted: Mon May 05, 2008 8:59 am   Post subject: Drawing a circle with the mouse

I am trying to make a paint program for fun. I recently changed it to draw with the mouse, rather than the arrow keys. I have 2 problems, though.

1. When I Draw.FillOval to get the line, if I move the mouse to quickly, it doesn't draw them all connected. Rather, they seperate out because of lag. I realize I probably need a new algorithm for this.

2. I have no idea how to do a 'circle tool' with the mouse. I created one with the arrow keys that had a few bugs, but worked rouphly the way I wanted. I want it to work so that when you click, you set the centerpoint of the circle. Then when you move the mouse, the radius is equal to the distance between the mouse and the centerpoint. basicaly, a click-and-drag circle.

Here is my code for my circle tool. I know what is wrong, but once again, I haven't a clue as to how to fix it.

code:

var mousex : int
var mousey : int
var mousebutton : int
var num2 : array char of boolean
var circlex : int
var circley : int
loop
    Input.KeyDown (num2)
    Mouse.Where (mousex, mousey, mousebutton)
   
    if mousebutton = 1 then
        circlex := mousex
        circley := mousey
        Draw.FillOval (circlex, mousey, mousex, mousey, black)
delay (10)
cls
    end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
octopi




PostPosted: Mon May 05, 2008 12:58 pm   Post subject: Re: Drawing a circle with the mouse

Draw it out on paper.

You are going to need to save the start position (center of circle) into some variables.

Next your going to need to calculate the radius, which is going to be the length of the line connecting two points.
The original start position, and the current position. You'll want to use a^2 + b^2 = c^2 formula for this. (There are tutorials on compsci all about this stuff)
(newX - startX)^2 + (newY - startY)^2 = radius^2

You'll have to take the square root of that to find the radius.

So as you move your mouse, draw a circle at startX,startY, with a radius of the radius you calculated above.
octopi




PostPosted: Mon May 05, 2008 1:17 pm   Post subject: Re: Drawing a circle with the mouse

Hmmm, I took a look at your code, your pretty close.

I think this is what you might want:


code:
var mousex : int
var mousey : int
var mousebutton : int
var num2 : array char of boolean
var circlex : int := 0
var circley : int := 0
var radiusSq, radius : int := 0
loop
    Input.KeyDown (num2)
    Mouse.Where (mousex, mousey, mousebutton)

    if mousebutton = 1 then
            radiusSq := (mousex - circlex) ** 2 + (mousey - circley) ** 2
            radius := floor (sqrt (radiusSq))
            Draw.FillOval (circlex, circley, radius, radius, black)
            delay (10)
            cls
    else
        circlex := mousex
        circley := mousey
    end if
end loop
Insectoid




PostPosted: Mon May 05, 2008 3:08 pm   Post subject: RE:Drawing a circle with the mouse

SHOOT! MY SHIFT BUTTON MUST BE JAMMED OR SOMETHING I AM NOT ON CAPS LOCK OTHERWISE THIS WOULDNT HAPPEN WHEN I PRESS ! WTF THIS HAPENED AT SCHOOL TOO BUT WHEN I REBOOTED IT WAS FINE WHATS WRONG?
Insectoid




PostPosted: Mon May 05, 2008 3:19 pm   Post subject: RE:Drawing a circle with the mouse

Once again, I reboot, and it works! Maybe this has something to do with the song I was listening to on youtube (You're pitiful- weird al)
andrew.




PostPosted: Mon May 05, 2008 4:59 pm   Post subject: RE:Drawing a circle with the mouse

Why did you post that?

Anyways, I had trouble with this a while ago too. I figured it out. I think that the best way to do this is to sit down and think about it. Step-by-step how this is going to work and then write down the procedure on paper. After that, go and enter that into Turing code and try it.
Insectoid




PostPosted: Mon May 05, 2008 6:07 pm   Post subject: RE:Drawing a circle with the mouse

I posted that because it happened while writing an actual post and I wanted an answer. Also, when that happened, my mousewheel started going refreshing/going back/going forwad on my browser.

Anyway, I'm working on pacman now, so no worries, I'll figure this out.
isaiahk9




PostPosted: Fri May 09, 2008 3:22 pm   Post subject: RE:Drawing a circle with the mouse

insectoid, if you were working at that at school, are you sure its not a teacher using netsupport/Lanschool on you. Some teachers have fidled with my work at school with mentioned above. Check out off topic to see Dan's solution to avoid netsupport.
If you weren't working at school then i dont know.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: