x_offset - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Game Development (https://python-forum.io/forum-11.html) +--- Thread: x_offset (/thread-14252.html) |
x_offset - Graham - Nov-21-2018 Hi All, I am just starting with Python/pygame and am playing around with shapes. I am trying to get some lines on screen as below (not dotted) ----------------- --------------- ------------ --------- I can get the y_offset to work but not the x_offset what am I missing? for y_offset in range(0, 100, 10): for x_offset in range(0, 100, 10): pygame.draw.line(screen, RED, [x_offset, 160 + y_offset], [x_offset-10, 160 + y_offset], 5)Thanks for looking RE: x_offset - Mekire - Nov-22-2018 Ask yourself, how many lines will those loops draw? The current answer is 100. You are drawing the lines you want but are also drawing 90 other lines that overlap the ones you want. You want something like this probably? x_offset = 100 for y_offset in range(0, 100, 10): start, end = [0, 160+y_offset], [x_offset-y_offset, 160+y_offset] pg.draw.line(self.screen, pg.Color("red"), start, end, 1) RE: x_offset - Graham - Nov-22-2018 Thanks for the reply, when I ran the code I got the error message Traceback (most recent call last): File "shapes.py", line 46, in <module> pg.draw.line(self.screen, pg.Color("red"), start, end, 1) NameError: name 'pg' is not defined All sorted used this code for y_offset in range(0, 100, 10): pygame.draw.line(screen, PURPLE, [0, 160 + y_offset], [190-y_offset, 160 + y_offset], 5)To get this result, After a bit more thought, this; |