News:

Help! We're trapped in the computer, and the computer is trapped in 2008! Someone call the time police!

Main Menu

Drawing Circles

Started by iago, April 21, 2006, 08:25:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

iago

Incidentally, I don't know if it's common knowledge or not, but if you do this:

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. 

Joe

Quote from: iago 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:

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. 

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!
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


Chavo

Quote from: iago 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:

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

MyndFyre

Hahaha:


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.  ;)
Quote from: Joe on January 23, 2011, 11:47:54 PM
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Quote from: Rule on May 26, 2009, 02:02:12 PMOur species really annoys me.

deadly7

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

Quik

Quote from: unTactical on April 22, 2006, 02:17:43 PM
Quote from: iago 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:

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