Created
November 12, 2013 15:38
-
-
Save dimkir/7433001 to your computer and use it in GitHub Desktop.
Processing sketch : angularMotion
This file contains hidden or 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
import geomerative.*; | |
//import org.apache.batik.svggen.font.table.*; | |
//import org.apache.batik.svggen.font.*; | |
Mover2 m; | |
//final int C_MOVER_COUNT = 11; | |
String sentence = "I dag våknet min mann opp, rullet over, og sa God morgen, vakker. Han har ikke ringt meg at i måneder, men som jeg var i ferd med å svare, innså jeg at han snakket til hans kjæledyr skilpadde, ikke meg. FML"; | |
Mover2[] rotators; | |
//int CW = 800; | |
//int CH = 600; | |
// | |
int CW = 1600; | |
int CH = 900; | |
void setup(){ | |
//size(CW, CH, P3D); | |
size(1600, 900); | |
setupFont(); | |
RG.init(this); | |
setupColor(); | |
String[] words = split(sentence, " "); | |
rotators = new Mover2[words.length]; | |
for(int i = 0 ; i < rotators.length ; i++){ | |
rotators[i] = new Mover2(random(width), random(height), 10 + random(10), randomColor(), words[i]); | |
} | |
} | |
void draw(){ | |
// translate(310,100, -720); | |
// rotateY(11.4); | |
background(0); | |
applyAngularAccelerationToRotators(0.0001); | |
updateRotators(); | |
drawRotators(); | |
} | |
void applyAngularAccelerationToRotators(float aa){ | |
for(Mover2 m : rotators){ | |
m.applyAngularAcceleration(aa); | |
} | |
} | |
void updateRotators(){ | |
boolean isHovered; | |
for(Mover2 m: rotators){ | |
isHovered = m.hasXY(mouseX, mouseY); | |
m.setHovered(isHovered); | |
if ( !isHovered) m.update(); | |
} | |
} | |
void drawRotators(){ | |
for(Mover2 m: rotators){ | |
m.draw(); | |
} | |
} |
This file contains hidden or 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
void setupColor(){ | |
colorMode(HSB, 100); | |
} | |
color randomColor(){ | |
return color(random(100), 100, 100); | |
} |
This file contains hidden or 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
/* | |
Implementation of angular mover | |
*/ | |
class Mover2 | |
{ | |
// location | |
PVector location; | |
PVector velocity; | |
PVector acceleration; | |
// angular velocity | |
float angle; | |
float angle_velocity; | |
float angle_acceleration; | |
// properties of the item | |
float mRadius; | |
color mFillColor; | |
color mTextColor = #FFFFFF; | |
// text properties | |
RShape shape; | |
// scale parameters for perlin noise | |
float noize; | |
float dt = 0.01; | |
// word | |
String mWord; | |
// transparency | |
int C_BOX_FILL_ALPHA = 100; | |
// box dimensions | |
int C_CONTEXT_HEIGHT = 200; | |
int C_CONTEXT_WIDTH = 300; | |
int C_BOX_PADDING = 15; | |
Mover2(float x, float y, float radius, color c, String word){ | |
// set location related vars | |
location = new PVector(x, y); | |
acceleration = new PVector(0,0); | |
velocity = PVector.random2D(); | |
velocity.mult(1 + random(2)); | |
// set properties | |
mRadius = radius; | |
mFillColor = c; | |
// set angle data | |
angle = random(360); | |
angle_velocity = random(0.00, 0.05); | |
// setup letter | |
// "COPRGTB.TTF" "FreeSans.ttf" | |
shape = RG.getText(word, "COPRGTB.TTF", 72, CENTER); | |
// setup text | |
mWord = word; | |
// set noise | |
noize = random(1000); | |
} | |
float nextNoise(){ | |
noize += dt; | |
return noise(noize); | |
} | |
void draw(){ | |
fill(mFillColor); | |
pushMatrix(); | |
translate(location.x, location.y); | |
pushMatrix(); | |
scale(nextNoise()); | |
rotate(angle); | |
rectMode(CENTER); | |
// if ( isHovered() ){ | |
// noFill(); | |
// } | |
shape.draw(); | |
stroke(0); | |
rect(0,0, mRadius * 2, mRadius * 2); | |
popMatrix(); | |
if ( isHovered() ){ | |
drawContextMenu(); | |
} | |
popMatrix(); | |
} | |
void applyAngularAcceleration(float accel){ | |
angle_acceleration += accel; | |
} | |
void applyAcceleration(PVector force){ | |
acceleration.add(force); | |
} | |
void update(){ | |
// update regular velocity | |
velocity.add(acceleration); | |
acceleration.mult(0); | |
location.add(velocity); | |
if ( isOutsideScreen(location) ){ | |
velocity.mult(-1); | |
} | |
// update angular velocity | |
angle_velocity += angle_acceleration; | |
angle_acceleration = 0.0f; | |
angle += angle_velocity; | |
} | |
private boolean isOutsideScreen(PVector v){ | |
if ( v.x >= width || v.x < 0 || v.y > height || v.y < 0){ | |
return true; | |
} | |
return false; | |
} | |
private boolean mIsHovered = false; | |
private boolean isHovered(){ | |
return mIsHovered; | |
} | |
private void setHovered(boolean isHovered){ | |
mIsHovered = isHovered; | |
} | |
boolean hasXY(float x, float y){ | |
float dx = location.x - x; | |
float dy = location.y - y; | |
float squareDist = dx * dx + dy * dy; | |
float dst = sqrt(squareDist); | |
if ( dst <= mRadius * 4 ){ | |
return true; | |
} | |
else{ | |
return false; | |
} | |
} | |
void drawContextMenu(){ | |
pushMatrix(); | |
scaleViaNoise(); | |
rectMode(CORNER); | |
fill(mFillColor, C_BOX_FILL_ALPHA); | |
rect(0,0, C_CONTEXT_WIDTH - C_BOX_PADDING, C_CONTEXT_HEIGHT); | |
fill(mTextColor); | |
text("this is text which should fit into the rectnagle box which is there", | |
C_BOX_PADDING, C_BOX_PADDING, | |
C_CONTEXT_WIDTH - 2 * C_BOX_PADDING, | |
C_CONTEXT_HEIGHT- 2 * C_BOX_PADDING ); | |
popMatrix(); | |
} | |
float t2 = random(1000); | |
float dt2 = 0.05; | |
void scaleViaNoise(){ | |
t2 += dt2; | |
scale((sin(t2) /2) + 1); | |
} | |
} |
This file contains hidden or 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
int C_TRANSLATION_FONT_SIZE = 24; | |
void setupFont(){ | |
PFont f = createFont("FreeSans.ttf", C_TRANSLATION_FONT_SIZE); | |
textFont(f); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment