Display a random ellipse using P1D data points
Source code name: "shapes_ellipse3.py"
Programming language: Python
Topic: Graphics/2D
DMelt Version 1. Last modified: 05/09/2015. License: Pro
https://datamelt.org/code/cache/shapes_ellipse3_476.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 *
from jhplot import * 
from jhplot.shapes  import *
from java.util import Random
from math import *

c1 =HPlot("Canvas",500,500)
c1.setGTitle("Random ellipse")
c1.setAntiAlias(1)
c1.setLegend(0)
c1.setNameX("X")
c1.setNameY("Y")
c1.setRange(-10.0, 10.0, -10, 10.0)
c1.visible(1)

p1=P1D("Random ellipse")
rand = Random()
# a, b are the radius on the x and y axes respectively
a=4  # semi-major axis 
b=2  # semi-minor exis
xshift=0 # (X,Y) position
yshift=-1
theta=1.0 # rotation
step=0.05
ra=[v*step for v in range(0,int(6.28/step))]
for t in ra:    # fill random ellipse.
      x= a*cos(t)*cos(theta) - b*sin(t)*sin(theta)+xshift         
      y = b*cos(theta)*sin(t) + a*sin(theta)*cos(t)+yshift
      p1.add(x+0.4*rand.nextGaussian(), y+0.5*rand.nextGaussian())      
ele1= Ellipse(xshift, yshift, a, b) 
ele1.setFill(0)
ele1.setRotation(theta)
ele1.setColor(Color.red)
ele1.setTransparency(0.6)
c1.add(ele1)

# set HLabel in the USER coordinate system
lab=HLabel("Random ellipse", 1, 8)
c1.add(lab)

# now show all objects
c1.draw(p1)

# export to some image (png,eps,pdf,jpeg...)
# c1.export(Editor.DocMasterName()+".png");


You see the box below because you did not login.