Skip to content

Commit

Permalink
pushing to github
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Nitsch committed Jul 23, 2012
0 parents commit a6ab8cd
Show file tree
Hide file tree
Showing 14 changed files with 1,231 additions and 0 deletions.
Empty file added README.md
Empty file.
Binary file added copy_to_data/ofxAsciiArt/images/8x8.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
130 changes: 130 additions & 0 deletions copy_to_data/ofxAsciiArt/shaders/ascii.frag
@@ -0,0 +1,130 @@
#version 120

uniform sampler2D inputTexture;
uniform sampler2D asciiTexture;
uniform sampler2D hashTexture;
uniform vec2 imageSize;
uniform vec2 canvasSize;

varying float mode;
varying float contrast;
varying float depth;

const float charMapSize = 2048.0;
const float numChars = 256.0;
const vec2 fontSize = vec2(8.0, 8.0);
const vec2 hashSize = vec2(256.0, 256.0);

vec4 pix = vec4(0.0, 0.0, 0.0, 1.0);
vec2 ratio;
float colorDepth;

float packColor(vec4 color) {
return (color.r + (color.g*256.0) + (color.b*256.0*256.0) + (color.a*256.0*256.0*256.0));
}

vec4 contrastPix(float _x, float _y, float _contrast) {
float factor = (259.0 * (_contrast + 255.0)) / (255.0 * (259.0 - _contrast));
vec4 pix = texture2D(inputTexture, vec2(_x, _y));

pix.r = (factor * ((pix.r*255.0) - 128.0) + 128.0)/255.0;
pix.g = (factor * ((pix.g*255.0) - 128.0) + 128.0)/255.0;
pix.b = (factor * ((pix.b*255.0) - 128.0) + 128.0)/255.0;

return pix;
}

vec4 analyseQuads(vec2 _offset) {

// TODO: Clear these magic numbers.
float i_x = 1.0/(canvasSize.x*0.62);
float i_y = 1.0/(canvasSize.y*0.93);

float h_fs_x = (fontSize.x/2.0)/canvasSize.x;
float h_fs_y = (fontSize.y/2.0)/canvasSize.y;

vec4 lut_pix;
vec4 t_pix;
vec4 key = vec4(0.0, 0.0, 0.0, 0.0);

for(float y=_offset.y; y<_offset.y+h_fs_y; y+=i_y) {
for(float x=_offset.x; x<_offset.x+h_fs_x; x+=i_x) {
t_pix = vec4(0.0, 0.0, 0.0, 1.0);

lut_pix = contrastPix(x, y, contrast);
key.r += lut_pix.g;
lut_pix.r = (floor((lut_pix.r*255.0)/colorDepth)*colorDepth)/255.0;
lut_pix.g = (floor((lut_pix.g*255.0)/colorDepth)*colorDepth)/255.0;
lut_pix.b = (floor((lut_pix.b*255.0)/colorDepth)*colorDepth)/255.0;
t_pix += lut_pix;

lut_pix = contrastPix(x+h_fs_x, y, contrast);
key.g += lut_pix.g;
lut_pix.r = (floor((lut_pix.r*255.0)/colorDepth)*colorDepth)/255.0;
lut_pix.g = (floor((lut_pix.g*255.0)/colorDepth)*colorDepth)/255.0;
lut_pix.b = (floor((lut_pix.b*255.0)/colorDepth)*colorDepth)/255.0;
t_pix += lut_pix;

lut_pix = contrastPix(x, y+h_fs_y, contrast);
key.b += lut_pix.g;
lut_pix.r = (floor((lut_pix.r*255.0)/colorDepth)*colorDepth)/255.0;
lut_pix.g = (floor((lut_pix.g*255.0)/colorDepth)*colorDepth)/255.0;
lut_pix.b = (floor((lut_pix.b*255.0)/colorDepth)*colorDepth)/255.0;
t_pix += lut_pix;

lut_pix = contrastPix(x+h_fs_x, y+h_fs_y, contrast);
key.a += lut_pix.g;
lut_pix.r = (floor((lut_pix.r*255.0)/colorDepth)*colorDepth)/255.0;
lut_pix.g = (floor((lut_pix.g*255.0)/colorDepth)*colorDepth)/255.0;
lut_pix.b = (floor((lut_pix.b*255.0)/colorDepth)*colorDepth)/255.0;
t_pix += lut_pix;

t_pix /= 4.0;
pix += t_pix;
}
}

pix /= fontSize.x+fontSize.y;
key = floor(key)/16.0;

return key;
}

