Question

Create a new Python script called LinePlot.py in PyCharm and try the following code: import pygame pygame.init() screen_width = 1000 screen_height = 800 screen = pygame.display.set_mode((screen_width, screen_height)) done = False white = pygame.Color(255, 255, 255) green = pygame.Color(0, 255, 0) xoriginoffset = int(screen.get_width() / 2) yoriginoffset = int(screen.get_height() / 2) while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True # x axis for x in range(-500, 500): screen.set_at((x + xoriginoffset, yoriginoffset), green) # y axis for y in range(-400, 400): screen.set_at((xoriginoffset, y + yoriginoffset), green) for x in range(-500, 500): y = 2 * x + 4 #LINE EQUATION screen.set_at((x + xoriginoffset, y + yoriginoffset), white) pygame.display.update() pygame.quit() This is plotting the same original line equation we used in the DESMOS exercise in Chapter 2, Let's Start Drawing (you can see it in Figure 2.3, albeit upside down because y is flipped). The xoriginoffset and yoriginoffset values are used to place the origin in the center of the window. You will notice that there are also green pixels drawn to show the $\mathrm{x}$ and $\mathrm{y}$ axes. The result is shown in Figure 3.2: (Figure can't copy) Besides the image being upside down in the Python render, the line is the same as the one drawn in DESMOS. Or is it? With high-resolution monitors, it can be difficult to see the issue that arises from plotting a line in this way. So, let's try something else.

   Create a new Python script called LinePlot.py in PyCharm and try the following code:
import pygame
pygame.init()
screen_width = 1000
screen_height = 800
screen = pygame.display.set_mode((screen_width,
screen_height))
done = False
white = pygame.Color(255, 255, 255)
green = pygame.Color(0, 255, 0)
xoriginoffset = int(screen.get_width() / 2)
yoriginoffset = int(screen.get_height() / 2)
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
# x axis
for x in range(-500, 500):
screen.set_at((x + xoriginoffset, yoriginoffset),
green)
# y axis
for y in range(-400, 400):
screen.set_at((xoriginoffset, y + yoriginoffset),
green)
for x in range(-500, 500):
y = 2 * x + 4 #LINE EQUATION
screen.set_at((x + xoriginoffset, y +
yoriginoffset), white)
pygame.display.update()
pygame.quit()
This is plotting the same original line equation we used in the DESMOS exercise in Chapter 2, Let's Start Drawing (you can see it in Figure 2.3, albeit upside down because y is flipped). The xoriginoffset and yoriginoffset values are used to place the origin in the center of the window. You will notice that there are also green pixels drawn to show the $\mathrm{x}$ and $\mathrm{y}$ axes. The result is shown in Figure 3.2:
(Figure can't copy)
Besides the image being upside down in the Python render, the line is the same as the one drawn in DESMOS. Or is it? With high-resolution monitors, it can be difficult to see the issue that arises from plotting a line in this way. So, let's try something else.
Show more…
Mathematics for Game Programming and Computer Graphics: Explore the essential mathematics for creating, rendering, and manipulating 3D virtual environments
Mathematics for Game Programming and Computer Graphics: Explore the essential mathematics for creating, rendering, and manipulating 3D virtual environments
Penny de Byl 1st Edition
Chapter 3, Problem 1 ↓

Instant Answer

verified

Step 1

py.  Show more…

Show all steps

lock
AceChat toggle button
Close icon
Ace pointing down

Please give Ace some feedback

Your feedback will help us improve your experience

Thumb up icon Thumb down icon
Thanks for your feedback!
Profile picture
Create a new Python script called LinePlot.py in PyCharm and try the following code: import pygame pygame.init() screen_width = 1000 screen_height = 800 screen = pygame.display.set_mode((screen_width, screen_height)) done = False white = pygame.Color(255, 255, 255) green = pygame.Color(0, 255, 0) xoriginoffset = int(screen.get_width() / 2) yoriginoffset = int(screen.get_height() / 2) while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True # x axis for x in range(-500, 500): screen.set_at((x + xoriginoffset, yoriginoffset), green) # y axis for y in range(-400, 400): screen.set_at((xoriginoffset, y + yoriginoffset), green) for x in range(-500, 500): y = 2 * x + 4 #LINE EQUATION screen.set_at((x + xoriginoffset, y + yoriginoffset), white) pygame.display.update() pygame.quit() This is plotting the same original line equation we used in the DESMOS exercise in Chapter 2, Let's Start Drawing (you can see it in Figure 2.3, albeit upside down because y is flipped). The xoriginoffset and yoriginoffset values are used to place the origin in the center of the window. You will notice that there are also green pixels drawn to show the $\mathrm{x}$ and $\mathrm{y}$ axes. The result is shown in Figure 3.2: (Figure can't copy) Besides the image being upside down in the Python render, the line is the same as the one drawn in DESMOS. Or is it? With high-resolution monitors, it can be difficult to see the issue that arises from plotting a line in this way. So, let's try something else.
Close icon
Play audio
Feedback
Powered by NumerAI
Need help? Use Ace
Ace is your personal tutor. It breaks down any question with clear steps so you can learn.
Start Using Ace
Ace is your personal tutor for learning
Step-by-step explanations
Instant summaries
Summarize YouTube videos
Understand textbook images or PDFs
Study tools like quizzes and flashcards
Listen to your notes as a podcast
Continue solving this problem
Create a free account to:
  • View full step-by-step solution
  • Ask follow-up questions with Ace AI
  • Save progress and study later
Continue Free
Numerade

Get step-by-step video solution
from top educators

Continue with Clever
or



By creating an account, you agree to the Terms of Service and Privacy Policy
Already have an account? Log In

A free answer
just for you

Watch the video solution with this free unlock.

Numerade

Log in to watch this video
...and 100,000,000 more!


EMAIL

PASSWORD

OR
Continue with Clever