From 005fb2151261735ac359c5b1e939155b78aacfbe Mon Sep 17 00:00:00 2001 From: DonoG Date: Mon, 24 Sep 2018 22:49:31 +1000 Subject: [PATCH 1/2] Add files via upload --- examples/HLine/HLine_001/HLine_001.pde | 32 +++++++++++ examples/HLine/HLine_002/HLine_002.pde | 75 ++++++++++++++++++++++++++ examples/HLine/HLine_003/HLine_003.pde | 39 ++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 examples/HLine/HLine_001/HLine_001.pde create mode 100644 examples/HLine/HLine_002/HLine_002.pde create mode 100644 examples/HLine/HLine_003/HLine_003.pde diff --git a/examples/HLine/HLine_001/HLine_001.pde b/examples/HLine/HLine_001/HLine_001.pde new file mode 100644 index 00000000..9263be66 --- /dev/null +++ b/examples/HLine/HLine_001/HLine_001.pde @@ -0,0 +1,32 @@ +import hype.*; + +HDrawablePool pool; + +void setup() { + size(640,640); + H.init(this).background(#242424); + + pool = new HDrawablePool(100); + pool.autoAddToStage() + .add(new HLine(0, 0, 0,20)) + .onCreate( + new HCallback() { + public void run(Object obj) { + HLine d = (HLine) obj; + d + .position(width/2,height/2,(int)random(width), (int)random(height)) + .strokeWeight(1) + .stroke(#999999) + ; + } + } + ) + .requestAll() + ; + + H.drawStage(); + noLoop(); +} + +void draw() { +} \ No newline at end of file diff --git a/examples/HLine/HLine_002/HLine_002.pde b/examples/HLine/HLine_002/HLine_002.pde new file mode 100644 index 00000000..62eb95cb --- /dev/null +++ b/examples/HLine/HLine_002/HLine_002.pde @@ -0,0 +1,75 @@ +import hype.*; +import hype.extended.behavior.HOscillator; +import hype.extended.layout.HGridLayout; + +HDrawablePool pool; +HOscillator o; +HOscillator o2; + +void setup() { + size(640, 640, P3D); + H.init(this).background(#242424).use3D(true); + + o = new HOscillator() + .property(H.Z) + .range(-120, 0) + .speed(2) + .freq(1) + .currentStep(4) + .waveform(H.EASE) + ; + + o2 = new HOscillator() + .property(H.Z) + .range(0, 120) + .speed(0.7F) + .freq(2) + .currentStep(39) + .waveform(H.SINE) + ; + + pool = new HDrawablePool(400); + pool.autoAddToStage() + .add(new HLine(0, 0, 0, 0, 0, 32)) + .layout( + new HGridLayout() + .startX(16) + .startY(16) + .spacing(32, 32) + .cols(20) + ) + .onCreate( + new HCallback() { + public void run(Object obj) { + HLine d = (HLine) obj; + int i = pool.currentIndex(); + d + .strokeWeight((i+1)%4) + .stroke(#999999) + ; + } + } + ) + .requestAll() + ; +} + +void draw() { + o.nextRaw(); //get oscillator values + o2.nextRaw(); + for (HDrawable d : pool) + { + if (d instanceof HLine) { + HLine l = (HLine)d; + l + .x1(o2.curr()) + .x2(o.curr()) + .y1(o.curr()) + .y2(o2.curr()) + .z1(o2.curr()) + .z2(o.curr()) + ; + } + } + H.drawStage(); +} \ No newline at end of file diff --git a/examples/HLine/HLine_003/HLine_003.pde b/examples/HLine/HLine_003/HLine_003.pde new file mode 100644 index 00000000..cf5b5726 --- /dev/null +++ b/examples/HLine/HLine_003/HLine_003.pde @@ -0,0 +1,39 @@ +import hype.*; +import hype.extended.layout.HSphereLayout; +import hype.extended.colorist.HColorPool; + +HSphereLayout layout; +HColorPool colors; + +void setup() { + size(640, 640, P3D); + H.init(this).background(#242424).use3D(true); + + layout = new HSphereLayout().loc(width/2, height/2, 0).radius(200).rotate(true); + layout.useProportional().detail(13); + + colors = new HColorPool().add(H.RED).add(H.GREEN); + + H.add(new HSphere().size(50).loc(width/2, height/2, 0).anchorAt(H.CENTER)); + + for (int i=0; i<320; i++) { + PVector loc = layout.getNextPoint(); + HLine line = new HLine(width/2, height/2, 0, loc.x, loc.y, loc.z); + line.stroke(H.WHITE); + line.strokeWeight(i%3.0F); + line.gradient(colors); + H.add(line); + } +} + +void draw() { + if (mousePressed) { + translate(width/2, height/2); + rotateX(map(mouseY, 0, height, -(TWO_PI/2), TWO_PI/2)); + rotateY(map(mouseX, 0, width, -(TWO_PI/2), TWO_PI/2)); + translate(-width/2, -height/2); + } + + lights(); + H.drawStage(); +} \ No newline at end of file From 4a5efbe03f11738931cdb482c2e865be8b3b1b30 Mon Sep 17 00:00:00 2001 From: DonoG Date: Mon, 24 Sep 2018 22:51:06 +1000 Subject: [PATCH 2/2] Adding HLine --- src/main/java/hype/HLine.java | 209 ++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 src/main/java/hype/HLine.java diff --git a/src/main/java/hype/HLine.java b/src/main/java/hype/HLine.java new file mode 100644 index 00000000..f83c278b --- /dev/null +++ b/src/main/java/hype/HLine.java @@ -0,0 +1,209 @@ +package hype; + +import hype.extended.colorist.HColorPool; +import processing.core.PConstants; +import processing.core.PGraphics; +import processing.core.PVector; + +import static processing.core.PApplet.*; + +//public class HLine extends HDrawable { +public class HLine extends HDrawable3D { + private float x1 = 0, x2 = 0, y1 = 100, y2 = 100, z1 = 0, z2 = 0; + private HColorPool colors; + + public HLine() { + } + + public float x1() { + return x1; + } + + public float x2() { + return x2; + } + + public float y1() { + return y1; + } + + public float y2() { + return y2; + } + + public float z1() { + return z1; + } + + public float z2() { + return z2; + } + + public HLine(float startx, float starty, float endx, float endy) { + x1 = startx; + y1 = starty; + x2 = endx; + y2 = endy; + } + + public HLine(float startx, float starty, float startz, float endx, float endy, float endz) { + x1 = startx; + y1 = starty; + z1 = startz; + x2 = endx; + y2 = endy; + z2 = endz; + } + + public HLine position(float startx, float starty, float endx, float endy) { + x1 = startx; + y1 = starty; + x2 = endx; + y2 = endy; + return this; + } + + public HLine position(float startx, float starty, float startz, float endx, float endy, float endz) { + x1 = startx; + y1 = starty; + z1 = startz; + x2 = endx; + y2 = endy; + z2 = endz; + return this; + } + + public HLine position(HDrawable a, HDrawable b) { + x1 = a.x(); + x2 = b.x(); + y1 = a.y(); + y2 = b.y(); + z1 = a.z(); + z2 = b.z(); + return this; + } + + public HLine position(PVector a, PVector b) { + x1 = a.x; + x2 = b.x; + y1 = a.y; + y2 = b.y; + z1 = a.z; + z2 = b.z; + return this; + } + + + public HLine x1(float f) { + x1=f; + return this; + } + + public HLine x2(float f) { + x2=f; + return this; + } + + public HLine y1(float f) { + y1=f; + return this; + } + + public HLine y2(float f) { + y2=f; + return this; + } + + public HLine z1(float f) { + z1=f; + return this; + } + + public HLine z2(float f) { + z2=f; + return this; + } + + public HLine gradient(HColorPool c) { + colors = c; + return this; + } + + @Override + public HLine createCopy() { + HLine copy = new HLine(); + copy.x1 = x1; + copy.x2 = x2; + copy.y1 = y1; + copy.y2 = y2; + copy.z1 = z1; + copy.z2 = z2; + if (colors != null) copy.colors = colors; + copy.copyPropertiesFrom(this); + return copy; + } + + + @Override + public void draw(PGraphics g, boolean usesZ, + float drawX, float drawY, float alphaPc + ) { + applyStyle(g, alphaPc); + + if (usesZ) { + if (colors == null) { + g.line(x1, y1, z1, x2, y2, z2); + } else { +// gradient + int max = colors.size(); + int clr = colors.getColorAt(0); + g.beginShape(PConstants.LINES); + g.stroke(clr); + g.vertex(x1, y1, z1); + for (int index = 1; index < max-1; index++) { + float pc = (float)index / (max); + clr = colors.getColorAt(index); + float x = lerp(x1, x2, pc); + float y = lerp(y1, y2, pc); + float z = lerp(z1, z2, pc); + g.stroke(clr); + g.vertex(x, y, z); + g.stroke(clr); + g.vertex(x, y, z); + } + clr = colors.getColorAt(max-1); + g.stroke(clr); + g.vertex(x2, y2, z2); + g.endShape(); +// end gradient + } + } else { + if (colors == null) { + g.line(x1, y1, x2, y2); + } else { + //gradient + int max = colors.size(); + int clr = colors.getColorAt(0); + g.beginShape(PConstants.LINES); + g.stroke(clr); + g.vertex(x1, y1); + for (int index = 1; index < max-1; index++) { + float pc = (float)index / (max); + clr = colors.getColorAt(index); + float x = lerp(x1, x2, pc); + float y = lerp(y1, y2, pc); + g.stroke(clr); + g.vertex(x, y); + g.stroke(clr); + g.vertex(x, y); + } + clr = colors.getColorAt(max-1); + g.stroke(clr); + g.vertex(x2, y2); + g.endShape(); +// end gradient + } + } + } +} +