In [5]:
#To install Compose. Im commenting out to avoid the output. :P
Pkg.add("Compose")
#Importing compose
using Compose
cd ~/.julia/v0.3/Compose/src/
Files to take a look at :
In [6]:
#Forms are things that have a shape.
a = rectangle()
Out[6]:
In [7]:
#Forms are a subtype of ComposeNode.
super(Compose.Form)
Out[7]:
In [8]:
#Properties are things that go along with a form. Colors etc.
fill("red")
Out[8]:
In [9]:
#Properties are again a subtype of ComposeNode.
super(Compose.Property)
Out[9]:
In [7]:
#Then there are contexts. They tell you where to draw the form and property.
context() #It has some default values for width and height specified. Contexts are things that can be drawn.
Out[7]:
In [8]:
context(0,0,1mm,3mm) #X0,Y0,width,height. You can use relative and absolute measures.
Out[8]:
In [9]:
#AAaand Context is a subtype of?
super(Compose.Context)
Out[9]:
In [10]:
#Dont worry. :P
super(Compose.Container)
Out[10]:
So you can combine all of these to create the scene graph of ComposeNodes. The root node will be a context node, which can have children being forms, properties or context.
In [11]:
context(),rectangle(),fill("red") #Newick format for trees!
Out[11]:
In [1]:
blueRect = compose(context(1/2,1/2,1w-10cm,1/2),rectangle(),fill("blue"))
In [11]:
redRect = compose(context(0,0,1,1/2),rectangle(),fill("red"),blueRect) #The compose function is used for drawing and obtaining the output.
Out[11]:
In [12]:
#You can use the introspect function to see the trees. This function may not work for everything though.
introspect(redRect)
#Triangles are properties and squares are forms.
Out[12]:
compose walks this tree and combines all these elements together.
In [14]:
type X
x::String
end
In [15]:
#Example for how to use writemime
function Base.writemime(io::IO,mime::Base.Multimedia.MIME{symbol("text/html")},x::X)
print(io,"<b>$(x.x)</b>")
end
Out[15]:
In [16]:
aa = X("Hello")
Out[16]:
In Compose, writemime calls the draw function, which takes a backend and a context and converts in into the corresponding output format. There are backends for SVG, PNG available.
In [17]:
type Y
y::String
end
In [18]:
function Base.writemime(io::IO,mime::Base.Multimedia.MIME{symbol("text/html")},x::Y)
print(io,"<script>alert(\"$(x.y)\");</script>")
end
Out[18]:
In [19]:
yy = Y("Alert!") #Press shift+enter to run this.
Out[19]:
So like that we can use writemime to make it convert to the JS we need to draw webGL stuff! I've forgotten some of what Gowda said but we'll read the code and we can get this done I think. For example, I forgot where the conversion between relative and absolute was happening. :P
In [21]:
aa
Out[21]:
In [22]:
type Cube
side::Int
end
In [3]:
Pkg.generate("Compose3D","MIT")
In [23]:
abstract Measure
In [26]:
abstract MeasureOp{n} <: Measure
In [31]:
help(MeasureOp{1})
In [7]:
srand(0)
In [ ]: