Skip to content

Commit

Permalink
Support third party client applictions with appropriate entry points
Browse files Browse the repository at this point in the history
  • Loading branch information
Stu Bailey committed Sep 9, 2012
1 parent 0fd882b commit 79c56a0
Show file tree
Hide file tree
Showing 8 changed files with 20,581 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/eclient.erl
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
-module(eclient).
-export([start/0,
start/3,
start/1,
start/4,
stop/0]).
-include("../include/e.hrl").
-compile([export_all]).

start()->
start(?E_DEFAULT_HOST,?E_DEFAULT_ADDRESS,?E_DEFAULT_PORT).
start([]).

start(Name,Address,Port)->
start(YawsConfOptions) when is_list(YawsConfOptions)->
start(?E_DEFAULT_HOST,?E_DEFAULT_ADDRESS,?E_DEFAULT_PORT,YawsConfOptions).

start(Name,Address,Port,YawsConfOptions)->
crypto:start(),
{ok,ParsedAddress} = inet_parse:ipv4_address(Address),
econnect:start(Name,ParsedAddress,Port).
econnect:start(Name,ParsedAddress,Port,YawsConfOptions).


stop()->
Expand Down
18 changes: 13 additions & 5 deletions src/econnect.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@

-include("../include/e.hrl").

start(_Servername,IPAddress,Port) ->
start(Servername,IPAddress,Port) ->
start(Servername,IPAddress,Port,[]).

