Created
June 5, 2018 02:28
-
-
Save skishida/e75b63daeefb7fbea99212e50d813978 to your computer and use it in GitHub Desktop.
Smarthair demo program
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
// SmartHair DBC DEMO Program | |
public static enum VIEWMODE{ | |
rect, | |
circle, | |
animation, | |
shade; | |
private static VIEWMODE[] vals = values(); | |
public VIEWMODE next() | |
{ | |
return vals[(this.ordinal()+1) % vals.length]; | |
} | |
}; | |
VIEWMODE viewmode = VIEWMODE.rect; | |
float distance = 100.0; | |
final float MIN_DISTANCE = 100.0; | |
float angle = 0.0; | |
void setup() { | |
size(1920, 1080, P3D); | |
frameRate(120); | |
smooth(); | |
noStroke(); | |
rectMode(CENTER); | |
} | |
void drawRect() { | |
fill(255, 204); | |
rect(mouseX, height/2, mouseY/2+10, mouseY); | |
fill(255, 204); | |
int inverseX = width-mouseX; | |
int inverseY = height-mouseY; | |
rect(inverseX, height/2, (inverseY/2)+10, mouseY); | |
} | |
void drawCircle() { | |
fill(255); | |
ellipse(mouseX, mouseY, distance, distance); | |
} | |
void drawAnim() { | |
fill(255); | |
pushMatrix(); | |
translate(mouseX, mouseY); | |
rotate(angle); | |
rect(0, 0, 50, 1000); | |
rotate(angle*1.7); | |
rect(0, 0, 50, 1000); | |
popMatrix(); | |
} | |
void drawShade() { | |
float b = angle % PI; | |
if ( b > 1.0 ) b = 2.0 - b; | |
background(b*255); | |
} | |
void draw() { | |
String title = String.format("[frame %d] [fps %6.2f]", frameCount, frameRate); | |
surface.setTitle(title); | |
background(0); | |
// update param. | |
distance -= (distance / MIN_DISTANCE) / 0.1; | |
if(distance <= MIN_DISTANCE) distance = MIN_DISTANCE; | |
angle += 0.01; | |
switch (viewmode) { | |
case rect: | |
drawRect(); | |
break; | |
case circle: | |
drawCircle(); | |
break; | |
case animation: | |
drawAnim(); | |
break; | |
case shade: | |
drawShade(); | |
break; | |
default: | |
break; | |
} | |
} | |
void mousePressed() { | |
if (mouseButton == LEFT) { | |
distance = 500; | |
} else if (mouseButton == RIGHT) { | |
viewmode = viewmode.next(); | |
} else { | |
} | |
} | |
void mouseWheel(MouseEvent event) { | |
float e = event.getCount(); | |
println(e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment