Computer Graphics CG Point Circle Method circle

Source: Internet
Author: User
Circle

Last name:

Student ID:

Class:

Date: 2012-4

Lab: Circle

Lab content:

I am using the MidPoint Circle Method (improved (2) algorithm)

Core algorithms:

// Draw 8 symmetric points

Public
Static void
Draweightpoint (IntX,IntY, graphics g)

{

G. filloval (Offsetx+ X,Offsety+ Y,Pointsize,Pointsize);

G. filloval (Offsetx+ X,Offsety-2 *R+ (Offsety-Y ),Pointsize,Pointsize);

G. filloval (Offsetx-3 *R+ (Offsetx-X ),Offsety+ Y,Pointsize,Pointsize);

G. filloval (Offsetx-3 *R+ (Offsetx-X ),Offsety-2 *R+ (Offsety-Y ),Pointsize,Pointsize);

G. filloval (Offsetx+ Y,Offsety+ X,Pointsize,Pointsize);

G. filloval (Offsetx+ Y,Offsety-2 *R+ (Offsety-X ),Pointsize,Pointsize);

G. filloval (Offsetx-3 *R+ (Offsetx-Y ),Offsety+ X,Pointsize,Pointsize);

G. filloval (Offsetx-3 *R+ (Offsetx-Y ),Offsety-2 *R+ (Offsety-X ),Pointsize,Pointsize);

}

// The core algorithm of the MidPoint Circle

Public
Staticvoid
Drawcircle (Graphics g ){

IntX, Y, D;

X = 0;

Y =R;

IntDeltax = 3;

IntDeltay = 2-R-R;

D = 1-R;

Draweightpoint(X, y, G );

While(X <= y ){

If(D <0 ){

D + = deltax;

Deltax + = 2;

}Else{

D + = deltax + deltay;

Deltax + = 2;

Deltay + = 2;

Y --;

}

X ++;

Draweightpoint(X, y, G );

}

Experiment results :()

Program source code:

PackageCs0904.no200942094;

ImportJava. AWT. graphics;

ImportJavax. Swing. jframe;

ImportJavax. Swing. jpanel;

Public
Class
DrawcircleExtendsJpanel {

Private
Static int
Framewidth= 600;

Private
Static int
Frameheight= 600;

Private
Static int
Offsetx= 300,Offsety= 200;

// Coordinates of the start point and focus

// Radius

Private
Static int
R= 100;

// Define the vertex size

Private
Static int
Pointsize= 5;

// Calculate a cell for every 20 cells

Private
Static int
Turnbigger (IntTemp ){

ReturnTemp * 20;

}

Public
Static void
Main (string [] ARGs ){

Jframeframe =NewJframe ("drawline ");

Frame. getcontentpane (). Add (NewDrawcircle ());

Frame. setdefaclocloseoperation (jframe.Exit_on_close);

Frame. setsize (Framewidth,Frameheight);

Frame. setlocation (200,10 );

Frame. setvisible (True);

}

// Draw 8 symmetric points

Public
Static void
Draweightpoint (IntX,IntY, graphics g)

{

G. filloval (Offsetx+ X,Offsety+ Y,Pointsize,Pointsize);

G. filloval (Offsetx+ X,Offsety-2 *R+ (Offsety-Y ),Pointsize,Pointsize);

G. filloval (Offsetx-3 *R+ (Offsetx-X ),Offsety+ Y,Pointsize,Pointsize);

G. filloval (Offsetx-3 *R+ (Offsetx-X ),Offsety-2 *R+ (Offsety-Y ),Pointsize,Pointsize);

G. filloval (Offsetx+ Y,Offsety+ X,Pointsize,Pointsize);

G. filloval (Offsetx+ Y,Offsety-2 *R+ (Offsety-X ),Pointsize,Pointsize);

G. filloval (Offsetx-3 *R+ (Offsetx-Y ),Offsety+ X,Pointsize,Pointsize);

G. filloval (Offsetx-3 *R+ (Offsetx-Y ),Offsety-2 *R+ (Offsety-X ),Pointsize,Pointsize);

}

Public
Static void
Drawcircle (Graphics g ){

IntX, Y, D;

X = 0;

Y =R;

IntDeltax = 3;

IntDeltay = 2-R-R;

D = 1-R;

Draweightpoint(X, y, G );

While(X <= y ){

If(D <0 ){

D + = deltax;

Deltax + = 2;

}Else{

D + = deltax + deltay;

Deltax + = 2;

Deltay + = 2;

Y --;

}

X ++;

Draweightpoint(X, y, G );

}

G. drawstring ("", x + 20, Y + 20 );

}

 

Protected
Void
Paintcomponent (graphicsg ){

Super. Paintcomponent (g );

For(IntI = 0; I <Frameheight; I + =Turnbigger(1 )){

G. drawline (0, I,Framewidth, I );

}

For(IntI = 0; I <Framewidth; I + =Turnbigger(1 )){

G. drawline (I, 0, I,Frameheight);

}

Drawcircle(G );

}

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.