Show basic shapes (Line, Circle, image)
Source code name: "shapes.py"
Programming language: Python
Topic: Graphics/2D
DMelt Version 1. Last modified: 05/09/2015. License: Pro
https://datamelt.org/code/cache/shapes_5578.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 Font,BasicStroke,Color
from java.util import Random
from jhplot import HLabel, HPlot 
from jhplot.shapes  import *

# make empty canvas in some range
c1 =HPlot("Canvas",600,400)
c1.setGTitle("HShape package to draw Java 2D objects")
c1.setLegend(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.setType(2)
c1.add(arr)

# arrow in the NDC system
arr = Arrow(-2.0, 4.6, -2.5, 8.0)
arr.setColor(Color.black)
stroke = BasicStroke(1.0)
arr.setStroke(stroke)
arr.setType(3)
c1.add(arr)


# arrow in the NDC system
arr = Arrow(-3.0, 2.6, -2.0, 10.7)
arr.setColor(Color.black)
stroke = BasicStroke(1.0)
arr.setStroke(stroke)
arr.setType(1)
c1.add(arr)




tex=  Text("This is a text",-2.4, 12)
c1.add(tex)


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");


You see the box below because you did not login.