Stifte verfolgen sich

[Startseite]


Programmgesteuertes Zeichnen ] Freihandzeichnen ] Das Ballprojekt ] Autorennen ] Weitere Beispiele ] Der Zug ] n-Damen-Problem ] Drucken mit stiftUndCo ] Türme von Hanoi ]
Kochsche Kurve
Windmühlen
Die Uhr
Stifte verfolgen sich
Stifte verfolgen sich

Beispiel für Felder, hier mit der Ereignisanwendung realisiert, was aber nicht nötig ist.  Probieren Sie es aus, indem Sie mit der linken oder rechten Maustaste in den Appletbereich klicken.

import stiftUndCo.*;
import java.awt.*;

public class Verfolgung extends EreignisAnwendung // alternativ: EreignisApplet
{
	private BuntStift[] b;	// Feld von Buntstiften
	private int anzahl;
	private double xm,ym,radius;

	public Verfolgung() // alternativ void initApplet()
	{
		 super(); // im Applet weglassen
		 anzahl=10;
		 xm=bildschirm().breite()/2;
		 ym=bildschirm().hoehe()/2;
		 radius=xm;
		 if (ym<xm) { radius=ym;}
		 radius=radius-5;
		
		b = new BuntStift[anzahl]; 
		/* Das Objekt b wird als Feld mit 
    					anzahl Elementen erzeugt*/


		for (int i=0; i < anzahl;i++)
		{ b[i]=new BuntStift(this.bildschirm()); 		
// die Felder des Objektes b werden erzeugt
		  
		}
	}

	public void bearbeiteMausDruck(int x, int y)
	{

		stift().setzeFuellMuster(Muster.GEFUELLT);
		stift().setzeFarbe(Farbe.rgb(Hilfe.zufall(0,255)
			,Hilfe.zufall(0,255)
    		,Hilfe.zufall(0,255)));
		stift().bewegeBis(0,0);
		stift().zeichneRechteck(bildschirm().breite()
			,bildschirm().hoehe());
		for (int i=0; i < anzahl;i++)
		{ 
			b[i].hoch();
			b[i].bewegeBis(xm,ym);
			b[i].dreheBis((360/anzahl)*i);
			b[i].bewegeUm(radius);
			b[i].setzeFarbe(Farbe.rgb(Hilfe.zufall(0,255)
				,Hilfe.zufall(0,255)
				,Hilfe.zufall(0,255)));
			b[i].runter();
		}
	}
	public void bearbeiteMausDruckRechts(int x, int y)
	{

		stift().setzeFuellMuster(Muster.GEFUELLT);
		stift().setzeFarbe(Farbe.rgb(Hilfe.zufall(0,255)
				,Hilfe.zufall(0,255)
				,Hilfe.zufall(0,255)));
		stift().bewegeBis(0,0);
		stift().zeichneRechteck(bildschirm().breite()
			,bildschirm().hoehe());

		for (int i=0; i < anzahl;i++)
		{ 
		b[i].hoch();
		b[i].bewegeBis(Hilfe.zufall(1,2*(int)xm)
			,Hilfe.zufall(1,2*(int)ym));
		
		b[i].setzeFarbe(Farbe.rgb(Hilfe.zufall(0,255)
			,Hilfe.zufall(0,255)
			,Hilfe.zufall(0,255)));
		b[i].runter();
		}
	}

	public void bearbeiteAndereEreignisse()
	{
			
		for (int i=0; i < anzahl-1; i++)
		{
			b[i].bewegeBis(b[i].hPosition()+	
				 0.2*(b[i+1].hPosition()-b[i].hPosition()),
			b[i].vPosition()
				+0.2*(b[i+1].vPosition()-b[i].vPosition()));
		} 
		// ende for
		b[anzahl-1].bewegeBis(b[anzahl-1].hPosition()+
				 0.2*(b[1].hPosition()-b[anzahl-1].hPosition()),
		b[anzahl-1].vPosition()
			+0.2*(b[1].vPosition()-b[anzahl-1].vPosition()));
	}

}
 

 


Seitenanfang

© Georg Dick