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 TypeMethodDescriptionvoiddraw(DrawingPanel panel, Graphics g) Draws the lattice.bytegetCell(int _row, int _col) Gets a lattice cell value.doublegetXMax()Gets the maximum x needed to draw this object.doublegetXMin()Gets the minimum x needed to draw this object.doublegetYMax()Gets the maximum y needed to draw this object.doublegetYMin()Gets the minimum y needed to draw this object.booleanDetermines if information is available to set min/max values.voidRandomizes the lattice values.voidrandomize(double probability) Randomizes the lattice values with the specified probability.voidresizeLattice(int _nrow, int _ncol) Resize the lattice.voidsetBlock(int row_offset, int col_offset, byte[][] val) Sets a block of cells to new values.voidsetBlock(int row_offset, int col_offset, int[][] val) Sets a block of cells to new values.voidsetCell(int _row, int _col, int val) Sets a lattice cell to a new value.voidsetCol(int row_offset, int col, byte[] val) Sets a column of cells to new values.voidsetCol(int row_offset, int col, int[] val) Sets a column of cells to new values.voidsetColorPalette(Color[] colors) Sets the color palette.voidsetIndexedColor(int i, Color color) Sets the color for a single index.voidsetMinMax(double xmin, double xmax, double ymin, double ymax) Scales this lattice to the given values in world units.voidsetRow(int row, int col_offset, byte[] val) Sets a row of cells to new values starting at the given column.voidsetRow(int row, int col_offset, int[] val) Sets a row of cells to new values starting at the given column.voidsetVisible(boolean _vis) toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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:MeasurableDetermines if information is available to set min/max values. Objects that store data should return false if data is null.- Specified by:
isMeasuredin interfaceMeasurable- Returns:
- true if min/max values are valid
-
getXMin
public double getXMin()Description copied from interface:MeasurableGets the minimum x needed to draw this object.- Specified by:
getXMinin interfaceMeasurable- Returns:
- minimum
-
getYMin
public double getYMin()Description copied from interface:MeasurableGets the minimum y needed to draw this object.- Specified by:
getYMinin interfaceMeasurable- Returns:
- minimum
-
getXMax
public double getXMax()Description copied from interface:MeasurableGets the maximum x needed to draw this object.- Specified by:
getXMaxin interfaceMeasurable- Returns:
- maximum
-
getYMax
public double getYMax()Description copied from interface:MeasurableGets the maximum y needed to draw this object.- Specified by:
getYMaxin 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
-