Program to draw a star using DDA Line Drawing Algorithm in C++
- Get link
- X
- Other Apps
#include <iostream>
#include <graphics.h>
using namespace std;
void star(float,float,float,float);
int main()
{
int i,gd=DETECT,gm;
char path[] = "";
initgraph(&gd,&gm,path);
//Statically setted coordinates
star(300,200,200,400);
star(200,400,400,400);
star(300,200,400,400);
star(200,250,400,250);
star(200,250,300,450);
star(400,250,300,450);
getch();
closegraph();
}
//Function to draw a star
void star(float x1,float y1,float x2,float y2)
{
float x,y,dx,dy,step;
int i;
dx=(x2-x1);
dy=(y2-y1);
if(dx>=dy)
{
step=abs(dx);
}
else
{
step=abs(dy);
}
dx=dx/step;
dy=dy/step;
x=x1;
y=y1;
i=1;
while(i<=step)
{
putpixel(x,y,WHITE);
x=x+dx;
y=y+dy;
i=i+1;
}
}
- Get link
- X
- Other Apps
Popular posts from this blog
Download and install MATLAB R2017a in Ubuntu 18.04 | Linux Free | Cracked
Smile emoji using graphics in Java using Applet
import java.awt.*; import java.awt.event.*; import java.applet.*; public class Smile extends Applet { public void paint(Graphics g) { setBackground(Color.BLACK); g.setColor(Color.YELLOW); g.fillOval(30,50,100, 100); g.setColor(Color.BLACK); g.fillOval(55,75,10, 10); g.fillOval(95,75,10, 10); g.drawArc(60, 85, 40,40,-30,-120); } } /* <applet code="Smile.class" width="200" height="200"> </applet> */ OUTPUT:
Smile emoji using graphics
#include<graphics.h> void BoundaryFill_4_Connected(int,int,int,int); using namespace std; main() { int gd = DETECT, gm; char path[] =""; initgraph(&gd, &gm, path); circle(200,200,100); circle(240,160,13); circle(160,160,13); ellipse(200, 250, 0, 360, 25, 10); BoundaryFill_4_Connected( 200, 200, YELLOW, WHITE); BoundaryFill_4_Connected( 240, 160, CYAN, WHITE); BoundaryFill_4_Connected( 160, 160, CYAN, WHITE); BoundaryFill_4_Connected( 200, 250, RED, WHITE); getch(); closegraph(); return 0; } void BoundaryFill_4_Connected(int x,int y,int f_color,int b_color) { int current = getpixel(x,y); if(current != b_color && current != f_color) { putpixel(x,y,f_color); Boun...
Comments
Post a Comment