Skip to content

Commit 2f2084c

Browse files
committed
adding rainbow color
1 parent 9a529dc commit 2f2084c

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎ch04/GraphicsTest.java‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import java.awt.Canvas;
22
import java.awt.Graphics;
3+
import java.awt.Color;
34
import javax.swing.JFrame;
45

56
/**
@@ -19,10 +20,12 @@ public static void main(String[] args) {
1920

2021
public void paint(Graphics g) {
2122
double angle = 0.0;
22-
for (int x = 0; x <= 256; x += 8) {
23-
double y = 50 + (Math.sin(angle) * 35.0);
23+
for (int x = 0; x <= 1024; x += 8) {
24+
double y = 150 + (Math.sin(angle) * 35.0);
2425
System.out.println("y = " + y);
25-
g.fillRect(x, (int) y, 4, 8);
26+
Color rainbow = new Color(x/2, 200, 200);
27+
g.setColor(rainbow);
28+
g.fillRect(x, (int) y, 4, 64);
2629
angle += Math.PI/40.0;
2730
}
2831
}

0 commit comments

Comments
 (0)