12/2/2009 - İki cismin çarpışmasına örneklerle ulaşmak: Örnek3 BallCollision
import java.applet.Applet; import java.awt.Color; import java.awt.Graphics; import java.awt.Image;
/** * * @author KAYWINSOFT */ public class BallCollision extends Applet implements Runnable{ Image bgIM; Graphics bgGA; Thread one = new Thread(this); int ball1X = 50; int ball1Y = 50; int ball2X = 300; int ball2Y = 50; int radius = 20; int[] b1CO = new int[400]; int[] b2CO = new int[400]; public void init(){ bgIM = createImage(400,400); bgGA = bgIM.getGraphics(); setBackground(Color.ORANGE); } public void start(){ one.start(); } public void run(){ int i = 0; int one; int two; while(true){ System.out.println(i); one = i; two = i; if(ball1X + radius != ball2X - radius) { b1CO[i] = ball1X++; b2CO[i] = ball2X--; } else{ while(true) { if(ball1X != 0 && ball2X != 300) { ball1X -=1 ; ball2X +=1; bgGA.setColor(Color.black); bgGA.drawOval(ball1X, ball1Y, 2 * radius, 2 * radius); bgGA.setColor(Color.blue); bgGA.drawOval(ball2X, ball2Y, 2*radius, 2*radius); repaint(); } try{ Thread.sleep(20); }catch(Exception e){ } } } repaint(); try{ Thread.sleep (20); } catch (InterruptedException ex) { System.out.println(ex.toString()); } i++; } } public void paint(Graphics g){ g.setColor(Color.black); g.fillOval(ball1X , ball1Y , 2 * radius, 2 * radius); g.setColor(Color.blue); g.fillOval(ball2X, ball2Y, 2 * radius, 2 * radius); } }
En sonunda bu kodla 2 cismin çarpışmasını izleyebiliyoruz. Burda da baya bir amatörce davranıldı ki henüz geliştirme aşamasındadır. İleriki safhalarda çarpışma anında ses ve bir kaç aksiyon daha eklenmesini planlıyorum. ----------------------------------------------------------------- Onur, bu benim programımım abi :D



amatörlükten kastettiğim yer şuydu, henüz eski oluşturulan (paint fonksiyonunda) toplarla işlemleri sonlandıramadım. Global olarak oluşturulan bgGA grafik nesnesi ile işlemleri sonlandırdım. Bunu halledersem zaten işlem tamam :D
|
|
Yorum (yok) :: Yorum yaz! :: Bağlantı
|
12/2/2009 - İki cismin çarpışmasına örneklerle ulaşmak: Örnek2

/** * * @author KAYWINSOFT */ import java.applet.Applet; import java.awt.*;
public class ProfPendulum extends Applet implements Runnable { public Thread myThread = null; Image hiddenImage; Graphics hiddenGraphics; Font font = new Font("Times Roman", Font.BOLD, 18);
int step = 0; int tableSetUp = 0; int oldSecond = 0;
int radius = 95;
double[] sine = new double[20]; // sine values every 18 degrees double[] sineScaled = new double[20]; // sine values / 3 double[] pendulumX = new double[20]; double[] pendulumY = new double[20]; double[] beamXLeft = new double[20]; double[] beamYLeft = new double[20]; double[] beamXRight = new double[20]; double[] beamYRight = new double[20]; double[] stopXRight = new double[20]; double[] stopYRight = new double[20]; double[] stopXLeft = new double[20]; double[] stopYLeft = new double[20];
int[] pendulumXabs = new int[20]; int[] pendulumYabs = new int[20]; int[] beamXLeftAbs = new int[20]; int[] beamYLeftAbs = new int[20]; int[] beamXRightAbs = new int[20]; int[] beamYRightAbs = new int[20]; int[] stopXLeftAbs = new int[20]; int[] stopYLeftAbs = new int[20]; int[] stopXRightAbs = new int[20]; int[] stopYRightAbs = new int[20];
int[] spokeAngleX = new int[66]; int[] spokeAngleY = new int[66];
// pendulum int PIVOTX = 100; int PIVOTY = 117; int PENDLENGTH = 250; int BEAMWIDTHL = 35; int BEAMWIDTHR = 45; int SLOPE = 8; // this puts slope on stop at left of beam
public void init() { hiddenImage = createImage(400,400); hiddenGraphics = hiddenImage.getGraphics(); fillSpokeAngleTable( radius ); }
public void fillSpokeAngleTable( int radius ) { // this is filled during initialisation for(int x = 0; x <= 65; x++) { spokeAngleX[x] = (int)(radius * Math.sin( x * 2 * Math.PI/60)); spokeAngleY[x] = (int)(radius * Math.cos( x * 2 * Math.PI/60)); } }
public synchronized void update(Graphics g) { // could check and only do this if its changed buildBuffer(hiddenGraphics);
// paint the buffer to the screen paint(g); }
public void paint (Graphics g) { g.drawImage(hiddenImage,0,0,this); g.drawString("PENDULUM", 50,50); }
public void start() { if (myThread == null) myThread = new Thread(this); myThread.start(); }
public void stop() { myThread.stop(); myThread = null; // ...or else the next start() will break }
public void run() { while (true) { try{myThread.sleep(100);} catch (InterruptedException e){ } step++; if(step >= 20) step = 0; repaint(); } }
private void buildBuffer(Graphics g) {
// yellow background g.setColor(Color.yellow); g.fillRect(0,0,size().width, size().height);
// red border g.setColor(Color.red); g.drawRect(0,0,size().width - 1, size().height -1); g.drawRect(1,1,size().width - 3, size().height -3);
drawPendulum( g, PENDLENGTH,BEAMWIDTHL,BEAMWIDTHR,SLOPE,PIVOTX,PIVOTY); }
public void drawPendulum(Graphics g, int pendLength, int beamWidthL, int beamWidthR, int slope, // puts a slope on left stop int pivotX, int pivotY) { if(tableSetUp == 0) fillPendulumTable(pendLength, pivotX, pivotY, beamWidthL, beamWidthR); tableSetUp = 1; // pendulum is pivotted at point pivotX and pivotY // it has a beam across the top with different left and right lengths g.setColor(Color.red); // pendulum g.drawLine(pivotX, pivotY, pendulumXabs[step], pendulumYabs[step]); g.fillOval(pendulumXabs[step] - 5, pendulumYabs[step] - 5, 10, 10 );
// beam g.drawLine(beamXLeftAbs[step], beamYLeftAbs[step], beamXRightAbs[step], beamYRightAbs[step] );
// stop (right) g.drawLine(beamXRightAbs[step], beamYRightAbs[step], stopXRightAbs[step], stopYRightAbs[step] ); // stop (left) g.drawLine(beamXLeftAbs[step], beamYLeftAbs[step], stopXLeftAbs[step] - slope, stopYLeftAbs[step] ); }
// This fills two arrays with the x,y positions of the pendulum bottom. public void fillPendulumTable( int length, int pivotX, int pivotY, int beamWidthL, int beamWidthR ) { for (int x = 0; x <=19; x++) { // sine values, 0 to 360degrees sine[x] = Math.sin(x * 2.0 * Math.PI / 20); // sine values multiplied by the max swing // this is the angle per tenth of a second in radians sineScaled[x] = sine[x] * 0.3;//0.3=swing in rads,about +-57* .3=17deg // pendulum x and y values pendulumX[x] = Math.sin(sineScaled[x]); pendulumY[x] = Math.cos(sineScaled[x]); //beam right beamXRight[x] = Math.sin(sineScaled[x] + (Math.PI/2) ); beamYRight[x] = Math.cos(sineScaled[x] + (Math.PI/2) ); //beam left beamXLeft[x] = Math.sin(sineScaled[x] - (Math.PI/2) ); beamYLeft[x] = Math.cos(sineScaled[x] - (Math.PI/2) ); // stops: Math.PI/5 is an arbitrary angle of 72 degrees // stop right stopXRight[x] = Math.sin(sineScaled[x] + (Math.PI/2) - Math.PI/5 ); stopYRight[x] = Math.cos(sineScaled[x] + (Math.PI/2) - Math.PI/5 ); // stop left stopXLeft[x] = Math.sin(sineScaled[x] - (Math.PI/2) + Math.PI/5 ); stopYLeft[x] = Math.cos(sineScaled[x] - (Math.PI/2) + Math.PI/5 );
// absolute values // pendulum pendulumXabs[x] = pivotX + (int)(length * pendulumX[x]); pendulumYabs[x] = pivotY + (int)(length * pendulumY[x]); // beam beamXLeftAbs[x] = pivotX + (int)(beamWidthL * beamXLeft[x]); beamYLeftAbs[x] = pivotY + (int)(beamWidthL * beamYLeft[x]); beamXRightAbs[x] = pivotX + (int)(beamWidthR * beamXRight[x]); beamYRightAbs[x] = pivotY + (int)(beamWidthR * beamYRight[x]); stopXLeftAbs[x] = pivotX + (int)(beamWidthL * stopXLeft[x]); stopYLeftAbs[x] = pivotY + (int)(beamWidthL * stopYLeft[x]); stopXRightAbs[x] = pivotX + (int)(beamWidthR * stopXRight[x]); stopYRightAbs[x] = pivotY + (int)(beamWidthR * stopYRight[x]); } } }
Gerçekten profosyenelce öyle değil mi? [Katkılarından dolayı Ali'ye teşekkürler.]


|
|
Yorum (yok) :: Yorum yaz! :: Bağlantı
|
12/2/2009 - İki cismin çarpışmasına örneklerle ulaşmak: Örnek1

Merhaba,
Bugünkü yazıda bitirme projeme başlamadan önce yapmam gerektiğine inandığım bir kaç grafiksel örneği paylaşacağım. Aslında çok fazla bir işe yaramasalar da ya da çok amatörce programlar olsa da bazı fikirlerin aklımda canlanması açısından ve size de sunmak açısından güzel örnekler olduklarını düşünüyorum. Kodların bazı kısımlarında bir kaç arkadaşımdan yardım aldığımı da belirtmek isterim. Onlara buradan teşekkür ediyorum. [ Mehmet, Ali ve Onur :D ]
İlk örnek pendulum'a geçişi sağlayabilmek için kendimce tasarladığım bir programdır. Pendulum da bilineceği üzere sarkaç sistemidir. Belli başlı formüllerle hesaplamaları yapılıp frekansı ya da hareket açıları hesaplanır. Programda bu formülleri kullanırken de aynen kağıt üstünde işlem yapar gibi işlem yapmak zorundayız. http://www.physics-lab.net/applets/simple-pendulum örneği gerçekten ileri düzey. Benim örneğim biraz daha amatör, sınırlamalar var ilk örnekte örneğin belirli bir noktaya vardığında o noktaya çarpmasını istedim.
/** * * @author KAYWINSOFT */ import java.awt.*; import java.applet.*;
public class BallMove extends Applet implements Runnable{
int x_pos = 10; int y_pos = 100; int radius = 20; int y_speed = 1; Image dbImage; Graphics dbg; int appletsize_x = 100; int appletsize_y = 100; int x_speed = 1; //X yönünde top hızı public void start () {
// define a new thread Thread th = new Thread (this); // start this thread th.start ();
} //ilk değişikliklerin yapıldığı yer. public void init() { setBackground (Color.yellow); } public void run () { Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
// Thread doğru olarak çalıştıkça devam et while (true) { // top sınıra yaklaştığında yukarı kaldır if (x_pos > appletsize_x - radius) { // top yönünü değiştirme x_speed = -1; } // top sınırdan uzaklaştığında aşağı indir else if (x_pos < radius) { x_speed = +1; } if (y_pos > appletsize_y - radius) { y_speed = -1; } else if (y_pos < radius) { y_speed = +1; }
//x koordinat değiştirme x_pos += x_speed; y_pos += y_speed;
repaint();
try { Thread.sleep (20); } catch (InterruptedException ex) { // do nothing }
Thread.currentThread().setPriority(Thread.MAX_PRIORITY); }
} public void update (Graphics g) { if (dbImage == null) { dbImage = createImage (this.getSize().width, this.getSize().height); dbg = dbImage.getGraphics (); }
dbg.setColor(Color.YELLOW); dbg.setColor (getBackground ()); dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
dbg.setColor (getForeground()); paint (dbg); g.drawImage (dbImage, 0, 0, this); g.drawLine(x_pos, y_pos, 0,0); } public void paint (Graphics g) { // set color g.setColor (Color.red); // paint a filled colored circle g.fillOval (x_pos - radius, y_pos - radius, 2 * radius, 2 * radius);
} }
henüz dosya upload'ı uygun olmadığı için resimlerle idare etmenizi rica edeceğim. Fakat şunu belirteyim, böyle gözlendiğinde cidden baya bir amatörce oluyor.

|
|
Yorum (yok) :: Yorum yaz! :: Bağlantı
|
1/9/2008 - [DUYURU] JAVA VE C++ ÜZERİNE PROJE KABULÜ
 
Merhaba arkadaşlar, bir süredir stajda olmam sebebiyle yazılarıma ara verdim. Bu haftaki yazıma da bir duyuru için yazmış bulunuyorum. Bir süredir (Ağustos 2006) üzerinde çalışmakta olduğum JAVA programlama dili ve gene hemen hemen aynı sürede üzerinde çalışmakta olduğum C++ programlama dilleri üzerine proje kabul etmekteyim. Sınırlama ve ücretlendirme ile ilgili gerekli bilgiyi bana mail atarak öğrenebilirsiniz.
konu olarak "proje" yazarsanız sevinirim. mailTo: kaywinsoft_km@yahoo.com
Hayırlı günler ve hayırlı ramazanlar dilerim.
|
|
Yorum (yok) :: Yorum yaz! :: Bağlantı
|
|
Hakkımda
Kategoriler
Arkadaşlarım
|