import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.applet.*; public class Liivakell extends Applet implements MouseListener, Runnable{ int x=60; int y=60; int a=50; int b=100; int c=50; int d=139; int e=100; int f=139; int bb=95; boolean kukkumine=true; boolean keeramine=false; double nurk=0; Maatriks uuskoht; Maatriks muutus=new Maatriks( Math.cos(nurk), Math.sin(nurk), -Math.sin(nurk), Math.cos(nurk) ); Maatriks asukoht=new Maatriks(10, 2); int kx=75, ky=95; public Liivakell(){ asukoht.m=new double[][]{ {50, 50}, {100, 50}, {50, 80}, {100, 80}, {70, 95}, {80, 95}, {50, 110}, {100, 110}, {50, 140}, {100, 140} }; for(int k=0; k90){ x=60; y=60; a=50; c=50; e=100; b=100; d=139; f=139; bb=95; } if(x<=90){ if(x<90){ d=d-1; f=f-1; } if(y>=80){ a=a+1; b=b-1; } x=x+1; y=y+1; if(x<=90){ bb=bb+5; } if(bb>d){ bb=95; } } repaint(); } if(keeramine){ System.out.println("keerab"); try{Thread.sleep(15);} catch(Exception viga){} if(nurk<3.14){ uuskoht=asukoht.korruta(muutus); repaint(); nurk=nurk+0.01; muutus=new Maatriks( Math.cos(nurk), Math.sin(nurk), -Math.sin(nurk), Math.cos(nurk) ); } if(nurk>=3.14){ keeramine=false; kukkumine=true; nurk=0; } } } } public void joonistaKujund(Graphics g, Maatriks koht){ double[][] m=koht.m; g.drawLine(kx+(int)m[0][0], ky-(int)m[0][1], kx+(int)m[2][0], ky-(int)m[2][1]); g.drawLine(kx+(int)m[0][0], ky-(int)m[0][1], kx+(int)m[1][0], ky-(int)m[1][1]); g.drawLine(kx+(int)m[2][0], ky-(int)m[2][1], kx+(int)m[4][0], ky-(int)m[4][1]); g.drawLine(kx+(int)m[1][0], ky-(int)m[1][1], kx+(int)m[3][0], ky-(int)m[3][1]); g.drawLine(kx+(int)m[3][0], ky-(int)m[3][1], kx+(int)m[5][0], ky-(int)m[5][1]); g.drawLine(kx+(int)m[4][0], ky-(int)m[4][1], kx+(int)m[6][0], ky-(int)m[6][1]); g.drawLine(kx+(int)m[5][0], ky-(int)m[5][1], kx+(int)m[7][0], ky-(int)m[7][1]); g.drawLine(kx+(int)m[6][0], ky-(int)m[6][1], kx+(int)m[8][0], ky-(int)m[8][1]); g.drawLine(kx+(int)m[7][0], ky-(int)m[7][1], kx+(int)m[9][0], ky-(int)m[9][1]); g.drawLine(kx+(int)m[8][0], ky-(int)m[8][1], kx+(int)m[9][0], ky-(int)m[9][1]); } public void paint(Graphics g){ if(kukkumine==true){ joonistaKujund(g, asukoht); g.setColor(Color.yellow); g.drawLine(a, x, b, y); g.drawLine(c, d, e, f); g.fillOval(72, bb, 4, 4); if(x>90){ g.setColor(Color.white); g.fillOval(72, bb, 4, 4); } } if(keeramine==true){ g.setColor(Color.black); joonistaKujund(g, uuskoht); System.out.println("Joonistab keeratult"); } } public void mousePressed(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){ x=e.getX(); y=e.getY(); if(x>=50 && y>=50 && x<=100 && y<=140){ keeramine=true; kukkumine=false; } } public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public static void main(String[] argumendid){ Frame f=new Frame(); f.add(new Liivakell()); f.setSize(300, 300); f.setVisible(true); } }