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

Username:   Password: 
 RegisterRegister   
 Pygame spray paint tool
Index -> Programming, Python -> Python Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Comp.Sci




PostPosted: Wed Jan 11, 2012 7:08 pm   Post subject: Pygame spray paint tool

Ok, so i have made this paint program and i have "spray paint" as one of my tools. I have used dots to replicate the spray paint look. Here is my code:

for i in range(size**2/20): # Slows down speed
x=(randint(-10,+10)) #for dots to be randomly placed 10 pixels away from mx,my ( I have used "size" instead of 10 and -10 for my actual program so i can control the
y=(randint(-10,+10)) #size of the figure that is later formed with the dots. For this example, i used 10 and -10 to make things easier
screen.set_at((mx+x,my+y),clr)

*this is just the spray paint part, all the variables are defined somewhere else.

Okay, so my problem is that when I use this tool, the random dots eventually form a square figure around the cursor. Instead, i want the dots to form a circle figure around the cursor.. I know that you need to use the distance formula to get the radius and then cut off whatever is outside of it (therefore creating a circle), but how would i write that in code?
Sponsor
Sponsor
Sponsor
sponsor
mirhagk




PostPosted: Wed Jan 11, 2012 7:28 pm   Post subject: RE:Pygame spray paint tool

well you need to decide how your going to create the circle. An easy way is to generate the dot, then check if it's in the circle, and if so, draw it. However this means that you won't neccassarily have the same amount of pixels drawn each frame (which is probably okay for something like this).

If this is fine, then simply take that and y, and see if they are within the circle. The distance formula is sqrt(x**2+y**2) and then check if that's within the circle (which is 10 in this case, or the size variable I guess)
Display posts from previous:   
   Index -> Programming, Python -> Python Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: