Skip to content

Commit 23c4212

Browse files
author
HarshKhandeparkar
committed
docs: add docs for RealComplexSpace
1 parent e37519b commit 23c4212

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ A *Real Renderer* is a fancy name for a class that is exported by this package.
4545
#### List of Real Renderers
4646
- [`RealRenderer`](#realrenderer)
4747
- [`RealLineGraph`](#reallinegraph)
48+
- [`RealComplexSpace`](#realcomplexspace)
4849
4950
#### `RealRenderer`
5051
This is the base class. It does not have any specific use. It can only display a blank graph with coordinate axes on it. See [example](https://harshkhandeparkar.github.io/gpujs-real-renderer).
@@ -98,7 +99,7 @@ e.g.: `RealRenderer.draw().reset().startRender()`
9899
99100
- `reset()`: Resets the pixels on the graph to a blank graph with the coordinate axes.
100101
101-
#### RealLineGraph
102+
#### `RealLineGraph`
102103
This Real Renderer extends the `RealRenderer` class and can be used to plot generated data in real-time as the data is obtained. This can be used to analyze data that changes over time.
103104
104105
This is a generic line graph with straight lines joining points. (The first point connects to the origin)
@@ -143,6 +144,65 @@ The returned object contains two properties `x` and `y` each of which are arrays
143144
144145
- `reset()`: This is the same method as that of `RealRenderer` but it also resets the axes and the plots.
145146
147+
#### `RealComplexSpace`
148+
This Real Renderer extends the `RealRenderer` class and can be used to plot changing complex numbers. A few watched numbers are plotted every time the renderer renders. A callback is fired just before the render, to change the numbers.
149+
150+
This class provides another class, `Complex`, to define, manipulate, add, subtract, multiply etc. complex numbers.
151+
152+
See [example](https://harshkhandeparkar.github.io/gpujs-real-renderer).
153+
154+
##### Properties (Read-Only)
155+
- `Complex` (*Class*): A class for defining and manipulating complex numbers. Has the following methods.
156+
- `constructor(r, theta)`: Default constructor with r(modulus) and theta(argument) (polar form of a complex number).
157+
- `getCartesianForm()`: A method that returns the x and y coordinates of the same complex number in cartesian form, as an array of the form `[x, y]`.
158+
- `getPolarForm()`: A method that returns the r(modulus) and theta(argument) of the same complex number in polar form, as an array of the form `[r, theta]`.
159+
- `add(addedNum)`: Adds another number `addedNum` which is another object of `Complex` class to itself and returns the output. Also edits itself.
160+
- `subtract(subtractedNum)`: Subtracts another number `subtractedNum` which is another object of `Complex` class from itself and returns the output. Also edits itself.
161+
- `multiply(multipliedNum)`: Multiplies another number `multipliedNum` which is another object of `Complex` class to itself and returns the output. Also edits itself.
162+
- `divide(dividedNum)`: Divides itself by another number `dividedNum` which is another object of `Complex` class and returns the output. Also edits itself.
163+
- `conjugate()`: Modifies itself to be its own complex conjugate and returns itself.
164+
- `reciprocal()`: Modifies itself to be its own reciprocal and returns itself.
165+
NOTE: All of the above methods except `getCartesianForm` and `getPolarForm` are chainable.
166+
167+
- `watchedNumbers`(*Object*): An object that stores all the *watched* complex numbers, ie the ones that are plotted during each render. This object is of the form
168+
```js
169+
{
170+
name1: { // Here, `name` is any arbitrary name, the property does not matter
171+
number: Complex(), // The complex number
172+
show: boolean, // Whether to show/plot the number or not
173+
persistent: boolean, // Whether the number's older locations will persist on the graph or disappear in the next render (see example)
174+
interpolate: boolean, // Whether to interpolate (ie draw a line between this number and another number, see example for use cases)
175+
interpolateTo: Complex(), // Draws a line between this number and the watched number
176+
attributes: Object // optional user-defined attributes
177+
},
178+
name2: {...same}
179+
}
180+
```
181+
182+
##### Options
183+
Since this is a child class of `RealRenderer`, all the options of `RealRender` are applicable here as well.
184+
Apart from those, the following are additional options that can be passed on to the constructor.
185+
186+
- `brushSize`(*Number*) (Default: `1`): Determines the size of the brush, i.e. the radius of the plotted points, in pixels.
187+
188+
- `brushColor`(*Array*) (Default: `[1, 1, 1]`): The color of the brush, i.e. the plotted points.
189+
190+
- `lineThickness`(*Number*) (Default: `0.05`): The thickness of the line joining the different plotted points, in coordinate units with scaleFactors.
191+
192+
- `lineColor`(*Array*) (Default: `[0, 0.5, 0]`): The color of the line joining different points.
193+
194+
- `changeNumbers(watchedNumbers, time)`(*Function*) (Default: `function(watchedNumbers) {return watchedNumbers}`): A callback that is fired at the start of every render. The first argument is the object of watched numbers (see above properties), the second argument is the internal `time` variable which can be used to keep track of render time.
195+
The expected return type is a similar object(but can be changed).
196+
197+
##### Methods
198+
Since this is a child class of `RealRenderer`, all the methods of `RealRender` are available here as well.
199+
Apart from these methods, the following new methods are also available and are chainable too.
200+
201+
- `watch(name, number, show = true, persistent = true, interpolate = false, interpolateTo = null, attributes = {})`: Add a new number to the `watchedNumbers`, see properties above.
202+
203+
- `clearWatched()`: Clears all watched numbers.
204+
205+
- `plot(number)`: Plots a single `number`, an instance of `Complex` class.
146206
147207
****
148208
### Thank You!

0 commit comments

Comments
 (0)