in Education by
A few days ago I've started learning pygame. So, now I've got the code which allows me to draw different curves with the help of a mouse. My task is to fill the curve with a color. I know for sure that the curve is close import pygame as py import sys py.init() White = (255,255,255) Black = (0,0,0) clock = py.time.Clock() H = 400 W = 600 sc = py.display.set_mode((W,H)) sc.fill(White) py.display.set_caption('Curve drawing') py.display.update() draw = False while 1: for i in py.event.get(): if i.type == py.QUIT: py.image.save(sc,r'C:/Users/Xiaomi' + '/temporary.png') py.quit() sys.exit() elif i.type == py.MOUSEBUTTONDOWN: if i.button == 1: draw = True elif i.button == 2: sc.fill(White) py.display.update() elif i.type == py.MOUSEBUTTONUP: if i.button == 1: draw = False if draw == True: py.draw.circle(sc,Black,i.pos,7) py.display.update() Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
You could use the PyGame polygon drawing function to create a filled area bounded by all the mouse points. So instead of drawing the circle at each point, keep adding a mouse position to the list of co-ordinates as a mouse moves. When a button is released, draw the filled polygon around all these points. fill_coords = [] # points to make filled polygon while 1: for i in py.event.get(): if i.type == py.QUIT: py.image.save(sc,r'C:/Users/Xiaomi' + '/temporary.png') py.quit() sys.exit() elif i.type == py.MOUSEBUTTONDOWN: if i.button == 1: draw = True fill_coords = [] # restart the polygon elif i.button == 2: sc.fill(White) py.display.update() elif i.type == py.MOUSEBUTTONUP: if i.button == 1: draw = False pygame.draw.polygon( sc, Black, fill_coords ) # filled polygon elif i.type == pygame.MOUSEMOTION: # when the mouse moves if ( draw ): fill_coords.append( i.pos ) # remember co-ordinate mouse_position = pygame.mouse.get_pos() if draw == True: py.draw.circle(sc,Black,i.pos,7) py.display.update() If you are a beginner and want to know more about Python the do check out the python for data science course

Related questions

0 votes
    I have the dataset that has the no_employees column that is the str object. whats is a best way to create the new ... 1-5 |Very Small Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    please see my code below, example_list = [ ['a','b','c'], ['f','g','h'], ['i','j','k'], ] my_string = ''' ' ... g','h'), ('i','j','k'); Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    When I try t display the Plotly graph from python as an image that works fine import plotly.express as px from IPython. ... ='png')))"] Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    When I run pip3 install -r requirements.txt on the project I get this error message: pip._vendor.pkg_resources. ... on my machine. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    The code works fine but the only problem I encountered an error is: bad operand type for unary +: 'str'. This is ... for unary +: 'str' Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    I have the data frame that looks like this: Date Visa Mastercard Amex Paypal 1/1/20 0 20 0 0 2/1/20 ... info() Any help is appreciated Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I have this following datetime64[ns] type timestamps. x1=pd.Timestamp('2018-04-25 00:00:00') x2=pd.Timestamp('2020- ... -04-25 00:53:00 Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    I am totally new to Machine Learning and I have been working with unsupervised learning technique. Image shows my ... 3 were given Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I want to upload the file pdf to the folder but a file is not saved to a folder. I already read the ... .run(debug=True)``` Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I have a big data frame. I want to replace float 1.0 and 0.0 with the true and false. My code: import pandas ... to do it in one line. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    To the data frame df: Player Team Points Mean Price Value Gameweek 1 Jim Leeds 4.4 4.40 10.44 0.44 2 Jim ... scalar What am I missing? Select the correct answer from above options...
asked Jan 18, 2022 in Education by JackTerrance
0 votes
    SA=1000.00 AI=0.12 MP=100.00 def remainb(x): if x==0: return 0 else: return x=(SA+(AI/12)*SA)-MP for ... . run the loop until SA==0). Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what is Python with Data Science? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Suppose I have a Tensorflow tensor. How do I get the dimensions (shape) of the tensor as integer values? I ... 'Dimension' instead. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    While training a tensorflow seq2seq model I see the following messages : W tensorflow/core/common_runtime/gpu/pool_allocator ... GB GPU Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
...