-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawingRandomTriangles.java
More file actions
70 lines (61 loc) · 1.82 KB
/
Copy pathDrawingRandomTriangles.java
File metadata and controls
70 lines (61 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment_10528808;
/**
*
* @author Mawutor
*/
import java.util.Random;
import java.awt.*;
import javax.swing.JFrame;
import java.awt.Polygon;
public class DrawingRandomTriangles extends Canvas
{
Random r= new Random();
int x= r.nextInt(500)+100;
int y=r.nextInt(500)+100;
int color=r.nextInt(3);
public void paint ( Graphics g)
{
int n =0;
while(n==0)
{
Random r= new Random();
int x= r.nextInt(500)+100;
int y=r.nextInt(500)+100;
int color=r.nextInt(3);
n++;
Polygon tri = new Polygon();
tri.addPoint(100, 100);
tri.addPoint(100, 300);
tri.addPoint(200, 300);
if(color==1){
g.setColor(Color.red);
g.fillPolygon(tri);
}
else if(color==2){
g.setColor(Color.yellow);
g.fillPolygon(tri);
}
else if(color==3){
g.setColor(Color.blue);
g.fillPolygon(tri);
}
else if(color==0){
g.setColor(Color.cyan);
g.fillPolygon(tri);
}
}
}
public static void main(String[] args)
{
JFrame win = new JFrame("Polygon Demo");
win.setSize(1024,768);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.add( new DrawingRandomTriangles() );
win.setVisible(true);
}
}