start(_Servername,IPAddress,Port,ConfOptions) when is_list(ConfOptions) ->
code:add_patha(?YAWS_EBIN_DIRS),
file:make_dir(?YAWS_LOG_DIR),
error_logger:info_msg("Starting Embedded Yaws!~n"),
GL = [{logdir,?YAWS_LOG_DIR},
GL = [
{logdir,?YAWS_LOG_DIR},
{ebin_dir, ?YAWS_EBIN_DIRS}],
SL = [{doc_root,?YAWS_DOC_ROOT},
DocRoot = "/Users/sbailey/Git/E/www",
SL = [
{xtra_docroots,["/Users/sbailey/Git/erland/www"]},
{opaque,[{"vdir","/apps/ /Users/sbailey/Git/erland/www"}]},
{port,Port},
{listen,?YAWS_LOCAL_PORT}],
yaws:start_embedded(?YAWS_DOC_ROOT,SL,GL),
{listen,?YAWS_LOCAL_PORT}],
%% yaws:start_embedded(?YAWS_DOC_ROOT,SL,GL),
yaws:start_embedded(DocRoot,SL,GL),
self().

stop(_Servername,IPAddress,Port,Docroot) ->
Expand Down
3 changes: 3 additions & 0 deletions src/elib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ window_update_image(WindowID,ImageID,ImageData) when is_atom(WindowID),
is_binary(ImageData)->
econnect:send(eserver,{window_update_image,WindowID,ImageID,ImageData}).

launch_eclock(Width,Height)->
econnect:send(eserver,{launch_eclock,float(Width),float(Height)}).

118 changes: 118 additions & 0 deletions www/esketches/bannerSketch.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
PROCESSINGJS.COM HEADER ANIMATION
MIT License - F1lT3R/Hyper-Metrix
Native Processing Compatible
*/

// Set number of circles
int count = 1000;
// Set maximum and minimum circle size
int maxSize = 100;
int minSize = 20;
// Build float array to store circle properties
float[][] e = new float[count][5];
// Set size of dot in circle center
float ds=2;
// Selected mode switch
int sel = 0;
// Set drag switch to false
boolean dragging=false;
// If use drags mouse...
void mouseDragged(){
// Set drag switch to true
dragging=true;
}
// If user releases mouse...
void mouseReleased(){
// ..user is no-longer dragging
dragging=false;
}

// Set up canvas
void setup(){
// Frame rate
frameRate(10);
// Size of canvas (width,height)
size(1500,3000);
// Stroke/line/border thickness
strokeWeight(1);
// Initiate array with random values for circles
for(int j=0;j< count;j++){
e[j][0]=random(width); // X
e[j][1]=random(height); // Y
e[j][2]=random(minSize,maxSize); // Radius
e[j][3]=random(-.5,.5); // X Speed
e[j][4]=random(-.5,.5); // Y Speed
}
}

// Begin main draw loop (called 25 times per second)
void draw(){
// Fill background black
background(0);
// Begin looping through circle array
for (int j=0;j< count;j++){
// Disable shape stroke/border
noStroke();
// Cache diameter and radius of current circle
float radi=e[j][2];
float diam=radi/2;
// If the cursor is within 2x the radius of current circle...
if( dist(e[j][0],e[j][1],mouseX,mouseY) < radi ){
// Change fill color to green.
fill(64,187,128,100);
// Remember user has circle "selected"
sel=1;
// If user has mouse down and is moving...
if (dragging){
// Move circle to circle position
e[j][0]=mouseX;
e[j][1]=mouseY;
}
} else {
// Keep fill color blue
fill(64,128,187,100);
// User has nothing "selected"
sel=0;
}
// Draw circle
ellipse(e[j][0],e[j][1],radi,radi);
// Move circle
e[j][0]+=e[j][3];
e[j][1]+=e[j][4];


/* Wrap edges of canvas so circles leave the top
and re-enter the bottom, etc... */
if( e[j][0] < -diam ){ e[j][0] = width+diam; }
if( e[j][0] > width+diam ){ e[j][0] = -diam; }
if( e[j][1] < 0-diam ){ e[j][1] = height+diam; }
if( e[j][1] > height+diam){ e[j][1] = -diam; }

// If current circle is selected...
if (sel==1) {
// Set fill color of center dot to white..
fill(255,255,255,255);
// ..and set stroke color of line to green.
stroke(128,255,0,100);
} else {
// otherwise set center dot color to black..
fill(0,0,0,255);
// and set line color to turquoise.
stroke(64,128,128,255);
}

// Loop through all circles
for(int k=0;k< count;k++){
// If the circles are close...
if( dist(e[j][0],e[j][1],e[k][0],e[k][1]) < radi){
// Stroke a line from current circle to adjacent circle
line(e[j][0],e[j][1],e[k][0],e[k][1]);
}
}
// Turn off stroke/border
noStroke();
// Draw dot in center of circle
rect(e[j][0]-ds,e[j][1]-ds,ds*2,ds*2);
}
}
70 changes: 70 additions & 0 deletions www/js/e.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ var emsg_handle = function(tuple) {
case 'window_update_image':
windowUpdateImage(tuple);
break;
case 'launch_eclock':
launchEClock(tuple);
break;
default:
alert("The EClient sent unknown command: " + command)
}
Expand Down Expand Up @@ -79,12 +82,79 @@ var windowUpdateImage = function(tuple) {
var Image = new Ext.Component({
autoEl: { tag: 'img', width: images[ImageID].autoEl.width, height: images[ImageID].autoEl.height, src: img}
});

// images[ImageID].autoEl.src = img;
// images[ImageID].doAutoRender();
// images[ImageID].show();

windows[WindowID].remove(images[ImageID]);
windows[WindowID].add(Image);
windows[WindowID].doLayout();
images[ImageID] = Image;
};

function sketchClock(processing) {
// Override draw function, by default it will be called 60 times per second
processing.draw = function() {

// determine center and max clock arm length
var centerX = processing.width / 2, centerY = processing.height / 2;
var maxArmLength = Math.min(centerX, centerY);

function drawArm(position, lengthScale, weight) {
processing.strokeWeight(weight);
processing.line(centerX, centerY,
centerX + Math.sin(position * 2 * Math.PI) * lengthScale * maxArmLength,
centerY - Math.cos(position * 2 * Math.PI) * lengthScale * maxArmLength);
}

// erase background
processing.background(224);

var now = new Date();

// Moving hours arm by small increments
var hoursPosition = (now.getHours() % 12 + now.getMinutes() / 60) / 12;
drawArm(hoursPosition, 0.5, 5);

// Moving minutes arm by small increments
var minutesPosition = (now.getMinutes() + now.getSeconds() / 60) / 60;
drawArm(minutesPosition, 0.80, 3);

// Moving hour arm by second increments
var secondsPosition = now.getSeconds() / 60;
drawArm(secondsPosition, 0.90, 1);
}
};

function launchEClock(tuple)
{
var Width = tuple[1];
var Height = tuple[2];
canvasWindow = new Ext.Window({
title:'EClock'
,height:Height + 32 //132
,width:Width + 14 //114
,items:{
xtype: 'box',
autoEl:{
tag: 'canvas'
}
,listeners:{
render:{
scope:this
,fn:function(){
var processingInstance = new Processing(canvasWindow.items.items[0].el.dom, sketchClock);
processingInstance.size(Width,Height);

}
}
}
}
});
canvasWindow.show();
// var processingInstance = new Processing(canvasWindow.items.items[0].el.dom, sketchProc);
};

connection.onmessage = function(msg) {
var blob = msg.data;
Expand Down
Loading

0 comments on commit 79c56a0

Please sign in to comment.