In [5]:
#To install Compose. Im commenting out to avoid the output. :P
Pkg.add("Compose")
#Importing compose
using Compose


INFO: Nothing to be done

cd ~/.julia/v0.3/Compose/src/

Files to take a look at :

  • Compose.jl contains the top level code.
  • form.jl contains the code which is used to create shape primitives.
  • measure.jl is what is used to define measurements. It takes care of making absolute measures and relative measures work together.

In [6]:
#Forms are things that have a shape.
a = rectangle()


Out[6]:
Form{RectanglePrimitive}([RectanglePrimitive(Point(Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),0.0,0.0),Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),0.0,0.0)),Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),1.0,0.0),Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),0.0,1.0))])

In [7]:
#Forms are a subtype of ComposeNode.
super(Compose.Form)


Out[7]:
ComposeNode

In [8]:
#Properties are things that go along with a form. Colors etc.
fill("red")


Out[8]:
Property{FillPrimitive}([FillPrimitive(RGB{Float64}(1.0,0.0,0.0))])

In [9]:
#Properties are again a subtype of ComposeNode.
super(Compose.Property)


Out[9]:
ComposeNode

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]:
Compose.Container

In [10]:
#Dont worry. :P
super(Compose.Container)


Out[10]:
Compose.ComposeNode

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]:
(Compose.Context(Compose.BoundingBox(Compose.Measure{Compose.MeasureNil,Compose.MeasureNil}(0.0,Compose.MeasureNil(),Compose.MeasureNil(),0.0,0.0),Compose.Measure{Compose.MeasureNil,Compose.MeasureNil}(0.0,Compose.MeasureNil(),Compose.MeasureNil(),0.0,0.0),Compose.Measure{Compose.MeasureNil,Compose.MeasureNil}(0.0,Compose.MeasureNil(),Compose.MeasureNil(),1.0,0.0),Compose.Measure{Compose.MeasureNil,Compose.MeasureNil}(0.0,Compose.MeasureNil(),Compose.MeasureNil(),0.0,1.0)),Compose.UnitBox{Void,Void,Void,Void}(nothing,nothing,nothing,nothing,Compose.Measure{Compose.MeasureNil,Compose.MeasureNil}(0.0,Compose.MeasureNil(),Compose.MeasureNil(),0.0,0.0),Compose.Measure{Compose.MeasureNil,Compose.MeasureNil}(0.0,Compose.MeasureNil(),Compose.MeasureNil(),0.0,0.0),Compose.Measure{Compose.MeasureNil,Compose.MeasureNil}(0.0,Compose.MeasureNil(),Compose.MeasureNil(),0.0,0.0),Compose.Measure{Compose.MeasureNil,Compose.MeasureNil}(0.0,Compose.MeasureNil(),Compose.MeasureNil(),0.0,0.0)),Compose.Rotation(0.0,Compose.Point(Compose.Measure{Compose.MeasureNil,Compose.MeasureNil}(0.0,Compose.MeasureNil(),Compose.MeasureNil(),0.5,0.0),Compose.Measure{Compose.MeasureNil,Compose.MeasureNil}(0.0,Compose.MeasureNil(),Compose.MeasureNil(),0.0,0.5))),nothing,Compose.ListNull{Compose.ComposeNode}(),0,false,false,false,false,nothing,nothing,0.0),Compose.Form{Compose.RectanglePrimitive}([Compose.RectanglePrimitive(Compose.Point(Compose.Measure{Compose.MeasureNil,Compose.MeasureNil}(0.0,Compose.MeasureNil(),Compose.MeasureNil(),0.0,0.0),Compose.Measure{Compose.MeasureNil,Compose.MeasureNil}(0.0,Compose.MeasureNil(),Compose.MeasureNil(),0.0,0.0)),Compose.Measure{Compose.MeasureNil,Compose.MeasureNil}(0.0,Compose.MeasureNil(),Compose.MeasureNil(),1.0,0.0),Compose.Measure{Compose.MeasureNil,Compose.MeasureNil}(0.0,Compose.MeasureNil(),Compose.MeasureNil(),0.0,1.0))]),Compose.Property{Compose.FillPrimitive}([Compose.FillPrimitive(Color.RGB{Float64}(1.0,0.0,0.0))]))

In [1]:
blueRect = compose(context(1/2,1/2,1w-10cm,1/2),rectangle(),fill("blue"))


compose not defined
while loading In[1], in expression starting on line 1

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]:
writemime (generic function with 21 methods)

In [16]:
aa = X("Hello")


Out[16]:
Hello

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]:
writemime (generic function with 22 methods)

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]:
Hello

In [22]:
type Cube
    side::Int
end

In [3]:
Pkg.generate("Compose3D","MIT")


INFO: Initializing Compose3D repo: /home/rohitvarkey/.julia/v0.3/Compose3D
INFO: Generating LICENSE.md
INFO: Generating README.md
INFO: Generating src/Compose3D.jl
INFO: Generating test/runtests.jl
INFO: Generating .travis.yml
INFO: Generating .gitignore
INFO: Committing Compose3D generated files

In [23]:
abstract Measure

In [26]:
abstract MeasureOp{n} <: Measure

In [31]:
help(MeasureOp{1})


INFO: Loading help data...
DataType   : MeasureOp{1}
  supertype: Measure

In [7]:
srand(0)

In [ ]: