Author Topic: Drawing Circles  (Read 3249 times)

0 Members and 1 Guest are viewing this topic.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Drawing Circles
« on: April 21, 2006, 08:25:23 pm »
Incidentally, I don't know if it's common knowledge or not, but if you do this:

Code: [Select]
i = 0;
do
  i++
  plot_pixel(sin(i), cos(i));
loop

It draws a circle.  Although it works better if you increment i by very small values, it's all good.  I learned that a long long time ago when I was playing with QBasic graphics.  By plotting SIN and COS against each other I used to draw spirals and waves and circles and stuff. 

Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Drawing Circles
« Reply #1 on: April 22, 2006, 12:52:29 pm »
Incidentally, I don't know if it's common knowledge or not, but if you do this:

Code: [Select]
i = 0;
do
  i++
  plot_pixel(sin(i), cos(i));
loop

It draws a circle.  Although it works better if you increment i by very small values, it's all good.  I learned that a long long time ago when I was playing with QBasic graphics.  By plotting SIN and COS against each other I used to draw spirals and waves and circles and stuff. 

Code: [Select]
import java.awt.*;
import javax.swing.*;

/**
This class demonstrates drawing a circle by using the point {sin(i), cos(i)}
@author William LaFrance
@date 22 April 2006
*/
public class DrawCircle extends JFrame
{
/**
Program entry-point<br />
Calls class constructor
@param args Command-line arguments, split by spaces
*/
public static void main(String args[])
{
new DrawCircle();
}

/**
Class constructor<br />
Creates JFrame object and initalizes it
*/
private DrawCircle()
{
super("Circle Thing!");

this.setSize(1000, 1000);

this.getContentPane().setBackground(Color.black);

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

this.setVisible(true);
}

/**
Draws the circle on the JFrame
@param g Graphics object to use for drawing on the JFrame
*/
    public void paint(Graphics g)
{

g.setColor(Color.yellow);
for (double i = 1; i < 100; i+=0.05)
{
g.fillRect((int)(Math.sin(i)*450)+500, (int)(Math.cos(i)*450)+500, 2, 2);
}
}
}

Cool!
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Chavo

  • x86
  • Hero Member
  • *****
  • Posts: 2219
  • no u
    • View Profile
    • Chavoland
Drawing Circles
« Reply #2 on: April 22, 2006, 02:17:43 pm »
Incidentally, I don't know if it's common knowledge or not, but if you do this:

Code: [Select]
i = 0;
do
  i++
  plot_pixel(sin(i), cos(i));
loop

It draws a circle.  Although it works better if you increment i by very small values, it's all good.  I learned that a long long time ago when I was playing with QBasic graphics.  By plotting SIN and COS against each other I used to draw spirals and waves and circles and stuff. 

Welcome to being bored in high school with your first TI graphing calculator :-P

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: Drawing Circles
« Reply #3 on: April 22, 2006, 03:07:29 pm »
Hahaha:

Code: [Select]
public void DrawCircle(Color outlineColor, Point center, int radius, Image target)
{
    using (Graphics g = Graphics.FromImage(target))
    {
        g.DrawEllipse(new Pen(new SolidBrush(outlineColor)),
            center.X - radius,
            center.Y - radius,
            center.X + radius,
            center.Y + radius);
    }
}

<3 library methods.  ;)
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline deadly7

  • 42
  • Moderator
  • Hero Member
  • *****
  • Posts: 6496
    • View Profile
Re: Drawing Circles
« Reply #4 on: April 23, 2006, 04:32:07 pm »
If you want to draw a circle, why not do x^2+y^2=r^2?
[17:42:21.609] <Ergot> Kutsuju you're girlfrieds pussy must be a 403 error for you
 [17:42:25.585] <Ergot> FORBIDDEN

on IRC playing T&T++
<iago> He is unarmed
<Hitmen> he has no arms?!

on AIM with a drunk mythix:
(00:50:05) Mythix: Deadly
(00:50:11) Mythix: I'm going to fuck that red dot out of your head.
(00:50:15) Mythix: with my nine

Offline Quik

  • Webmaster Guy
  • x86
  • Hero Member
  • *****
  • Posts: 3262
  • \x51 \x75 \x69 \x6B \x5B \x78 \x38 \x36 \x5D
    • View Profile
Re: Drawing Circles
« Reply #5 on: April 23, 2006, 04:37:19 pm »
Incidentally, I don't know if it's common knowledge or not, but if you do this:

Code: [Select]
i = 0;
do
  i++
  plot_pixel(sin(i), cos(i));
loop

It draws a circle.  Although it works better if you increment i by very small values, it's all good.  I learned that a long long time ago when I was playing with QBasic graphics.  By plotting SIN and COS against each other I used to draw spirals and waves and circles and stuff. 

Welcome to being bored in high school with your first TI graphing calculator :-P

Amen, brothah.
Quote
[20:21:13] xar: i was just thinking about the time iago came over here and we made this huge bomb and light up the sky for 6 min
[20:21:15] xar: that was funny