Posts
Showing posts from October, 2018
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+...