'electric sign letter using general path java
i am trying to create the letter A with the general path in java. i have got the general shape down, but I need to animate it
the two sides are slowly going up and the center dash is just static. I'm not sure how to use the count variable in the loop to make it go from left to right.
import java.awt.*;
import java.util.*;
import java.awt.Color;
import java.awt.geom.*;
import javax.swing.*;
public class sign implements Moveable {
private int xx;
private int yy;
private int width;
public int count = 0;
// constructor
public sign(int x0, int y0, int w) {
xx = x0;
yy = y0;
width = w;
}// end constructor
// implementation of Moveable
public void translate(int dx, int dy) {
int delx = dx; // horizontal increment or decrement (depending on current position)
int dely = dy; // vertical displacement
count = count + 1;
}
public void draw(Graphics2D g2) {
g2.setColor(Color.BLACK);
Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, 600, 600);
g2.fill(rect);
if (count < 70) {
Random gen = new Random();
// paint
for (int i = 0; i <= count; i = i + 1) {
Color c = new Color(Math.abs(gen.nextInt()) % 255, Math.abs(gen.nextInt()) %
255, Math.abs(gen.nextInt()) % 255);
g2.setColor(c);
GeneralPath path1 = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 50);
GeneralPath path2 = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 50);
GeneralPath path3 = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 50);
path1.moveTo(100, 500);
path1.lineTo(100 + (count - i), 500 - 4 * (count - i));
path1.lineTo(150 + (count - i), 500 - 4 * (count - i));
path1.lineTo(150, 500);
path1.lineTo(100, 500);
path2.moveTo(290, 500);
path2.lineTo(290 - (count - i), 500 - 4 * (count - i));
path2.lineTo(350 - (count - i), 500 - 4 * (count - i));
path2.lineTo(350, 500);
path2.lineTo(290, 500);
path3.moveTo(150, 400);
path3.lineTo(150 , 380);
path3.lineTo(290, 380);
path3.lineTo(290, 400);
g2.fill(path1);
g2.draw(path1);
g2.fill(path2);
g2.draw(path2);
g2.fill(path3);
g2.draw(path3);
} // end of paint method
} else {
count = 0;
}
} // end draw
}
if anyone could help me animate that center dash in the letter "A" that would be great.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
