Painter a GUI for view/control of GeoGrapy


Inherits from: Object


The Painter allows to plot the graph, update it dynamically, move the vertices with the mouse, see the actants walking. 


Control


The Painter is inteneded as a view/control element, so its methods are defined mainly for internal administration.


Note: GUIs are always deferred, so you can use SystemClock in routines involving graphics.


Creation / Class Methods


*new (graph, runner, vertices, edges, vLabels, eLabels, vDim, eDim, alpha, colFact, fontName, fontSize)

Short prose description of method.

graph - a graph instance. Default value is nil. See Graph.

runner - a runner instance. Default value is nil. See Runner.

vertices - a boolean allowing for able/disable vertices drawing. Default value is true.

edges - a boolean allowing for able/disable edges drawing. Default value is true.

vLabels - a boolean allowing for able/disable the drawing of verteices' labels. Default value is true.

eLabels - a boolean allowing for able/disable the drawing of edges' labels . Default value is true.

vDim - dimension of the  vertex rectangle. Default value is nil. It's an array.

eDim - dimension of the  edge rectangle (containing the label). Default value is nil. It's an array.

alpha - alpha value for transparency. Default value is 0.9.

colFact - a factor for visualizing number of items thru vertex color. Default value is 0.1. It means that after 10 times you reach the lightest value starting from black.

fontName - font name for vertex/edge labels. Default value is "Monaco", so you don't confuse l with I.

fontSize - font size for vertex/edge labels. Default value is 10. 

lviewdim - Dimension of the Listener visualisation rectangle.  

windowx, windowy, windowWidth, windowHeight - To control the painter window position and size 

vPosScale - for controlling the position where a vertex is visualized, in case the visualization has a different scale from the position  

(

g = Graph.new

.addVertex(200, 200, 0, "A").addVertex(1000, 600, 0, "B") 

.addEdge(1,2, 1).addEdge(2,1, 0.5) ;

r = Runner.new(g).addAndSetup(1).start(1) ;

p = Painter.new(g, r, true, true, true, true,

[400, 400],

[400, 400],

1,

1,

["Monaco", "Helvetica", "Times", "Optima", "Gill Sans"].choose,

100

)

)

// you can drag the big squares

// then:

// wait a little, it's all right

(

p.setAlpha(0.01) ;

Routine({

inf.do({ arg i ;

p.setEDim(p.eDim-5) ;

p.setVDim(p.vDim-5) ;

p.setAlpha(p.alpha+(i/3000).clip2(1)) ;

p.setFontName(["Monaco", "Helvetica", "Times", "Optima", "Gill Sans"].choose) ;

  p.setFontSize((100-i)) ;

  0.1.wait

})

}).play(SystemClock)

// still have to investigate why it rotates...

//("It's only rock'n'roll, but I like it")

)

/////// Audio

Server.local.boot ;

(

g = Graph.new ;

# x, y = [600, 400] ;

g.addVertex(x, y, 0, "p") ;

10.do({ arg i ;

g.addVertex(x, y, 0, "p") ;

g.addEdge(g.nv-2, g.nv-1, rrand(0.01, 0.1)) ;

# x, y = [100.rand*[-1,1].choose+x, 100.rand*[-1,1].choose+y] ;

if ( x > 1200, { x = x-1200}) ;

if ( y > 800, { y = y-800}) ;

if ( x < 0, { x = x.abs}) ;

if ( y < 0, { y = y.abs}) ; 

}) ;

r = Runner.new(g) ;

SlicePlayer(r).initAudio("sounds/a11wlk01.wav") ;

p = Painter(g, r, vLabels:false, eLabels:true, vDim:[10,5], colFact:0.01)

// colFact:0.01 is default, use 0.1 to see gradient workin sooner

)

// evaluate this