void main()
{
int m = int(mode);
colorDepth = 255.0/depth;

ivec2 ioffset = ivec2(gl_FragCoord.xy/fontSize.xy);
ioffset *= ivec2(fontSize.xy);
vec2 offset = vec2(ioffset);
offset /= canvasSize;

vec4 hashKey = analyseQuads(offset);
float index = packColor( hashKey )/256.0;

float hash_x = mod(floor(index), hashSize.x);
float hash_y = (index-hash_x)/hashSize.x;

vec4 char_pix = texture2D(hashTexture, vec2(hash_x/255.0, hash_y/255.0));
float char = floor((char_pix.g)*255.0);

vec2 pos = mod(gl_FragCoord.xy, fontSize.xy);
pos = pos / vec2(fontSize.x*numChars, fontSize.y);
pos.x += ((char*fontSize.x)/charMapSize);

vec4 ascii_pix = vec4(texture2D(asciiTexture, pos).rgb, 1.0);

if(ascii_pix.r > 0.0) {
if(m==1) {
ascii_pix.rgb = pix.rgb;
} else if(m==2) {
ascii_pix.rgb = vec3(pix.g*0.1, pix.g, pix.g*0.1);
} else if(m==3) {
float gray = (pix.r+pix.g+pix.b)/3.0;
ascii_pix.rgb = vec3(gray);
}
}

gl_FragColor = ascii_pix;
}
18 changes: 18 additions & 0 deletions copy_to_data/ofxAsciiArt/shaders/ascii.vert
@@ -0,0 +1,18 @@
#version 120

attribute float a_mode;
attribute float a_contrast;
attribute float a_depth;

varying vec2 texCoord;
varying float mode;
varying float contrast;
varying float depth;

void main()
{
mode = a_mode;
contrast = a_contrast;
depth = a_depth;
gl_Position = ftransform();
}
50 changes: 50 additions & 0 deletions example/src/gui/ofBaseGui.h
@@ -0,0 +1,50 @@
#pragma once

#include "ofxXmlSettings.h"
#include "ofConstants.h"

const ofColor
headerBackgroundColor(64),
backgroundColor(0),
textColor(255),
fillColor(128);

const int textPadding = 4;
const int defaultWidth = 200;
const int defaultHeight = 16;

class ofBaseGui{
public:
ofBaseGui(){
bGuiActive = false;
}

virtual void mouseMoved(ofMouseEventArgs & args) = 0;
virtual void mousePressed(ofMouseEventArgs & args) = 0;
virtual void mouseDragged(ofMouseEventArgs & args) = 0;
virtual void mouseReleased(ofMouseEventArgs & args) = 0;

virtual void setValue(float mx, float my, bool bCheckBounds) = 0;
virtual void draw() = 0;

void saveToFile(string filename) {
ofxXmlSettings xml;
xml.loadFile(filename);
saveToXml(xml);
xml.saveFile(filename);
}

void loadFromFile(string filename) {
ofxXmlSettings xml;
xml.loadFile(filename);
loadFromXml(xml);
}

virtual void saveToXml(ofxXmlSettings& xml) = 0;
virtual void loadFromXml(ofxXmlSettings& xml) = 0;

string name;
unsigned long currentFrame;
ofRectangle b;
bool bGuiActive;
};
5 changes: 5 additions & 0 deletions example/src/gui/ofGui.h
@@ -0,0 +1,5 @@
#pragma once

#include "ofToggle.h"
#include "ofSlider.h"
#include "ofPanel.h"

0 comments on commit a6ab8cd

Please sign in to comment.