# S.Chekanov (C) jHepWork
# show 1D histogram
from java.awt import *
from java.awt import Font
from java.util import Random
from jhplot import *
from jhplot.shapes import *
# make empty canvas in some range
c1 =HPlot("Canvas",600,400)
c1.gTitle("HShape package to draw Java 2D objects")
c1.setDrawLegend(0)
c1.setNameX("X")
c1.setNameY("Y")
c1.setRange(-4.0, 4.0, 0.0, 20.0)
c1.visible(1)
# show a line in the NDC system
line = Line(0.1,0.9, 0.2, 0.9)
line.setPosCoord("NDC")
line.setColor(Color.red)
line.setTransparency(0.5)
c1.add(line)
#show a line in the NDC system
line = Line(0.1,0.85, 0.2, 0.85);
line.setDashed(3.0);
line.setPosCoord("NDC");
line.setColor(Color.blue);
line.setTransparency(0.5);
c1.add(line);
# show dotted line in the USER system
line = Line(-2.0, 10, -1.0, 12.0)
line.setDotted(2.0)
line.setColor(Color.magenta)
line.setTransparency(0.5)
c1.add(line)
# arrow
arr = Arrow(-2, 2, -2, 10)
c1.add(arr)
# arrow in the NDC system
arr = Arrow(0.85, 0.5, 0.85, 0.7)
arr.setColor(Color.blue)
arr.setPosCoord("NDC")
stroke = BasicStroke(5.0)
arr.setStroke(stroke)
arr.setEndFilled()
c1.add(arr)
tex= Text("This is a text",-2.4, 12)
c1.add(tex)
# set a picture in the NDC system
file=SystemDir+fSep+"macros"+fSep+"examples"+fSep+"data"+fSep+"anllogo.png"
pic= Picture(0.8, 0.95, file)
pic.setPosCoord("NDC")
c1.add(pic)
cic= Circle(-0.5, 10, 2.0)
cic.setFill(1)
cic.setColor(Color.red)
cic.setTransparency(0.5)
c1.add(cic)
# filled eclipse
ele= Ellipse(-1.2, 8, 1.0, 0.9)
ele.setFill(1)
ele.setColor(Color.green)
ele.setTransparency(0.8)
c1.add(ele)
# show circle
cic=Circle(-0.9, 11, 1.5)
cic.setFill(0)
c1.add(cic)
# rectangle
rec=Rectan(0.0, 10.0, 0.9, 1.2);
rec.setFill(1);
c1.add(rec);
rec= Rectan(2.0, 3.0, 2.9, 1.6);
rec.setFill(1);
rec.setColor(Color.yellow);
rec.setTransparency(0.7);
c1.add(rec);
# set HLabel in the USER coordinate system
lab=HLabel("HLabel in USER", -2, 10);
c1.add(lab);
# set HLabel in the normilised coordinate system
lab=HLabel("HLabel in NDC", 0.5, 0.2, "NDC");
c1.add(lab);
# now show all objects
c1.update();
# export to some image (png,eps,pdf,jpeg...)
# c1.export(Editor.DocMasterName()+".png");
# jHepWork @S.Chekanov