(

Routine({

inf.do({ arg i ;

r.addAndSetup(1).start(r.na-1) ;

g.addVertex(x, y, 0, "p") ;

g.addEdge(g.nv-2, g.nv-1, rrand(0.01, 0.1)) ;

# x, y = [100.rand*[-1,1].choose+x, 100.rand*[-1,1].choose+y] ;

if ( x > 1200, { x = 2400-x}) ;

if ( y > 800, { y = 1600-y}) ;

if ( x < 0, { x = x.abs}) ;

if ( y < 0, { y = y.abs}) ; 

2.wait

})

}).play(SystemClock)

)

r.gui // if you want to see activation/disactivation of actants 


Accessing Instance and Class Variables

eLabels

Boolean for plotting edge labels.

Default value is true.

fontSize

Return the font size.

edges

Boolean for plotting edges.

Default value is true.

vDim

Return the vertices dimensions, i.e. an array.

w

The window.

vertices

Boolean for plotting vertices.

Default value is true.

eDim

Return the edge labels dimensions, i.e. an array.

vLabels

Boolean for plotting vertex labels.

Default value is true.

statsDict

an IdentityDictionary associating to a vertexID the number of its occurences.

The counter is referred to all the actants.


colFact

The factor used to calculate the color of each vertex as a function of occurences.

Default value is 0.1.

fontName

The font name.

Default value is "Monaco".

Doing Some Task (optional)


A short bit of prose explaining something about the task.


setEdges (bool)

setVertices (bool)

setELabels (bool)

setVLabels (bool)

Set a boolean to able/disable the different GUI element.

bool - default is true .

(

g = Graph.new

.addVertex(200, 200, 0, "A").addVertex(1000, 600, 0, "B") 

.addEdge(1,2, 1).addEdge(2,1, 0.5) ;

r = Runner.new(g) ;

p = Painter.new(g, r);

r.addAndSetup(1).start(1) ;

Routine.new({

inf.do({

// why raises an error? Anyway, you grasp the idea

[

p.setEdges([true, false].choose) ;

p.setVertices([true, false].choose) ;

p.setVLabels([true, false].choose) ;

p.setELabels([true, false].choose) ;

].choose ;

1.0.wait

})

}).play(AppClock)

)


setBackground (imagePath)

Set an image as a background, still retaining transparency.

Ok with GUI object, but not with edges (depends on drawHook)

imagePath: the path



/////// The same as before

// but now starting the Mars colonization 


(

g = Graph.new ;

# x, y = [600, 400] ;

g.addVertex(x, y, 0, "p") ;

10.do({ arg i ;

g.addVertex(x, y, 0, "p") ;

g.addEdge(g.nv-2, g.nv-1, rrand(0.01, 0.1)) ;

# x, y = [100.rand*[-1,1].choose+x, 100.rand*[-1,1].choose+y] ;

if ( x > 1200, { x = x-1200}) ;

if ( y > 800, { y = y-800}) ;

if ( x < 0, { x = x.abs}) ;

if ( y < 0, { y = y.abs}) ; 

}) ;

r = Runner.new(g) ;

SlicePlayer(r).initAudio("sounds/a11wlk01.wav") ;

p = Painter(g, r, vLabels:false, eLabels:true, vDim:[3,3])

.setBackground("/Library/Desktop\ Pictures/Nature/Flowing\ Rock.jpg") ;

)

(

Routine({

inf.do({ arg i ;

r.addAndSetup(1).start(r.na-1) ;

g.addVertex(x, y, 0, "p") ;

g.addEdge(g.nv-2, g.nv-1, rrand(0.01, 0.1)) ;

# x, y = [100.rand*[-1,1].choose+x, 100.rand*[-1,1].choose+y] ;

if ( x > 1200, { x = 2400-x}) ;

if ( y > 800, { y = 1600-y}) ;

if ( x < 0, { x = x.abs}) ;

if ( y < 0, { y = y.abs}) ; 

2.wait

})

}).play(SystemClock)

)