Package org.opensourcephysics.display2d
Class TriangularBinaryLattice
java.lang.Object
org.opensourcephysics.display2d.TriangularBinaryLattice
- All Implemented Interfaces:
Drawable
,Measurable
A TriangularBinaryLattice is an array where each array element has a value
of 0 or 1.
- Version:
- 1.0
- Author:
- Joshua Gould, Wolfgang Christian
-
Constructor Summary
ConstructorsConstructorDescriptionTriangularBinaryLattice
(int _nrow, int _ncol) Constructs a binary lattice with the given size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
draw
(DrawingPanel panel, Graphics g) Draws the lattice.byte
getCell
(int _row, int _col) Gets a lattice cell value.double
getXMax()
Gets the maximum x needed to draw this object.double
getXMin()
Gets the minimum x needed to draw this object.double
getYMax()
Gets the maximum y needed to draw this object.double
getYMin()
Gets the minimum y needed to draw this object.boolean
Determines if information is available to set min/max values.void
Randomizes the lattice values.void
randomize
(double probability) Randomizes the lattice values with the specified probability.void
resizeLattice
(int _nrow, int _ncol) Resize the lattice.void
setBlock
(int row_offset, int col_offset, byte[][] val) Sets a block of cells to new values.void
setBlock
(int row_offset, int col_offset, int[][] val) Sets a block of cells to new values.void
setCell
(int _row, int _col, int val) Sets a lattice cell to a new value.void
setCol
(int row_offset, int col, byte[] val) Sets a column of cells to new values.void
setCol
(int row_offset, int col, int[] val) Sets a column of cells to new values.void
setColorPalette
(Color[] colors) Sets the color palette.void
setIndexedColor
(int i, Color color) Sets the color for a single index.void
setMinMax
(double xmin, double xmax, double ymin, double ymax) Scales this lattice to the given values in world units.void
setRow
(int row, int col_offset, byte[] val) Sets a row of cells to new values starting at the given column.void
setRow
(int row, int col_offset, int[] val) Sets a row of cells to new values starting at the given column.void
setVisible
(boolean _vis) toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.opensourcephysics.display.Drawable
isInteractive
-
Constructor Details
-
TriangularBinaryLattice
public TriangularBinaryLattice(int _nrow, int _ncol) Constructs a binary lattice with the given size.- Parameters:
_nrow
- the number of rows_ncol
- the number of columns
-
-
Method Details
-
resizeLattice
public void resizeLattice(int _nrow, int _ncol) Resize the lattice.- Parameters:
_nx
- number of x sites_ny
- number of y sites
-
setVisible
public void setVisible(boolean _vis) -
isMeasured
public boolean isMeasured()Description copied from interface:Measurable
Determines if information is available to set min/max values. Objects that store data should return false if data is null.- Specified by:
isMeasured
in interfaceMeasurable
- Returns:
- true if min/max values are valid
-
getXMin
public double getXMin()Description copied from interface:Measurable
Gets the minimum x needed to draw this object.- Specified by:
getXMin
in interfaceMeasurable
- Returns:
- minimum
-
getYMin
public double getYMin()Description copied from interface:Measurable
Gets the minimum y needed to draw this object.- Specified by:
getYMin
in interfaceMeasurable
- Returns:
- minimum
-
getXMax
public double getXMax()Description copied from interface:Measurable
Gets the maximum x needed to draw this object.- Specified by:
getXMax
in interfaceMeasurable
- Returns:
- maximum
-
getYMax
public double getYMax()Description copied from interface:Measurable
Gets the maximum y needed to draw this object.- Specified by:
getYMax
in interfaceMeasurable
- Returns:
- minimum
-
randomize
public void randomize()Randomizes the lattice values. -
randomize
public void randomize(double probability) Randomizes the lattice values with the specified probability. A probability of 1 indicates that all cells will be occupied.- Parameters:
probability
- the probability of a site being occupied, between 0.0 and 1.0.
-
draw
Draws the lattice. -
setMinMax
public void setMinMax(double xmin, double xmax, double ymin, double ymax) Scales this lattice to the given values in world units.- Parameters:
xmin
-xmax
-ymin
-ymax
-
-
setBlock
public void setBlock(int row_offset, int col_offset, int[][] val) Sets a block of cells to new values. A cell is set to 1 if the value is >0; the cell is set to zero otherwise- Parameters:
row_offset
-col_offset
-val
- the array of values
-
setBlock
public void setBlock(int row_offset, int col_offset, byte[][] val) Sets a block of cells to new values. A cell is set to 1 if the value is >0; the cell is set to zero otherwise- Parameters:
row_offset
-col_offset
-val
- the array of values
-
setCol
public void setCol(int row_offset, int col, int[] val) Sets a column of cells to new values. A cell is set to 1 if the value is > 0; the cell is set to zero otherwise- Parameters:
row_offset
-col
-val
- the array of values
-
setCol
public void setCol(int row_offset, int col, byte[] val) Sets a column of cells to new values. A cell is set to 1 if the value is > 0; the cell is set to zero otherwise- Parameters:
row_offset
-col
-val
- the array of values
-
setRow
public void setRow(int row, int col_offset, int[] val) Sets a row of cells to new values starting at the given column. A cell is set to 1 if the value is >0; the cell is set to zero otherwise- Parameters:
row
-col_offset
- the colum offsetval
- the value
-
setRow
public void setRow(int row, int col_offset, byte[] val) Sets a row of cells to new values starting at the given column. A cell is set to 1 if the value is >0; the cell is set to zero otherwise- Parameters:
row
-col_offset
- the colum offsetval
- the value
-
setCell
public void setCell(int _row, int _col, int val) Sets a lattice cell to a new value. A cell should take on a value of 0 or 1.- Parameters:
_row
-_col
-val
-
-
getCell
public byte getCell(int _row, int _col) Gets a lattice cell value. Cell values are zero or one.- Parameters:
_row
-_col
-- Returns:
- the cell value.
-
setColorPalette
Sets the color palette. The color at the 0th index of the array is set to the zero color.- Parameters:
colors
-
-
setIndexedColor
Sets the color for a single index.- Parameters:
i
- the value to set the color for.color
-
-
toString
-