Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HLine class + examples #155

Open
wants to merge 2 commits into
base: lib_staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions examples/HLine/HLine_001/HLine_001.pde
Original file line number Diff line number Diff line change
@@ -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() {
}
75 changes: 75 additions & 0 deletions examples/HLine/HLine_002/HLine_002.pde
Original file line number Diff line number Diff line change
@@ -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();
}
39 changes: 39 additions & 0 deletions examples/HLine/HLine_003/HLine_003.pde
Original file line number Diff line number Diff line change
@@ -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();
}
209 changes: 209 additions & 0 deletions src/main/java/hype/HLine.java
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}