java - How to draw a line that spins around and around? -



java - How to draw a line that spins around and around? -

i'm trying draw line spins around , around, unfortunately, i'm not managing right far. if know how wrong please point out me. thanks. oh, btw, paints out fine, line not managing spin around in finish circle. spins halfway, , spins backward.

public class test2 extends drag { static int x1 = 200; static int x2 = 400; static int y1 = 250; static int y2 = 250; static int whichquad; static int initialx1 = 200; static int initialx2 = 400; static int initialy1 = 250; static int initialy2 = 250; public static void main(string args[]) throws interruptedexception { // maybe y1, , y2 have x2/2? yesssssssssssssssssss // okay given. initial y1 have equal initali y2; // x1+(x1/2) // if x1 == 0, quad == 1; // if x1 == 5, , y1 == 0, quad == 2; // if x1 == 10, quad == 3; // if x1 == 5, , y1 == 10, quad == 4; // if x1 == initialx1, quad == 1; // ******if x1 == (initialx1/2)+(initialx2/2), , y1 == initialy2 - // initialy1, quad == 2; // if x1 == initialx2, quad == 3; // ******if x1 == (initialx1/2)+(initialx2/2), , y1 == initialx2, // quad == 4; // if quad == 1, x1++,x2--,y1--,y2++ // if quad == 2, x1++,x2--,y1++,y2-- // if quad == 3, x1--,x2++,y1++,y2-- // if quad == 4, x1--,x2++,y1--,y2++ frame.frame.add(paint.paint); frame.frame(); while (true) { if (x1 == initialx1) { whichquad = 1; } if (x1 == (initialx1 / 2) + (initialx2 / 2) && y1 == initialx2/2) { whichquad = 2; } if (x1 == initialx2) { whichquad = 3; } if (x1 == (initialx1 / 2) + (initialx2 / 2) && y1 == initialx1) { whichquad = 4; } if (whichquad == 1) { x1++; x2--; if(y1 != initialy2 - initialy1){ y1--;} y2++; } if (whichquad == 2) { x1++; x2--; y1++; y2--; } if (whichquad == 3) { x1--; x2++; y1++; y2--; } if (whichquad == 4) { x1--; x2++; if(y1 != initialy2 - initialy1){ y1--;} y2++; } system.out.println("(" + whichquad + ")" + "x1:" + x1 + " y1:" + y1 + " x2:" + x2 + " y2:" + y2); thread.sleep(50); frame.frame.repaint(); } } }

your code right. seek this.

if (x1 == initialx1) { whichquad = 1; } if (x1 == (initialx1 / 2) + (initialx2 / 2) && y1 < initialy1) { whichquad = 2; } if (x1 == initialx2) { whichquad = 3; } if (x1 == (initialx1 / 2) + (initialx2 / 2) && y1 > initialy1) { whichquad = 4; }

java graphics draw lines movement

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -