الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كيف يمكن ان ارسم دائرة

بدأه .S.T.A.L.K.E.R في 1 يونيو 2009 · 5 رد · 555 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكــم ورحمـة الله وبركاتــه ،،

اجتاج الى كود رسم الدائرة باستخدام g.drawLine

يعني لا اريد رسمها باستخدام drawArc

بل عن طريق كود كامل وloops

و شكرا

#2

حاول في الموضوع وسنساعدك

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#3

صدقا ما بعرف اصلا قوانين الدائرة في الرياضيات

فارجو وضعها و منها ان شاء الله ابدأ

#4

تحياتي اخ محمد

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
public class BouncingCircle extends Applet implements Runnable {
  int x = 150, y = 50, r = 50; 
  int dx = 11, dy = 7; // Trajectory of circle
  Thread animator;
  volatile boolean pleaseStop; 
  public void paint(Graphics g) {
	g.setColor(Color.red);
	g.fillOval(x - r, y - r, r * 2, r * 2);
  }

  public void animate() {

	Rectangle bounds = getBounds();
	if ((x - r + dx < 0) || (x + r + dx > bounds.width))
	  dx = -dx;
	if ((y - r + dy < 0) || (y + r + dy > bounds.height))
	  dy = -dy;

	// move the circle.
	x += dx;
	y += dy;

	repaint();
  }

  public void run() {
	while (!pleaseStop) { // Loop until we're asked to stop
	  animate(); 
	  try {
		Thread.sleep(100);
	  }
	  catch (InterruptedException e) {
	  } 
	}
  }

  public void start() {
	animator = new Thread(this); 
	pleaseStop = false; 
	animator.start(); 

  }

  public void stop() {
	pleaseStop = true;
  }
}

هذا يعطيك خيارات جيدة للرسم مع امكانية الاعادة بالرسم

ماذا تقصد بقوانين الدائرة هل هي التي معتادين عليها ام هناك شئ جديد ؟

بالتوفيق

الله معك

#5

السلام عليكــم ورحمـة الله وبركاتــه ،،

إستخدم معادلة الدائرة

اقتباس
the circle with center (a, b ) and radius r is the set of all points (x, y) such that

x = a + r * cos(t)

y = b + r * sin(t)

where t is a parametric variable, interpreted geometrically as the angle that the ray from the origin to (x, y) makes with the x-axis.

وهذا مثال لرسم دائرة باستعمال drawLine فقط


import javax.swing.*;

public class DrawCircle {
public static void main(String[] args) {
JComponent c = new JComponent() {
public void paintComponent(Graphics g) {
super.paintComponent(g);
double x = -1, y= -1, oldX, oldY;
int r = 30, centerX = 50, centerY = 50, angle = 0;
while (angle < 360) {
oldX = x;
oldY = y;
x = centerX + r * Math.cos(Math.toRadians(angle));
y = centerY + r * Math.sin(Math.toRadians(angle));
if (oldX != -1 && oldY != -1)
g.drawLine((int)oldX, (int)oldY, (int)x, (int)y);
angle ++;
}
}
};
JFrame frm = new JFrame();
frm.add(c);
frm.setSize(150, 150);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);;
frm.setVisible(true);
}
}
   import java.awt.*;

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…