Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

bresenham circle drawing algorithm

#include <bits/stdc++.h>

using namespace std;

int main()

{

    int r;

    cin>>r;

    int x = 0, y = r, d = 3-2r;

    while(x <= y) 

        {

            setPixel(x, y);

                if (d < 0) {

                    d = d + 4x + 6; 

                }

                else {

                    d= d + 4(x-y) + 10;

                    y--;

                }

        x++;

    }

    return 0;

}
Comment

bresenham circle drawing algorithm

import numpy as np
import matplotlib.pyplot as plt


### Data input
x_cent = int(input("Enter x-coordinates of the center: "))
y_cent = int(input("Enter y-coordinates of the center: "))
r = int(input("Enter the radius of the circle: "))



#### Bresenham Circle Drawing Algorithm ####

### Initializations
x_quad1 = []
y_quad1 = []
decor = []


### Step 01
x_init = 0
y_init = r


### Step 02
decision_parameter = 3 - 2 * r


### Step 03: First octant
x = x_init
y = y_init
p = decision_parameter

while(x < y):
    x_quad1.append(x)
    y_quad1.append(y)
    
    if p < 0:
        x += 1
        p += 4 * x + 6
    else:
        x += 1
        y -= 1
        p += 4 * (x - y) - 10

# append the final point
x_quad1.append(x)
y_quad1.append(y)

# append the second octant to the first quadrant
for i in range(len(x_quad1)):
    x_quad1.append(y_quad1[i])
    y_quad1.append(x_quad1[i])

# Second Quadrant, WRT center coordinates
x_quad2 = [(x_cent - x) for x in x_quad1]
y_quad2 = [(y_cent + y) for y in y_quad1]

# Third Quadrant, WRT center coordinates
x_quad3 = [(x_cent - x) for x in x_quad1]
y_quad3 = [(y_cent - y) for y in y_quad1]

# Fourth Quadrant, WRT center coordinates
x_quad4 = [(x_cent + x) for x in x_quad1]
y_quad4 = [(y_cent - y) for y in y_quad1]

# First Quadrant, WRT center coordinates
x_quad1 = [(x_cent + x) for x in x_quad1]
y_quad1 = [(y_cent + y) for y in y_quad1]

# transform coordinates into a numpy array and print them out
x_quad1 = np.array(x_quad1, dtype = int)
y_quad1 = np.array(y_quad1, dtype = int)
x_quad2 = np.array(x_quad2, dtype = int)
y_quad2 = np.array(y_quad2, dtype = int)
x_quad3 = np.array(x_quad3, dtype = int)
y_quad3 = np.array(y_quad3, dtype = int)
x_quad4 = np.array(x_quad4, dtype = int)
y_quad4 = np.array(y_quad4, dtype = int)

print(np.vstack((x_quad1, y_quad1, x_quad2, y_quad2, 
                 x_quad3, y_quad3, x_quad4, y_quad4)).T)


### Step 04
fig = plt.figure()
ax = fig.add_subplot(111)

plt.plot(x_quad1, y_quad1, x_quad2, y_quad2, x_quad3, y_quad3, x_quad4, y_quad4)

ax.set_aspect('equal', adjustable='box')

plt.title("Bresenham Circle Drawing Algorithm")

plt.xlabel("x-axis")
plt.ylabel("y-axis")

plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: dfs algorithm python 
Python :: NaN stand for python 
Python :: // in python means 
Python :: type of tuple in python 
Python :: how to delete whole list in python 
Python :: convert time 
Python :: string count in python 
Python :: python typing union 
Python :: deque python 
Python :: join tables in django orm 
Python :: python string replace method 
Python :: pandas sum 
Python :: python decimal 
Python :: nested dictionary python 
Python :: self.assertequal python 
Python :: Restrict CPU time or CPU Usage using python code 
Python :: mod in python 
Python :: python function __name__ 
Python :: how to console log in django heroku 
Python :: python add encoding for non-English language like Arabic 
Python :: how to count the iteration a list python 
Python :: Python program for getting url, hostname, port numbers 
Python :: pdf reading shows gibberish python 
Python :: python glob sort numerically 
Python :: pandas dro pow 
Python :: tz convert python 
Python :: python source script custom functions 
Python :: gridTraveler python 
Python :: hack twitter with python 
Python :: sss 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =