Functions_GUI - NoaAizer/OOP_Ex1 GitHub Wiki

This class is an implementation of functions interface.
It's consisting of a collection (Array List in our project) of functions.
The class have an array of colors, in which it will draw the functions.

The functions-

It implements all the functions of a collection (size, isEmpty, contains, Iterator, both toArray functions, add, remove, containsAll,addAll,removeAll,retainAll,clear)

Constructors:
A default constructor that creates an empty new collection

initFromFile- init a new collection of functions from a given file name. IOException if the file does not exists of unreadable (wrong format)

saveToFile- write to a given file name. IOException if the file is not writable

drawFunctions (that gets all the parameters: width, height, rx, ry, resolution)- draws all the functions in the collection in a GUI window using the given parameters for the GUI window and the range & resolution.
       width- the width of the window, in pixels
       height - the height of the window, in pixels
       rx - the range of the horizontal axis
       ry- the range of the vertical axis
       resolution - the number of samples with in rx: the X_step = rx/resolution

drawFunctions (that reads from a Json file, using Gson)- draws all the functions in the collection in a GUI window using the given JSON file (the file with all the parameters for the GUI window).

  • Note: if the file is not readable or in wrong format, the functions should use default values.

Default drawFunctions- draws all the functions using default GUI parameters (width=1000, height= 600, x_Range(-10,10), y_Range (-5,15), resolution -200).

E.g-
For the default values, the output would be:

    1. java.awt.Color[r=0,g=0,b=255] f(x)= plus(-1.0x^4 +2.4x^2 +3.1,+0.1x^5 -1.2999999999999998x +5.0)
    1. java.awt.Color[r=0,g=255,b=255] f(x)= plus(div(1.0x +1.0,mul(mul(1.0x +3.0,+1.0x -2.0),1.0x -4.0)),2.0)
    1. java.awt.Color[r=255,g=0,b=255] f(x)= div(plus(-1.0x^4 +2.4x^2 +3.1,+0.1x^5 -1.2999999999999998x +5.0),-1.0x^4 +2.4x^2 +3.1)
    1. java.awt.Color[r=255,g=200,b=0] f(x)= -1.0x^4 +2.4x^2 +3.1
    1. java.awt.Color[r=255,g=0,b=0] f(x)= 0.1x^5 -1.2999999999999998x +5.0
    1. java.awt.Color[r=0,g=255,b=0] f(x)= max(max(max(max(plus(-1.0x^4 +2.4x^2 +3.1,+0.1x^5 -1.2999999999999998x +5.0),plus(div(1.0x +1.0,mul(mul(1.0x +3.0,1.0x -2.0),1.0x -4.0)),2.0)),div(plus(-1.0x^4 +2.4x^2 +3.1,0.1x^5 -1.2999999999999998x +5.0),-1.0x^4 +2.4x^2 +3.1)),-1.0x^4 +2.4x^2 +3.1),0.1x^5 -1.2999999999999998x +5.0)
    1. java.awt.Color[r=255,g=175,b=175] f(x)= min(min(min(min(plus(-1.0x^4 +2.4x^2 +3.1,+0.1x^5 -1.2999999999999998x +5.0),plus(div(1.0x +1.0,mul(mul(1.0x +3.0,1.0x -2.0),1.0x -4.0)),2.0)),div(plus(-1.0x^4 +2.4x^2 +3.1,0.1x^5 -1.2999999999999998x +5.0),-1.0x^4 +2.4x^2 +3.1)),-1.0x^4 +2.4x^2 +3.1),0.1x^5 -1.2999999999999998x +5.0)

The graph will look like this:

graph for example

⚠️ **GitHub.com Fallback** ⚠️