r/processing • u/seoceojoe • Oct 17 '16
[PWC32] Text
Hello Everybody, this is the 32nd Weekly Processing challenge, the challenges are decided just to give you a prompt to test your skills so it can be as simple or as complicated as you have time to write!
Start Date : 17-10-2016 End Date : 23-10-2016 Post entries in the comments here.
This Weeks Challenge : Text, Use text or fonts in any way you choose.
Winners from last week : jorn600
3
Upvotes
4
u/Introscopia Oct 20 '16
train station style flipping letters. Lots of improvements that could be done on this, maybe some other time!
PFont enriquetta; int W, H; float m = 6; LBGrid theGrid; void setup(){ size(1196, 300); W = 92; H = 100; enriquetta = createFont("Enriqueta", 125); textFont( enriquetta ); textSize( 125 ); StringList sl = new StringList(); sl.append( "Hello r/Processing!" ); sl.append( "This is my [PCW32] submission." ); FloatList fl = new FloatList(); fl.append( 240 ); fl.append( 240 ); theGrid = new LBGrid( width, height, sl, fl ); } void draw(){ background( 200 ); theGrid.display(); } class LetterBox{ PVector pos; PGraphics front_top, front_bot, back_top, back_bot; float h, v, a; boolean flipping; LetterBox(PVector v, char a, char b){ pos = v; render_back( a ); cycle(); render_back( b ); } void cycle(){ front_top = createGraphics( W, round(H/2f) ); front_top.beginDraw(); front_top.image(back_top, 0, 0); front_top.endDraw(); front_bot = createGraphics( W, round(H/2f) ); front_bot.beginDraw(); front_bot.image(back_bot, 0, 0); front_bot.endDraw(); } void render_back( char c ){ back_top = createGraphics( W, round(H/2f) ); back_top.beginDraw(); back_top.textFont( enriquetta ); back_top.textSize( 125 ); back_top.textAlign( CENTER, CENTER ); back_top.fill(255); back_top.rect(0, 0, W-1, -1 + H/2f, m, m, m, m ); back_top.fill(0); back_top.text( c, W/2f, (H/2f) -0.05*H ); back_top.endDraw(); back_bot = createGraphics( W, round(H/2f) ); back_bot.beginDraw(); back_bot.textFont( enriquetta ); back_bot.textSize( 125 ); back_bot.textAlign( CENTER, CENTER ); back_bot.fill(255); back_bot.rect(0, 0, W-1, -1 + H/2f, m, m, m, m ); back_bot.fill(0); back_bot.text( c, W/2f, -0.05*H ); back_bot.endDraw(); } void begin_flip( float t ){ h = 0; v = 0; a = (2 * H) / sq( t ); flipping = true; } void display(){ if( flipping ){ v += a; h += v; if( h > H ){ this.cycle(); flipping = false; } if( h < H/2f ){ float scale = map( h, 0, H/2f, 1, 0 ); pushMatrix(); translate(pos.x, pos.y); image( back_top, 0, 0 ); image( front_bot, 0, front_top.height ); translate( 0, h ); scale( 1, scale ); image( front_top, 0, 0 ); popMatrix(); } else{ float scale = map( h, H/2f, H, 0, 1 ); pushMatrix(); translate(pos.x, pos.y); image( back_top, 0, 0 ); image( front_bot, 0, front_top.height ); translate( 0, back_top.height); scale( 1, scale ); image( back_bot, 0, 0 ); popMatrix(); } } else{ pushMatrix(); translate(pos.x, pos.y); image( front_top, 0, 0 ); image( front_bot, 0, front_top.height ); popMatrix(); } } } class LBGrid{ LetterBox[] grid; StringList messages; FloatList times; float time; LBGrid(float w, float h, StringList s, FloatList f){ messages = s; times = f; int I = floor( w / W ); int J = floor( h / H ); grid = new LetterBox[I*J]; for(int i = 0; i < grid.length; i++){ int j = floor( i / float(I) ); char a = ' ', b = ' '; if( messages.size() >= 1 ) a = ( messages.get(0).length() > i )? messages.get(0).charAt( i ) : ' '; if( messages.size() >= 2 ) b = ( messages.get(1).length() > i )? messages.get(1).charAt( i ) : ' '; grid[i] = new LetterBox( new PVector( (i-(j*I))*W, j*H ), a, b ); println( i, j, (i-(j*I))*W, j*H ); } time = times.get(0); } void display(){ for( LetterBox l : grid ) l.display(); time--; if( time <= 0 ){ messages.remove( 0 ); times.remove( 0 ); if( messages.size() == 0 ){ messages.append( random_string( grid.length ) ); times.append( 240 ); } this.new_message( messages.get(0) ); time = times.get( 0 ); this.begin_flip( 30 ); } } void begin_flip( float t ){ for( LetterBox l : grid ) l.begin_flip( t ); } void new_message( String s ){ for(int i = 0; i < grid.length; i++){ char c = ( s.length() > i )? s.charAt( i ) : ' '; grid[i].render_back( c ); } } } String random_string( int n ){ String s = ""; for(int i = 0; i < n; i++) s += char( round(random(64.501, 122.499) ) ); return s; }3
u/Barachem Oct 20 '16 edited Oct 21 '16
Relativistic Letter Chaser: Accelerate, turn to catch the number before you shrink too much. Space is reset.
final float fps = 25; final float framing = 1000/fps; final float tolerance = 3; final float jitter = 10; final float stray = 0.005*TAU; final float max_speed = 10; final float max_2 = max_speed*max_speed; final float delta = 0.02; final float side = 600; final String vull = ""; final float gen_chance = 0.05; final float eatius = 10; final float eatius_2 = eatius*eatius; final float a_ = -0.499999; final float z_ = 25 - a_; final float decrease = 0.9995; final float pig = 15; final float thresh = 0.5; final float dig = thresh*pig; final float fleeing = 0.02; final float onit = 1.01; boolean[] keyz = new boolean[6]; food soup = new food(); eater slurp = new eater(); PVector busi = new PVector(35, 550); PVector cusi = new PVector(10, 575); PVector dusi = new PVector(35, 575); PVector eusi = new PVector(60, 575); button butt_w = new button(busi, 'w'); button butt_a = new button(cusi, 'a'); button butt_s = new button(dusi, 's'); button butt_d = new button(eusi, 'd'); void setup() { size(600, 600); textSize(pig); colorMode(HSB, 1.0); textAlign(CENTER); } void draw() { background(0); butt_w.display(keyz[0]); butt_a.display(keyz[3]); butt_s.display(keyz[1]); butt_d.display(keyz[2]); stroke(0.0, 0.0, 0.0); soup.eatea(); soup.display(); slurp.eatea(); slurp.display(); soup.jittering(slurp); slurp.straying(); slurp.devour(soup); soup.genation(); while (millis() % framing > tolerance) { } } void keyPressed() { if (key == 'w' || key == 'W') keyz[0] = true; if (key == 's' || key == 'S') keyz[1] = true; if (key == 'd' || key == 'D') keyz[2] = true; if (key == 'a' || key == 'A') keyz[3] = true; if (key == ' ') keyz[4] = true; } void keyReleased() { if (key == 'w' || key == 'W') keyz[0] = false; if (key == 's' || key == 'S') keyz[1] = false; if (key == 'd' || key == 'D') keyz[2] = false; if (key == 'a' || key == 'A') keyz[3] = false; if (key == ' ') keyz[4] = false; } float abs_PV(final PVector PV) { return sqrt(PV.x*PV.x + PV.y*PV.y); } PVector scale_PV(final PVector PV, final float scalar) { return new PVector(scalar*PV.x, scalar*PV.y); } PVector unity_PV(final PVector PV) { return scale_PV(PV, 1.0/abs_PV(PV)); } PVector distan(final PVector PV_1, final PVector PV_2) { return new PVector(PV_1.x - PV_2.x, PV_1.y - PV_2.y); } float distan_2(final PVector PV_1, final PVector PV_2) { final PVector PV_3 = distan(PV_1, PV_2); return PV_3.x*PV_3.x + PV_3.y*PV_3.y; } float randomize(final float max) { return random(-max, max); } float insider(float inside) { while (inside < 0) { inside += side; } while (inside > side) { inside -= side; } return inside; } class food { final float big = pig; boolean alive = true; int dna = 0; PVector posi = new PVector(random(side), random(side)); PVector spedi = new PVector(fleeing*random(side), fleeing*random(side)); PVector texi = new PVector(0.0*big, 0.34*big); void posis() { posi = new PVector(random(side), random(side)); spedi = new PVector(randomize(fleeing*side), randomize(fleeing*side)); } void reset() { if (keyz[4] || keyz[5]) { alive = true; dna = 0; posis(); keyz[5] = false; } } void jittering(eater slurp) { final PVector flee = scale_PV(unity_PV(distan(posi, slurp.posi)), fleeing); spedi.add(flee); posi.add(spedi); posi = new PVector (insider(posi.x), insider(posi.y)); reset(); } void devoured() { if (alive) { ++dna; alive = false; } } void genation() { if (!alive) { if (random(1) < gen_chance) { alive = true; posis(); } } } void eatea() { fill(0.5, 1.0, 0.5); if (alive) { ellipse(posi.x, posi.y, big, big); } } void display() { textSize(big); if (alive) { fill(1.0, 0.0, 1.0); // translate(posi.x, posi.y); text(dna, posi.x + texi.x, posi.y + texi.y); } } food() { } } class eater { final String dna = "e"; float big = pig; float phi = random(0, TAU); float speed = 0; PVector posi = new PVector(random(side), random(side)); PVector texi = new PVector(-0.08*big, 0.28*big); void texize() { texi = new PVector(-0.08*big, 0.28*big); } void reset() { if (keyz[4] || keyz[5]) { big = pig; phi = random(0, TAU); speed = 0; posi = new PVector(random(side), random(side)); texize(); } } float relative() { return sqrt(onit - speed*speed/max_2); } void decreasing() { big -= big*(1 - decrease)*relative(); if (big < dig) { keyz[5] = true; reset(); } } void accel() { if (keyz[0]) { speed += delta*relative(); decreasing(); } if (keyz[1]) { speed -= delta*relative(); decreasing(); } if (speed >= decrease*max_speed) { speed = max_speed; } if (speed <= -max_speed) { speed = -decrease*max_speed; } } void rotal() { if (keyz[2]) { phi += stray*relative(); decreasing(); } if (keyz[3]) { phi -= stray*relative(); decreasing(); } while (phi > TAU) { phi -= TAU; } while (phi < 0) { phi += TAU; } } void straying() { decreasing(); accel(); rotal(); posi.add(new PVector(speed*cos(phi), speed*sin(phi))); posi = new PVector (insider(posi.x), insider(posi.y)); reset(); } void devour(food soup) { if (soup.alive) { if (distan_2(posi, soup.posi) < big*big) { soup.devoured(); big = sqrt(big*big + pig*pig); texize(); } } } void eatea() { fill(0, 1.0, 1.0); ellipse(posi.x, posi.y, big, big); } void display() { fill(1.0, 0.0, 1.0); textSize(big); texize(); translate(posi.x, posi.y); rotate(phi); text(dna, texi.x, texi.y); } eater() { } } class button { PVector posi = new PVector(); char letter = '-'; final PVector texi = new PVector(0.5*pig, 0.8*pig); void reposi(final PVector bosi) { posi = bosi; } void display(boolean keyz) { stroke(1.0, 0.0, 1.0); fill(0.0, 0.0, 0.0); rect(posi.x, posi.y, pig, pig); fill(1.0, 0.0, 1.0); if (keyz) { fill(1.0, 0.0, 0.5); } textSize(pig); text(letter, posi.x + texi.x, posi.y + texi.y); } button(final PVector bosi, final char retter) { posi = bosi; letter = retter; } }2
u/jorn600 Oct 20 '16
These are all the lower case letters from a to z!
String [] letters = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}; String textHolder = "test"; void setup() { size(500,500); println(letters.length); textSize(20); background(0); } void draw() { if(mousePressed == true) { if(mouseButton == LEFT) { for(int i = 0; i < 26; i++) { fill(255); text(letters[i], mouseX,mouseY); } } if(mouseButton == RIGHT) { for(int i = 0; i < 26; i++) { fill(0); text(letters[i], mouseX,mouseY); } } } }2
u/DojoGroningen Oct 20 '16
A submission by Priscilla:
void setup() { size(320,200); textSize(32); } void draw() { fill(255,0,0); text("I love priscilla",10,20); text("kei veel", 20, 50); }2
u/_Doda Oct 20 '16
//Matrix Effect char test; int textHeight, numCols; int[] startPos; void setup() { size(800,600); noStroke(); textHeight = 16; textSize(textHeight); numCols = 60; startPos = new int[numCols]; for(int i =0; i < numCols; i++) { startPos[i] = (int)random(40); } } void draw() { fill(0,15); rect(0,0,width,height); for(int i =0; i < numCols; i++) { if(startPos[i] < height) startPos[i] += textHeight-4; else startPos[i] = (int)random(40); } for(int i = 0; i<numCols; i++) { int randChar = (int)random(33,126); test = (char)randChar; fill(0,200,0); text(test, (i+1) * (width / numCols), startPos[i]); } delay(130); }2
u/thijsveebee Oct 20 '16
I made my submission in p5.js without using a canvas. I get that that's kind of on the edge of what could be considered a "processing" submission, so I'll let you guys decide whether counts or not.
Here's a link to the page.
Here's a link to the code on GitHub.
And here's the raw code:
var lexicon; var result, inputA, inputB; function setup() { noCanvas(); lexicon = new RiLexicon(); var middle = select('#middle'); inputA = createInput("Structure sentence"); inputA.style("width", "50%"); inputB = createInput("Words"); inputB.style("width", "50%"); var button = createButton("Generate!"); button.mousePressed(generateSentence); var example = createButton("Example"); example.mousePressed(useExample); result = createElement("h1", ''); middle.child(inputA); middle.child(createP('')); middle.child(inputB); middle.child(createP('')); middle.child(example); middle.child(createP('')); middle.child(button); middle.child(createP('')); middle.child(result); } function generateSentence() { var sa = new RiString(inputA.value()); var sb = new RiString(inputB.value()); var words = sb.words(); var pos = sa.pos(); var other = sb.pos(); var output = ""; for (var i = 0; i != pos.length; ++i) { var found = false; for (var j = 0; j != other.length; ++j) { if (pos[i] == other[j]) { output += words[j]; words.splice(j, 1); other.splice(j, 1); found = true; break; } } if (!found) { output += lexicon.randomWord(pos[i]); } output += ' '; } var regex = /\W/; if (regex.test(sa.charAt(sa.length() - 1))) { output = trim(output); output += sa.charAt(sa.length() - 1); } output = output.charAt(0).toUpperCase() + output.slice(1); result.html(output); } function useExample() { inputA.value("The cat in the hat!"); inputB.value("under each table a dog"); generateSentence(); }