Posts
Showing posts from 2018
Smile emoji using graphics in Java using Applet
- Get link
- X
- Other Apps
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:
Program to find the LCM & HCF of n numbers
- Get link
- X
- Other Apps
class HcfLcm { public static void main(String[] args) { int n,x; System.out.println("Number of integers: "); n = Integer.parseInt(System.console().readLine()); if(n<1) { System.out.print("Invalid input!"); System.exit(0); } int[] arr = new int[n]; for(int i =0; i<n; i++) { System.out.print("Number "+(i+1)+":"); ...
System Clock Program in Java
- Get link
- X
- Other Apps
import java.awt.*; import java.awt.event.*; import java.text.SimpleDateFormat; import java.util.Date; class SystemClock extends Frame { Label l,lt; void initGUI() { setTitle("System Clock"); Font font = new Font("Times New Roman", Font.PLAIN, 20); lt = new Label("Date & Time",Label.CENTER); lt.setFont(font); add(lt,BorderLayout.NORTH); l = new Label("",Label.CENTER); l.setFont(font); add(l,BorderLayout.CENTER); setSize(400,400); setVisible(true); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent w) { System.exit(0); } }); while(true) { SimpleDateFormat formatter = new SimpleDateFormat("EEE, d MMM yyyy h:mm:ss a"); Date date = new Date(); l.setText(formatter.format(date)); } } public SystemClock() { initGUI(); } public static void main(String[] args) { new Sy...
Simple Program to implement Transformation in Graphics(Translation, Rotation, Scaling & Shearing)
- Get link
- X
- Other Apps
#include <iostream> #include <conio.h> #include <graphics.h> #include <math.h> using namespace std; main() { int gd = DETECT,gm; int x1,x2,x3,y1,y2,y3,choice; cout<<"Enter coordinates of the triangle(x1,y1) : "; cin>>x1>>y1; cout<<"Enter coordinates of the triangle(x2,y2) : "; cin>>x2>>y2; cout<<"Enter coordinates of the triangle(x3,y13 : "; cin>>x3>>y3; cout<<"**********MENU**********"; cout<<"\n1. Translation\n2. Rotation\n3. Scaling\n4. Shearing\n"; cin>>choice; cout<<"Before transformation: \n"; initgraph(&gd,&gm,""); line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); switch(choice) { ...
Smile emoji using graphics
- Get link
- X
- Other Apps
#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...
Program to make frequency count of words in a given text
- Get link
- X
- Other Apps
public class Frequency { public static void main(String[] args) { String text,word; int frequency=0; System.out.println("Enter the text:"); text = System.console().readLine(); String[] t = text.split(" "); System.out.println("Enter the word which frequency count want to check:"); word = System.console().readLine(); for(int i=0;i<t.length;i++) { if(t[i].equals(word)) { frequency++; } } System.out.println("Frequency count of the word '"+word+"' is: "+frequency); } } OUTPUT:
Program for Bresenham's Line Drawing Algorithm in C++
- Get link
- X
- Other Apps
#include <iostream> #include <graphics.h> #include <conio.h> using namespace std; int main() { int x,y,x1,y1,x2,y2,dx,dy,step,P; int i=1,gd=DETECT,gm; float m; cout<<"Enter the first point(x1,y1)"; cin>>x1>>y1; cout<<"Enter the second point(x2,y2)"; cin>>x2>>y2; char path[]=""; initgraph(&gd,&gm,path); dx= abs(x2-x1); dy = abs(y2-y1); m = dy/dx; x=x1; y=y1; putpixel(x,y,WHITE); if(dx>=dy) { step =dx; } else { step =dy; } if(m<1) { P = 2*dy - dx; while(i<=step) { if(P>0)...
Program to draw a circle using Mid-point circle drawing Algorithm & Boundary fill Algorithm
- Get link
- X
- Other Apps
#include<iostream> #include<graphics.h> using namespace std; void circleMidpoint(int,int,int); void BoundaryFill_4_Connected(int,int,int,int); int main() { int xc,yc,r; cout<<"Enter center coordinate of circle: "; cin>>xc>>yc; cout<<"Enter radius of circle: "; cin>>r; int gd=DETECT,gm; char path[] = ""; initgraph(&gd,&gm,path); circleMidpoint(xc,yc,r); BoundaryFill_4_Connected( xc, yc, BLUE, WHITE); getch(); closegraph(); return 0; } void circleMidpoint(int xc,int yc,int r) { int x=0,y=r,P; P= 1-r; while(x<y) { putpixel(xc+x, yc+y, WHITE); putpixel(xc-x, yc+y, WHITE); putpixel(xc+x, yc-y,...
Program to draw a circle using Mid-point circle drawing algorithm in C++
- Get link
- X
- Other Apps
#include<iostream> #include<graphics.h> using namespace std; void circleMidpoint(int,int,int); int main() { int xc,yc,r; cout<<"Enter center coordinate of circle:"; cin>>xc>>yc; cout<<"Enter radius of circle:"; cin>>r; int gd=DETECT,gm; char path[] = ""; initgraph(&gd,&gm,path); circleMidpoint(xc,yc,r); getch(); closegraph(); return 0; } void circleMidpoint(int xc,int yc,int r) { int x=0,y=r,P; P= 1-r; while(x<y) { putpixel(xc+x, yc+y, WHITE); putpixel(xc-x, yc+y, WHITE); putpixel(xc+x, yc-y, WHITE); putpixel(xc-x, yc-y, WHITE); putpixel(xc+y, yc+...
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/s...
Program for DDA Line Drawing Algorithm in C++
- Get link
- X
- Other Apps
//This code is tested in Code Blocks #include <iostream> #include <graphics.h> using namespace std; void dda(float,float,float,float); int main() { float x1,y1,x2,y2; cout<<"Enter the value of x1 and y1 : "; cin>>x1>>y1; cout<<"Enter the value of x2 and y2: "; cin>>x2>>y2; dda(x1,y1,x2,y2); } void dda(float x1,float y1,float x2,float y2) { float x,y,dx,dy,step; int i,gd=DETECT,gm; char path[] = ""; initgraph(&gd,&gm,path); 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; ...
HOW TO SETUP CODE BLOCKS FOR GRAPHICS PROGRAMS
- Get link
- X
- Other Apps
How to setup... Download Code::Blocks from here . You have to download the codeblocks-17.12mingw-setup.exe or codeblocks-17.12mingw nosetup.zip file. The first file(highlighted) is the install-able setup and the other one(highlighted) is portable zip file(not need to install). If you are beginners you prefer the first one. After the installation you locate the code blocks at location C:\Program Files (x86)\CodeBlocks or at C:\Program Files\CodeBlocks. You have to download the graphics file from this link . Extras this zip file, it includes three files (two header files & a library file). Now copy the graphics.h & winbgim.h header files and paste at location C:\Program Files (x86)\CodeBlocks\MinGW\include And copy the libbgi.a file at location C:\Program Files (x86)\CodeBlocks\MinGW\lib Now open the code blocks and follow the steps: 1. Left click on "Settings (menu item)" in "Start here - Code::B...