• Tidak ada hasil yang ditemukan

Manual CPCS 391

N/A
N/A
Protected

Academic year: 2024

Membagikan "Manual CPCS 391"

Copied!
12
0
0

Teks penuh

(1)

Manual CPCS 391

Lab 5

(2)

Introduction

What we'd like to do is to use this discriminating function

to maintain our trajectory of drawn pixels as close as

possible to the desired circle. Luckily, we can start with a point on the circle

) ، ٠ x ، ٠ y + ( r ) or ٠ )

، ( r in our adjusted

coordinate system). As we move along in steps of x we note that the slope is less than zero and greater than

negative one at points in the direction we're heading that are near our known point on a circle. Thus we need only to figure out at each step whether to step down in y or

maintain y at each step

.

(3)

Objective

Drawing in a Circle Drawing ( Mid-Point

Circle Algorithm )

(4)

Overview

We will compute points between x=0 and x=y and then draw the 8 matching points

In that area, the slope of the curve is between 0 and -1

From each step/point (x, y), the next one is either (x+1, y) or (x+1, y-1

(

We decide about which one by looking at the midpoint M

M inside (f<0) => next point is E

M ouside (f>0) => next point is SE

(5)

Prelab Activities

lectu

/ au .

edu .

anu .

escience ://

http

html .

en .

midPoint2 /

Circle /

cg /

re

Book “Computer Graphics CS

454,Part 1, ch3-9, Page 105.

(6)

import java.applet.Applet;

import java.awt.*;

import java.awt.event.AdjustmentEvent;

import java.awt.event.AdjustmentListener;

public class BresenhamCircle extends Applet implements AdjustmentListener { private static final long serialVersionUID = 1L;

int d = 5; int x0 = 0; int y0 = 0; int r = 0;

Label Hlabel = new Label();

Scrollbar Hrubka = new Scrollbar(Scrollbar.HORIZONTAL, 5, 1, 1, 100);

Choice R = new Choice();

Label Rlabel = new Label(" Color px: R:");

Choice G = new Choice();

Label Glabel = new Label(" G:");

Choice B = new Choice();

Label Blabel = new Label(" B:");

Color Farba = new Color(0,0,0);

Checkbox Vymaz = new Checkbox("Clean screen");

Graphics Buffer;

Dimension size1 = getSize();

private Image imgBuffer; //image doublebuffera

(7)

public void init() {

d = Hrubka.getValue();

add(Hlabel); add(Hrubka); add(Rlabel); add(Glabel);

add(R);

add(B); add(Vymaz);

add(G); add(Blabel);

Hlabel.setText("Width px: "+Hrubka.getValue());

Vymaz.setState(true);

G.add("G"); B.add("B");

R.add("R");

for (int i = 0; i < 256; i++){

} B.add(""+i); G.add(""+i); R.add(""+i);

Hrubka.addAdjustmentListener(this);

resize(600,400);

size1 = getSize();

imgBuffer = createImage(size1.width, size1.height);

Buffer = imgBuffer.getGraphics();

y0 = getHeight()/2;

x0 = getWidth()/2;

r = getHeight() / 3;

super.init();

}

(8)

public void start() {super.start();}

super.stop(); } public void stop() {

public void destroy() { super.destroy();

public void adjustmentValueChanged(AdjustmentEvent e){

if(e.getAdjustable().equals(Hrubka)){

d = Hrubka.getValue();

Hlabel.setText("Width px: "+Hrubka.getValue());

}

repaint(); }

public boolean action (Event evt, Object arg) { int r = 0, g = 0, b = 0;

if (R.getSelectedItem() != "R") {

r = Integer.parseInt(R.getSelectedItem());

//System.out.println(R.getSelectedItem());

}

if (G.getSelectedItem() != "G") {

} g = Integer.parseInt(G.getSelectedItem());

if (B.getSelectedItem() != "B") {

} b = Integer.parseInt(B.getSelectedItem());

repaint();

Farba = new Color(r,g,b);

} return true;

(9)

public boolean mouseDrag(Event arg0, int x, int y) {

r = (int)Math.round(Math.sqrt(Math.pow(x0 - x,2)+ Math.pow(y0 - y,2)));

//System.out.println("BresenhamCircle.mouseDrag() x:"+x+" y:"+y + " r:"+r );

repaint();

return super.mouseDrag(arg0, x, y);

}

public boolean mouseDown(Event arg0, int x, int y) { d = Hrubka.getValue();

x0 = x;

y0 = y;

//System.out.println("BresenhamCircle.mouseDown() x:"+x+" y:"+y);

repaint();

return super.mouseDown(arg0, x, y);

}

public void setPixel(int x, int y, int d, Graphics g) { g.setColor(Farba);

g.fillRect(x - (d/2), y - (d/2), d, d);

}

public void update(Graphics g) { paint(g);

}

(10)

public void paint( Graphics g ) { int rr = r - (r % d);

int y = rr;

if((size1.width != getWidth()) || (size1.height != getHeight())){

size1.width = getWidth();

size1.height = getHeight();

imgBuffer = createImage(getWidth(),getHeight());

Buffer = imgBuffer.getGraphics();

}

if(Vymaz.getState()){

Buffer.setColor(Color.WHITE);

Buffer.fillRect(0,0,getWidth(),getWidth());

}

for(int x = 0; x <= rr/Math.sqrt(2)+1; x+=d){

y = (int)Math.round(Math.sqrt(Math.pow(rr,2)-Math.pow(x,2)));

y = (y/d)*d;

(11)

setPixel(x0 + x, y0 + y, d, imgBuffer.getGraphics());

setPixel(x0 - x, y0 + y, d, imgBuffer.getGraphics());

setPixel(x0 + x, y0 - y, d, imgBuffer.getGraphics());

setPixel(x0 - x, y0 - y, d, imgBuffer.getGraphics());

setPixel(x0 + y, y0 + x, d, imgBuffer.getGraphics());

setPixel(x0 - y, y0 + x, d, imgBuffer.getGraphics());

setPixel(x0 + y, y0 - x, d, imgBuffer.getGraphics());

setPixel(x0 - y, y0 - x, d, imgBuffer.getGraphics());

}

g.drawImage(imgBuffer,0,0, this); //double buffering }

}

NetBeans

Save both time copy the code for the entire program

(12)

Outputs

Referensi

Dokumen terkait

The main aim of stereo matching algorithms is to find homologous points in the stereo pair [11]. The stereo matching points are used to estimate the depth and

% uses a natural cubic spline interpolation to find yy, the values % of the underlying function y at the points in the vector xx... These values can then be added to the y

10 (2008), 66– 72], Demirel and Soyt¨ urk presented necessary and sufficient conditions for Lorentz- Minkowski distances l(x, y) &gt; 0, l(x, y) &lt; 0 and l(x, y) = 0 in

As only small parts of a building facade are visible within one image, a direct matching of edges extracted from the images and a given building model cannot be

Draw the line Exercise 2 Draw a Vertical Line 1- Set T-square as before 2- Place any triangle on T-square edge 3- Slide your left hand to hold both T-square and triangle in

There is a unique linear transformation of R2 which maps the X-axis to the line y= 2x, and the Y-axis to the liney=x.. Leta >0 and define the linear transformation fx, y = ax−y,

Basics I x the cost of care taken by the firm,x ≥0,x ∈X, y the cost of care taken by the consumer,y ≥0,y ∈Y, πthe probability of occurrence of an accident, Dthe loss in case an

Computing the distance methods • To compute the intra-cluster distance: Sum/min/max/avg the absolute/squared distance between  All pairs of points in the cluster, or  Between