Package geomerative
Class RG
- java.lang.Object
-
- geomerative.RG
-
- All Implemented Interfaces:
processing.core.PConstants
public class RG extends java.lang.Object implements processing.core.PConstants
RG is a static class containing all the states, modes, etc.. Geomerative is mostly used by calling RG methods. e.g. RShape s = RG.getEllipse(30, 40, 80, 80)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RG.FontNotLoadedException
static class
RG.LibraryNotInitializedException
static class
RG.NoPathInitializedException
-
Field Summary
Fields Modifier and Type Field Description static int
ADAPTATIVE
ADAPTATIVE segmentator minimizes the number of segments avoiding perceptual artifacts like angles or cusps.static int
BYELEMENTINDEX
The adaptor adapts the shape to a particular shape by adapting each of the groups elements indices.static int
BYELEMENTPOSITION
The adaptor adapts the shape to a particular shape by adapting each of the groups elements positions.static int
BYPOINT
The adaptor adapts the shape to a particular shape by adapting each of the groups points.static boolean
ignoreStyles
static int
UNIFORMLENGTH
UNIFORMLENGTH segmentator is the slowest segmentator and it segments the curve on segments of equal length.static int
UNIFORMSTEP
UNIFORMSTEP segmentator is the fastest segmentator and it segments the curve based on a constant value of the step of the curve parameter, or on the number of segments wanted.static boolean
useFastClip
-
Fields inherited from interface processing.core.PConstants
ADD, ALPHA, ALT, AMBIENT, ARC, ARGB, ARROW, BACKSPACE, BASELINE, BEVEL, BEZIER_VERTEX, BLEND, BLUR, BOTTOM, BOX, BREAK, BURN, CENTER, CHATTER, CHORD, CLAMP, CLOSE, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CURVE_VERTEX, CUSTOM, DARKEST, DEG_TO_RAD, DELETE, DIAMETER, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ASYNC_SAVEFRAME, DISABLE_BUFFER_READING, DISABLE_DEPTH_MASK, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_KEY_REPEAT, DISABLE_NATIVE_FONTS, DISABLE_OPENGL_ERRORS, DISABLE_OPTIMIZED_STROKE, DISABLE_STROKE_PERSPECTIVE, DISABLE_STROKE_PURE, DISABLE_TEXTURE_MIPMAPS, DODGE, DOWN, DXF, ELLIPSE, ENABLE_ASYNC_SAVEFRAME, ENABLE_BUFFER_READING, ENABLE_DEPTH_MASK, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_KEY_REPEAT, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_ERRORS, ENABLE_OPTIMIZED_STROKE, ENABLE_STROKE_PERSPECTIVE, ENABLE_STROKE_PURE, ENABLE_TEXTURE_MIPMAPS, ENTER, EPSILON, ERODE, ESC, EXCLUSION, FX2D, GIF, GRAY, GROUP, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LANDSCAPE, LEFT, LIGHTEST, LINE, LINE_LOOP, LINE_STRIP, LINES, LINUX, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MODELVIEW, MOVE, MULTIPLY, NORMAL, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PATH, PDF, PERSPECTIVE, PI, PIE, platformNames, POINT, POINTS, POLYGON, PORTRAIT, POSTERIZE, PROBLEM, PROJECT, PROJECTION, QUAD, QUAD_BEZIER_VERTEX, QUAD_STRIP, QUADRATIC_VERTEX, QUADS, QUARTER_PI, RAD_TO_DEG, RADIUS, RECT, REPEAT, REPLACE, RETURN, RGB, RIGHT, ROUND, SCREEN, SHAPE, SHIFT, SOFT_LIGHT, SPAN, SPHERE, SPOT, SQUARE, SUBTRACT, SVG, TAB, TARGA, TAU, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, UP, VERTEX, WAIT, WHITESPACE, WINDOWS, X, Y, Z
-
-
Constructor Summary
Constructors Constructor Description RG()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static RShape
adapt(RShape shp, RShape path)
Adapt a shape along the curve of another shape.static void
beginShape()
Begin to create a shape.static void
bezierVertex(float cx1, float cy1, float cx2, float cy2, float x, float y)
Add a bezierVertex to the shape.static void
breakShape()
static void
breakShape(int endMode)
Begin a new path in the current shape.static RShape
centerIn(RShape grp, processing.core.PGraphics g)
static RShape
centerIn(RShape grp, processing.core.PGraphics g, float margin)
static RShape
createShape(RPoint[][] points)
Create a shape from an array of point arrays.static RShape
diff(RShape a, RShape b)
Binary difference between two shapes.static void
endShape()
static void
endShape(processing.core.PGraphics g)
End the shape being created and draw it to the screen or the PGraphics passed as parameter.static RShape
getEllipse(float x, float y, float w)
static RShape
getEllipse(float x, float y, float w, float h)
Get an ellipse as a shape object.static RShape
getLine(float x1, float y1, float x2, float y2)
Get a line as a shape object.static RShape
getRect(float x, float y, float w)
static RShape
getRect(float x, float y, float w, float h)
Get an rectangle as a shape object.static RShape
getRing(float x, float y, float widthBig, float widthSmall)
Get a ring as a shape object.static RShape
getShape()
End the shape being created and get it as an object.static RShape
getStar(float x, float y, float widthBig, float widthSmall, int spikes)
Get a star as a shape object.static RShape
getText(java.lang.String text)
static RShape
getText(java.lang.String text, java.lang.String font, int size, int align)
Get the shape corresponding to a text.static void
ignoreStyles()
static void
ignoreStyles(boolean value)
Ignore the styles of the shapes when drawing and use the Processing style methods.static void
init(processing.core.PApplet _parent)
Initialize the library.static boolean
initialized()
static RShape
intersection(RShape a, RShape b)
Binary intersection between two shapes.static RFont
loadFont(java.lang.String fontFile)
Load and get the font object that can be used in the textFont method.static RShape
loadShape(java.lang.String filename)
Load a shape object from a file.static RShape
polygonize(RShape shp)
Polygonize a shape.static void
saveShape(java.lang.String filename, RShape shape)
Save a shape object to a file.static void
setAdaptor(int adptorType)
Use this to set the adaptor type.static void
setAdaptorLengthOffset(float adptorLengthOffset)
Use this to set the adaptor length offset.static void
setAdaptorScale(float adptorScale)
Use this to set the adaptor scaling.static void
setDpi(int _dpi)
Use this to set the resolution of the display.static void
setPolygonizer(int segmenterMethod)
Use this to set the polygonizer type.static void
setPolygonizerAngle(float angle)
Use this to set the segmentator angle tolerance for the ADAPTATIVE segmentator and set the segmentator to ADAPTATIVE.static void
setPolygonizerLength(float length)
Use this to set the segmentator length for the UNIFORMLENGTH segmentator and set the segmentator to UNIFORMLENGTH.static void
setPolygonizerStep(float step)
Use this to set the segmentator step for the UNIFORMSTEP segmentator and set the segmentator to UNIFORMSTEP.static void
shape(RShape shp)
static void
shape(RShape shp, float x, float y)
static void
shape(RShape shp, float x, float y, float w, float h)
Draw a shape to a given position on the screen.static RShape[]
split(RShape shp, float t)
Split a shape along the curve length in two parts.static void
text(java.lang.String text)
Draw text to the screen using the font set using the textFont method.static void
textFont(RFont font, int size)
Set the font object to be used in all text calls.static RShape
union(RShape a, RShape b)
Binary union between two shapes.static void
vertex(float x, float y)
Add a vertex to the shape.static RShape
xor(RShape a, RShape b)
Binary xor between two shapes.
-
-
-
Field Detail
-
ignoreStyles
public static boolean ignoreStyles
-
useFastClip
public static boolean useFastClip
-
BYPOINT
public static final int BYPOINT
The adaptor adapts the shape to a particular shape by adapting each of the groups points. This can cause deformations of the individual elements in the group.- See Also:
- Constant Field Values
-
BYELEMENTPOSITION
public static final int BYELEMENTPOSITION
The adaptor adapts the shape to a particular shape by adapting each of the groups elements positions. This mantains the proportions of the shapes.- See Also:
- Constant Field Values
-
BYELEMENTINDEX
public static final int BYELEMENTINDEX
The adaptor adapts the shape to a particular shape by adapting each of the groups elements indices. This mantains the proportions of the shapes.- See Also:
- Constant Field Values
-
ADAPTATIVE
public static int ADAPTATIVE
ADAPTATIVE segmentator minimizes the number of segments avoiding perceptual artifacts like angles or cusps. Use this in order to have polygons and meshes with the fewest possible vertices.
-
UNIFORMLENGTH
public static int UNIFORMLENGTH
UNIFORMLENGTH segmentator is the slowest segmentator and it segments the curve on segments of equal length. This can be useful for very specific applications when for example drawing incrementaly a shape with a uniform speed.
-
UNIFORMSTEP
public static int UNIFORMSTEP
UNIFORMSTEP segmentator is the fastest segmentator and it segments the curve based on a constant value of the step of the curve parameter, or on the number of segments wanted. This can be useful when segmpointsentating very often a Shape or when we know the amount of segments necessary for our specific application.
-
-
Method Detail
-
loadFont
public static RFont loadFont(java.lang.String fontFile)
Load and get the font object that can be used in the textFont method.- Parameters:
fontFile
- the filename of the font to be loaded- Returns:
- RFont, the font object
-
text
public static void text(java.lang.String text)
Draw text to the screen using the font set using the textFont method.- Parameters:
text
- the string to be drawn on the screen
-
textFont
public static void textFont(RFont font, int size)
Set the font object to be used in all text calls.- Parameters:
font
- the font object to be setsize
- the size of the font
-
getText
public static RShape getText(java.lang.String text, java.lang.String font, int size, int align)
Get the shape corresponding to a text. Use the textFont method to select the font and size.- Parameters:
font
- the filename of the font to be loadedtext
- the string to be createdsize
- the size of the font to be usedalign
- the alignment. Use RG.CENTER, RG.LEFT or RG.RIGHT- Returns:
- RShape, the shape created
-
getText
public static RShape getText(java.lang.String text)
-
shape
public static void shape(RShape shp, float x, float y, float w, float h)
Draw a shape to a given position on the screen.- Parameters:
shp
- the shape to be drawnx
- the horizontal coordinatey
- the vertical coordinatew
- the width with which we draw the shapeh
- the height with which we draw the shape
-
shape
public static void shape(RShape shp, float x, float y)
-
shape
public static void shape(RShape shp)
-
createShape
public static RShape createShape(RPoint[][] points)
Create a shape from an array of point arrays.
-
loadShape
public static RShape loadShape(java.lang.String filename)
Load a shape object from a file.- Parameters:
filename
- the SVG file to be loaded. Must be in the data directory
-
saveShape
public static void saveShape(java.lang.String filename, RShape shape)
Save a shape object to a file.- Parameters:
filename
- the SVG file to be saved.shape
- the shape to be saved.
-
beginShape
public static void beginShape()
Begin to create a shape.
-
breakShape
public static void breakShape(int endMode)
Begin a new path in the current shape. Can only be called inside beginShape() and endShape().- Parameters:
endMode
- if called with RG.CLOSE it closes the current path before starting the new one.
-
breakShape
public static void breakShape()
-
vertex
public static void vertex(float x, float y)
Add a vertex to the shape. Can only be called inside beginShape() and endShape().- Parameters:
x
- the x coordinate of the vertexy
- the y coordinate of the vertex
-
bezierVertex
public static void bezierVertex(float cx1, float cy1, float cx2, float cy2, float x, float y)
Add a bezierVertex to the shape. Can only be called inside beginShape() and endShape().- Parameters:
cx1
- the x coordinate of the first control pointcy1
- the y coordinate of the first control pointcx2
- the x coordinate of the second control pointcy2
- the y coordinate of the second control pointx
- the x coordinate of the end pointy
- the y coordinate of the end point
-
endShape
public static void endShape(processing.core.PGraphics g)
End the shape being created and draw it to the screen or the PGraphics passed as parameter.- Parameters:
g
- the canvas on which to draw. By default it draws on the screen
-
endShape
public static void endShape()
-
getShape
public static RShape getShape()
End the shape being created and get it as an object.
-
getEllipse
public static RShape getEllipse(float x, float y, float w, float h)
Get an ellipse as a shape object.- Parameters:
x
- x coordinate of the center of the shapey
- y coordinate of the center of the shapew
- width of the ellipseh
- height of the ellipse- Returns:
- RShape, the shape created
-
getEllipse
public static RShape getEllipse(float x, float y, float w)
-
getLine
public static RShape getLine(float x1, float y1, float x2, float y2)
Get a line as a shape object.- Parameters:
x1
- x coordinate of the first point of the liney1
- y coordinate of the first point of the linex2
- x coordinate of the last point of the liney2
- y coordinate of the last point of the line- Returns:
- RShape, the shape created
-
getRect
public static RShape getRect(float x, float y, float w, float h)
Get an rectangle as a shape object.- Parameters:
x
- x coordinate of the top left corner of the shapey
- y coordinate of the top left of the shapew
- width of the rectangleh
- height of the rectangle- Returns:
- RShape, the shape created
-
getRect
public static RShape getRect(float x, float y, float w)
-
getStar
public static RShape getStar(float x, float y, float widthBig, float widthSmall, int spikes)
Get a star as a shape object.- Parameters:
x
- x coordinate of the center of the shapey
- y coordinate of the center of the shapewidthBig
- the outter width of the star polygonwidthSmall
- the inner width of the star polygonspikes
- the amount of spikes on the star polygon- Returns:
- RShape, the shape created
-
getRing
public static RShape getRing(float x, float y, float widthBig, float widthSmall)
Get a ring as a shape object.- Parameters:
x
- x coordinate of the center of the shapey
- y coordinate of the center of the shapewidthBig
- the outter width of the ring polygonwidthSmall
- the inner width of the ring polygon- Returns:
- RShape, the shape created
-
split
public static RShape[] split(RShape shp, float t)
Split a shape along the curve length in two parts.- Parameters:
shp
- the shape to be splitedt
- the proportion (a value from 0 to 1) along the curve where to split- Returns:
- RShape[], an array of shapes with two elements, one for each side of the split
-
adapt
public static RShape adapt(RShape shp, RShape path)
Adapt a shape along the curve of another shape.- Parameters:
shp
- the shape to be adaptedpath
- the shape which curve will be followed- Returns:
- RShape the adapted shape
-
polygonize
public static RShape polygonize(RShape shp)
Polygonize a shape.- Parameters:
shp
- the shape to be polygonized- Returns:
- RShape, the polygonized shape
-
init
public static void init(processing.core.PApplet _parent)
Initialize the library. Must be called before any call to Geomerative methods. Must be called by passing the PApplet. e.g. RG.init(this)
-
initialized
public static boolean initialized()
-
setDpi
public static void setDpi(int _dpi)
Use this to set the resolution of the display. This specifies the Dots Per Inch of the display.- Parameters:
_dpi
- the dots per inch of the display
-
diff
public static RShape diff(RShape a, RShape b)
Binary difference between two shapes.- Parameters:
a
- first shape to operate onb
- second shape to operate on- Returns:
- RShape, the result of the operation
-
union
public static RShape union(RShape a, RShape b)
Binary union between two shapes.- Parameters:
a
- first shape to operate onb
- second shape to operate on- Returns:
- RShape, the result of the operation
-
intersection
public static RShape intersection(RShape a, RShape b)
Binary intersection between two shapes.- Parameters:
a
- first shape to operate onb
- second shape to operate on- Returns:
- RShape, the result of the operation
-
xor
public static RShape xor(RShape a, RShape b)
Binary xor between two shapes.- Parameters:
a
- first shape to operate onb
- second shape to operate on- Returns:
- RShape, the result of the operation
-
ignoreStyles
public static void ignoreStyles(boolean value)
Ignore the styles of the shapes when drawing and use the Processing style methods.- Parameters:
value
- value to which the ignoreStyles state should be set
-
ignoreStyles
public static void ignoreStyles()
-
setAdaptor
public static void setAdaptor(int adptorType)
Use this to set the adaptor type.- Parameters:
adptorType
- it can be RG.BYPOINT, RG.BYELEMENTPOSITION or RG.BYELEMENTINDEX
-
setAdaptorScale
public static void setAdaptorScale(float adptorScale)
Use this to set the adaptor scaling. This scales the transformation of the adaptor.- Parameters:
adptorScale
- the scaling coefficient
-
setAdaptorLengthOffset
public static void setAdaptorLengthOffset(float adptorLengthOffset) throws java.lang.RuntimeException
Use this to set the adaptor length offset. This specifies where to start adapting the group to the shape.- Parameters:
adptorLengthOffset
- the offset along the curve of the shape. Must be a value between 0 and 1;- Throws:
java.lang.RuntimeException
-
setPolygonizer
public static void setPolygonizer(int segmenterMethod)
Use this to set the polygonizer type.- Parameters:
segmenterMethod
- can be RG.ADAPTATIVE, RG.UNIFORMLENGTH or RG.UNIFORMSTEP.
-
setPolygonizerAngle
public static void setPolygonizerAngle(float angle)
Use this to set the segmentator angle tolerance for the ADAPTATIVE segmentator and set the segmentator to ADAPTATIVE.- Parameters:
angle
- an angle from 0 to PI/2 it defines the maximum angle between segments.
-
setPolygonizerLength
public static void setPolygonizerLength(float length)
Use this to set the segmentator length for the UNIFORMLENGTH segmentator and set the segmentator to UNIFORMLENGTH.- Parameters:
length
- the length of each resulting segment.
-
setPolygonizerStep
public static void setPolygonizerStep(float step)
Use this to set the segmentator step for the UNIFORMSTEP segmentator and set the segmentator to UNIFORMSTEP.- Parameters:
step
- if a float from +0.0 to 1.0 is passed it's considered as the step, else it's considered as the number of steps. When a value of 0.0 is used the steps will be calculated automatically depending on an estimation of the length of the curve. The special value -1 is the same as 0.0 but also turning of the segmentation of lines (faster segmentation).
-
-