The above video goes away if you are a member and logged in, so log in now!

 Would you like to get all the newest Gaming News fromQJ.NET in your email each day? Want to learn more about the team who brings you the QJ news?

This is a discussion on Quadratic Functions within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Im writing a program to graph quadratic functions in lua. Code: white = Color.new(255, 255, 255) a = 1 b ...

 Tweet

Im writing a program to graph quadratic functions in lua.

Code:
```   white = Color.new(255, 255, 255)
a = 1
b = 2
c = 3
X = (b/2 * a) * -1
Y = a * X ^ 2 + b * X + c
screen:fillRect(X, Y, 2, 2, white)
Times1 = Y
Times2 = 0
Times3 = Y
Times4 = 0
while true do
if Times3 ~= Times4 then
Times2 = Times2 + 1
X = X + 1
Y = a * X ^ 2 + b * X + c
screen:fillRect(X, Y, 2, 2, white)
end

if Times1 ~= Times2 then
Times2 = Times2 + 1
X = X - 1
Y = a * X ^ 2 + b * X + c
screen:fillRect(X, Y, 2, 2, white)
end

screen.waitVblankStart()
screen.flip()
end```
thats what I have so far. It is suppose to plot the points for right now, I want to have it graph and plt the curves etc. I cant seem to get this to work tho...

2. Your better off using something like this :

Code:
```System.usbDiskModeActivate()
white = Color.new(255, 255, 255)
blue = Color.new(0, 0, 255)
a = 1
b = 2
c = 3

while true do
X = -240
oldY = nil

-- X Axis
screen:drawLine(0, 136, 480, 136, white)
-- Y Axis
screen:drawLine(240, 0, 240, 272, white)

while X ~= 240 do

Y = a * X ^ 2 + b * X + c

if oldY ~= nil then
screen:drawLine(X + 240, -oldY + 136, X + 1 + 240, -Y + 136, blue)
end

oldY = Y
X = X + 1
end

screen.waitVblankStart()
screen.flip()
screen:clear()

break
end

end```
The program loops through the X values of -240 to 240 (the screen is 480 pixels wide), then finds the appropriate Y value for each and makes a line.

4. I made a grapher too, simple, and in C, but may be of reference...
C/C++ Coding for my Math homework lol

But making one yourself is a great learning experience =)

So, I'll have a look throw your code and give some comments, but won't really be able to give the code examples in Lua, as Lua is a loss to me =)

Just looking through quickly, the main problem you're going to hit is multiple values of Y. You seem to be getting the previous X Y and the current X Y and drawing a line between them. If you input a simple circle algorithm (x^2 + y^2 = r^2), that means that there will be previous X Y Y and current X Y Y and I don't know how you'd handle that off the top of my head.

I'll have a look at the rest of the code soon.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

All times are GMT -8. The time now is 03:37 PM.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY