-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import processing.javafx.*; | ||
import micycle.pgs.*; | ||
import micycle.pgs.PGS_Coloring.ColoringAlgorithm; | ||
|
||
final int[] palette = new int[]{-3196779, -6237555, -16337744, -68513, -77824, -15985089}; | ||
PShape mesh; | ||
int millisLast; | ||
int timePeriod = 4000; // ms | ||
|
||
void setup() { | ||
size(1000, 1000, FX2D); | ||
frameRate(60); | ||
mesh = initMesh(); | ||
millisLast = millis(); | ||
} | ||
|
||
void draw() { | ||
background(0, 0, 40); | ||
//shape(mesh); | ||
randomSeed(0); | ||
var step = (float) smoothStep5(triangleWave(0, 1, millis(), timePeriod)); // oscillating alignment in [0...1] | ||
PGS_Conversion.getChildren(mesh).forEach(c -> { | ||
PShape transform; | ||
transform = PGS_Transformation.translate(c, random(-300, 300), random(-300, 300)); | ||
transform = PGS_Transformation.scale(transform, random(0.5, 2f)); | ||
transform = PGS_Transformation.rotateAroundCenter(transform, random(0, TWO_PI)); | ||
transform = PGS_Transformation.align(transform, c, step); | ||
transform.setFill(setAlpha(PGS_Conversion.getFillColor(transform), map(step, 1, 0, 0, 255))); | ||
transform.setStroke(color(0, map(step, 1, 0, 0, 255))); | ||
shape(transform); | ||
} | ||
); | ||
|
||
if (millis() - millisLast >= timePeriod && step > 0.99) { | ||
mesh = initMesh(); | ||
millisLast = millis(); | ||
} | ||
} | ||
|
||
PShape initMesh() { | ||
var segs = PGS_SegmentSet.graphMatchedSegments(PGS_PointSet.poisson(50, 50, width-50, height-50, random(15, 35))); | ||
segs = PGS_SegmentSet.filterAxisAligned(segs, radians(2)); // filter highly horizontal or vertical segments | ||
var segsShape = PGS_SegmentSet.toPShape(segs); | ||
|
||
var mesh = PGS_Voronoi.compoundVoronoi(segsShape); | ||
|
||
mesh = PGS_Meshing.simplifyMesh(mesh, 2, false); | ||
mesh = PGS_Meshing.stochasticMerge(mesh, choice(3, 5), choice(9999)); | ||
mesh = PGS_Processing.removeSmallHoles(mesh, 1e9); // remove occasional artifact | ||
mesh = PGS_Coloring.colorMesh(mesh, ColoringAlgorithm.RLF, palette); | ||
mesh = PGS_Conversion.setAllStrokeColor(mesh, color(0), 2); | ||
mesh = PGS_Meshing.smoothMesh(mesh, choice(20,200), true); | ||
|
||
|
||
return mesh; | ||
} | ||
|
||
static double triangleWave(double min, double max, double time, double timePeriod) { | ||
double amplitude = (max - min); | ||
double phase = (time / timePeriod) % 1.0; | ||
if (phase < 0.5) { | ||
return amplitude * (2 * phase) + min; | ||
} else { | ||
return amplitude * (2 - 2 * phase) + min; | ||
} | ||
} | ||
|
||
static double smoothStep5(double x) { | ||
return x * x * x * (x * (x * 6. - 15.) + 10.); | ||
} | ||
|
||
public static int setAlpha(int c, float alpha) { | ||
return (c & 16777215) | (int) alpha << 24; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import micycle.pgs.*; | ||
import micycle.pgs.color.ColorUtils; | ||
import processing.javafx.*; | ||
|
||
String shape = "egj{iC}iwikDjnkl@gudHxnbi@b_iwCnof}BnlptHvxy|H`qiwQ|bwdAi`n_@pw{pDcqijDpxelEormsChc~eBim}qCnd~hBmnoF|s{iAyz{gC`otdEsfglCb}j`@`h~c@_~cE|ytyAnzfk@zmyXvvo_A{mtb@~wnfBsi`kBdnohCabxt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isByfa~@{_ne@nrp[mym@l~cdCoqma@~}iiEqi`rApr|}Au|`wDhyhnJo}snB|goiBy}cq@rm~_Caxcq@nkne@mpxu@}prCeppi@i|luDpykAyxwdFgdez@wikfAcnfa@qrjjBku{v@edxg@kjr~@ouo_Cac_`Bc|eQ{qfb@uceXulgM_{v{Bqh`r@{eheBxcgCc|dgBgb|kAy~~tAhegFclzcDqh_M_ohr@iwxcA_loj@qmcxCpizCktb_@u`oXdx`cAiuzfH~vzcAy}{aDaaz]yiggDj}zdAk_bbDfxffBa`aaAfjlEq_puAun}Tgjiu@mhke@{lj^gq|k@_qbB{ssgDzkt{A_u}|Chl{gCieqtBg|iTa`jqHzshpCe`nxAezgE}p`Eej~m@~hmqBwdxxCdvx}@gv`rCn`ouEkrguCoplh@ytl}A|zlu@k}lvAiq~s@sj~qAfosO_cvr@rwsq@e{ya@bt|kD}xgl@tfmm@snk}Azu|mCihn_@|fzoA}xft@w`Ls}xv@ee{jBw`ex@rgjOo`|m@hxumHc_mlAfua[asze@`gwxD_`nqAv||}DoekjC`wi`GqohjA~t_kBuzmtAkx`h@{aboBitquFiecqLwzmyAa{txEap_eB}nftI~p~m@cuvc@"; | ||
PShape leaf; | ||
|
||
void setup() { | ||
size(1000, 1000, FX2D); | ||
|
||
leaf = PGS_Conversion.fromEncodedPolyline(shape); | ||
} | ||
|
||
void draw() { | ||
background(0, 0, 40); | ||
|
||
shape(moireVoronoi(leaf)); | ||
} | ||
|
||
PShape moireVoronoi(PShape shape) { | ||
var gridPoints = PGS_PointSet.squareGrid(0, 0, width, height, (10 + 181 / 10d)); | ||
var grid2 = PGS_Conversion.fromPVector(PGS_PointSet.squareGrid(0, 0, width, height, (10 + 181 / 13d))); | ||
|
||
var c = PGS_ShapePredicates.centroid(shape); | ||
var gridRotate = PGS_Transformation.rotate(grid2, c, millis() / 2000f); | ||
gridPoints.addAll(PGS_Conversion.toPVector(gridRotate)); | ||
|
||
var voronoi = PGS_Voronoi.innerVoronoi(gridPoints); | ||
var cells = PGS_Conversion.getChildren(voronoi); | ||
|
||
cells.forEach(cell -> { | ||
int id = Integer.parseInt(cell.getName()); | ||
int col = ColorUtils.sinebow(id * 0.001 * 192); | ||
cell.setFill(col); | ||
cell.setStroke(col); | ||
cell.setStrokeWeight(0.5f); | ||
}); | ||
|
||
return PGS_ShapeBoolean.intersectMesh(PGS_Conversion.flatten(cells), shape); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.