Show basic shapes (Line, Circle, image) in the NDC system
Code: "shapes_ndc.py". Programming language: Python
DMelt Version 1. Last modified: 05/09/2015. License: Free
https://datamelt.org/code/cache/shapes_ndc_119.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
from java.awt import BasicStroke,Color
from java.util import Random
from jhplot import *
from jhplot.shapes import *
c1 =HPlot("Canvas",600,400)
c1.setGTitle("HShape package to draw Java 2D objects")
c1.visible(1)
c1.setLegend(0)
# set the range to trigger the Canvas to show up
c1.setRange(0.0, 1.0, 0.0, 1.0)
c1.update()
# 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)
c1.update()
#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);
# arrow in the NDC system
arr = Arrow(0.85, 0.2, 0.85, 0.56)
arr.setColor(Color.blue)
arr.setPosCoord("NDC")
stroke = BasicStroke(5.0)
arr.setType(2)
arr.setStroke(stroke)
c1.add(arr)
# 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)
# show circle
cic= Circle(0.5, 0.5, 0.1)
cic.setPosCoord("NDC")
cic.setFill(1)
cic.setColor(Color.red)
cic.setTransparency(0.5)
c1.add(cic)
# 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");