mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-04-14 06:33:34 +02:00
Test classes
This commit is contained in:
29
test/res/bluej-project/Attractor.java
Normal file
29
test/res/bluej-project/Attractor.java
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
import schule.ngb.zm.*;
|
||||
|
||||
public class Attractor extends Mover {
|
||||
|
||||
private static final int G = 10;
|
||||
|
||||
private int mass = 0;
|
||||
|
||||
public Attractor( int x, int pY, int pMass ) {
|
||||
this(x, pY, pMass, new Vector());
|
||||
}
|
||||
|
||||
public Attractor( int x, int pY, int pMass, Vector pVelocity ) {
|
||||
super(x, pY, pVelocity);
|
||||
mass = pMass;
|
||||
|
||||
setFillColor(YELLOW);
|
||||
}
|
||||
|
||||
public void attract( Mover pMover ) {
|
||||
if( pMover != this ) {
|
||||
Vector force = new Vector(this.x, this.y);
|
||||
force.sub(pMover.getX(), pMover.getY()).scale(mass*G).limit(0, 50*G);
|
||||
pMover.applyForce(force);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
34
test/res/bluej-project/BluejTest.java
Normal file
34
test/res/bluej-project/BluejTest.java
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
import schule.ngb.zm.Zeichenmaschine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Beschreiben Sie hier die Klasse BluejTest.
|
||||
*
|
||||
* @author (Ihr Name)
|
||||
* @version (eine Versionsnummer oder ein Datum)
|
||||
*/
|
||||
public class BluejTest extends Zeichenmaschine
|
||||
{
|
||||
public void setup() {
|
||||
if( !IN_BLUEJ ) {
|
||||
drawing.clear(schule.ngb.zm.Color.HGRED);
|
||||
} else {
|
||||
drawing.clear(schule.ngb.zm.Color.HGGREEN);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void listClasses() {
|
||||
// find all classes in classpath
|
||||
List<String> allClasses = ClasspathInspector.getAllKnownClassNames();
|
||||
System.out.printf("There are %s classes available in the classpath\n", allClasses.size());
|
||||
|
||||
for (String clazz : allClasses) {
|
||||
if( clazz.contains("Boot") || clazz.contains("Main") ) {
|
||||
System.out.printf("%s\n", clazz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
283
test/res/bluej-project/ClasspathInspector.java
Normal file
283
test/res/bluej-project/ClasspathInspector.java
Normal file
@@ -0,0 +1,283 @@
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.Serializable;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
/**
|
||||
* Find classes in the classpath (reads JARs and classpath folders).
|
||||
*
|
||||
* @author Pål Brattberg, brattberg@gmail.com
|
||||
* @see http://gist.github.com/pal
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ClasspathInspector {
|
||||
static boolean DEBUG = false;
|
||||
|
||||
|
||||
public static List<String> getAllKnownClassNames() {
|
||||
List<String> classNames = new ArrayList<String>();
|
||||
List<File> classLocations = getClassLocationsForCurrentClasspath();
|
||||
for (File file : classLocations) {
|
||||
classNames.addAll(getClassNamesFromPath(file));
|
||||
}
|
||||
return classNames;
|
||||
}
|
||||
|
||||
public static List<Class> getAllKnownClasses() {
|
||||
List<Class> classFiles = new ArrayList<Class>();
|
||||
List<File> classLocations = getClassLocationsForCurrentClasspath();
|
||||
for (File file : classLocations) {
|
||||
classFiles.addAll(getClassesFromPath(file));
|
||||
}
|
||||
return classFiles;
|
||||
}
|
||||
|
||||
public static List<Class> getMatchingClasses(Class interfaceOrSuperclass) {
|
||||
List<Class> matchingClasses = new ArrayList<Class>();
|
||||
List<Class> classes = getAllKnownClasses();
|
||||
log("checking %s classes", classes.size());
|
||||
for (Class clazz : classes) {
|
||||
if (interfaceOrSuperclass.isAssignableFrom(clazz)) {
|
||||
matchingClasses.add(clazz);
|
||||
log("class %s is assignable from %s", interfaceOrSuperclass, clazz);
|
||||
}
|
||||
}
|
||||
return matchingClasses;
|
||||
}
|
||||
|
||||
public static List<Class> getMatchingClasses(String validPackagePrefix, Class interfaceOrSuperclass) {
|
||||
throw new IllegalStateException("Not yet implemented!");
|
||||
}
|
||||
|
||||
public static List<Class> getMatchingClasses(String validPackagePrefix) {
|
||||
throw new IllegalStateException("Not yet implemented!");
|
||||
}
|
||||
|
||||
private static Collection<? extends Class> getClassesFromPath(File path) {
|
||||
if (path.isDirectory()) {
|
||||
return getClassesFromDirectory(path);
|
||||
} else {
|
||||
return getClassesFromJarFile(path);
|
||||
}
|
||||
}
|
||||
|
||||
private static Collection<String> getClassNamesFromPath(File path) {
|
||||
if (path.isDirectory()) {
|
||||
return getClassNamesFromDirectory(path);
|
||||
} else {
|
||||
return getClassNamesFromJarFile(path);
|
||||
}
|
||||
}
|
||||
|
||||
private static String fromFileToClassName(final String fileName) {
|
||||
return fileName.substring(0, fileName.length() - 6).replaceAll("/|\\\\", "\\.");
|
||||
}
|
||||
|
||||
private static List<Class> getClassesFromJarFile(File path) {
|
||||
List<Class> classes = new ArrayList<Class>();
|
||||
log("getClassesFromJarFile: Getting classes for " + path);
|
||||
|
||||
try {
|
||||
if (path.canRead()) {
|
||||
JarFile jar = new JarFile(path);
|
||||
Enumeration<JarEntry> en = jar.entries();
|
||||
while (en.hasMoreElements()) {
|
||||
JarEntry entry = en.nextElement();
|
||||
if (entry.getName().endsWith("class")) {
|
||||
String className = fromFileToClassName(entry.getName());
|
||||
log("\tgetClassesFromJarFile: found " + className);
|
||||
Class claz = Class.forName(className);
|
||||
classes.add(claz);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to read classes from jar file: " + path, e);
|
||||
}
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
private static List<String> getClassNamesFromJarFile(File path) {
|
||||
List<String> classes = new ArrayList<>();
|
||||
log("getClassNamesFromJarFile: Getting classes for " + path);
|
||||
|
||||
try {
|
||||
if (path.canRead()) {
|
||||
JarFile jar = new JarFile(path);
|
||||
Enumeration<JarEntry> en = jar.entries();
|
||||
while (en.hasMoreElements()) {
|
||||
JarEntry entry = en.nextElement();
|
||||
if (entry.getName().endsWith("class")) {
|
||||
String className = fromFileToClassName(entry.getName());
|
||||
classes.add(className);
|
||||
log("\tgetClassesFromJarFile: found " + className);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to read classnames from jar file: " + path, e);
|
||||
}
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
private static List<Class> getClassesFromDirectory(File path) {
|
||||
List<Class> classes = new ArrayList<Class>();
|
||||
log("getClassesFromDirectory: Getting classes for " + path);
|
||||
|
||||
// get jar files from top-level directory
|
||||
List<File> jarFiles = listFiles(path, new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".jar");
|
||||
}
|
||||
}, false);
|
||||
for (File file : jarFiles) {
|
||||
classes.addAll(getClassesFromJarFile(file));
|
||||
}
|
||||
|
||||
// get all class-files
|
||||
List<File> classFiles = listFiles(path, new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".class");
|
||||
}
|
||||
}, true);
|
||||
|
||||
// List<URL> urlList = new ArrayList<URL>();
|
||||
// List<String> classNameList = new ArrayList<String>();
|
||||
int substringBeginIndex = path.getAbsolutePath().length() + 1;
|
||||
for (File classfile : classFiles) {
|
||||
String className = classfile.getAbsolutePath().substring(substringBeginIndex);
|
||||
className = fromFileToClassName(className);
|
||||
log("Found class %s in path %s: ", className, path);
|
||||
try {
|
||||
classes.add(Class.forName(className));
|
||||
} catch (Throwable e) {
|
||||
log("Couldn't create class %s. %s: ", className, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
private static List<String> getClassNamesFromDirectory(File path) {
|
||||
List<String> classes = new ArrayList<>();
|
||||
log("getClassNamesFromDirectory: Getting classes for " + path);
|
||||
|
||||
// get jar files from top-level directory
|
||||
List<File> jarFiles = listFiles(path, new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".jar");
|
||||
}
|
||||
}, false);
|
||||
for (File file : jarFiles) {
|
||||
classes.addAll(getClassNamesFromJarFile(file));
|
||||
}
|
||||
|
||||
// get all class-files
|
||||
List<File> classFiles = listFiles(path, new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".class");
|
||||
}
|
||||
}, true);
|
||||
|
||||
// List<URL> urlList = new ArrayList<URL>();
|
||||
// List<String> classNameList = new ArrayList<String>();
|
||||
int substringBeginIndex = path.getAbsolutePath().length() + 1;
|
||||
for (File classfile : classFiles) {
|
||||
String className = classfile.getAbsolutePath().substring(substringBeginIndex);
|
||||
className = fromFileToClassName(className);
|
||||
log("Found class %s in path %s: ", className, path);
|
||||
classes.add(className);
|
||||
}
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
private static List<File> listFiles(File directory, FilenameFilter filter, boolean recurse) {
|
||||
List<File> files = new ArrayList<File>();
|
||||
File[] entries = directory.listFiles();
|
||||
|
||||
// Go over entries
|
||||
for (File entry : entries) {
|
||||
// If there is no filter or the filter accepts the
|
||||
// file / directory, add it to the list
|
||||
if (filter == null || filter.accept(directory, entry.getName())) {
|
||||
files.add(entry);
|
||||
}
|
||||
|
||||
// If the file is a directory and the recurse flag
|
||||
// is set, recurse into the directory
|
||||
if (recurse && entry.isDirectory()) {
|
||||
files.addAll(listFiles(entry, filter, recurse));
|
||||
}
|
||||
}
|
||||
|
||||
// Return collection of files
|
||||
return files;
|
||||
}
|
||||
|
||||
public static List<File> getClassLocationsForCurrentClasspath() {
|
||||
List<File> urls = new ArrayList<File>();
|
||||
String javaClassPath = System.getProperty("java.class.path");
|
||||
if (javaClassPath != null) {
|
||||
for (String path : javaClassPath.split(File.pathSeparator)) {
|
||||
urls.add(new File(path));
|
||||
}
|
||||
}
|
||||
return urls;
|
||||
}
|
||||
|
||||
// todo: this is only partial, probably
|
||||
public static URL normalize(URL url) throws MalformedURLException {
|
||||
String spec = url.getFile();
|
||||
|
||||
// get url base - remove everything after ".jar!/??" , if exists
|
||||
final int i = spec.indexOf("!/");
|
||||
if (i != -1) {
|
||||
spec = spec.substring(0, spec.indexOf("!/"));
|
||||
}
|
||||
|
||||
// uppercase windows drive
|
||||
url = new URL(url, spec);
|
||||
final String file = url.getFile();
|
||||
final int i1 = file.indexOf(':');
|
||||
if (i1 != -1) {
|
||||
String drive = file.substring(i1 - 1, 2).toUpperCase();
|
||||
url = new URL(url, file.substring(0, i1 - 1) + drive + file.substring(i1));
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
private static void log(String pattern, final Object... args) {
|
||||
if (DEBUG)
|
||||
System.out.printf(pattern + "\n", args);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// find all classes in classpath
|
||||
List<Class> allClasses = ClasspathInspector.getAllKnownClasses();
|
||||
System.out.printf("There are %s classes available in the classpath\n", allClasses.size());
|
||||
|
||||
// find all classes that implement/subclass an interface/superclass
|
||||
List<Class> serializableClasses = ClasspathInspector.getMatchingClasses(Serializable.class);
|
||||
for (Class clazz : serializableClasses) {
|
||||
System.out.printf("%s is Serializable\n", clazz);
|
||||
}
|
||||
}
|
||||
}
|
||||
40
test/res/bluej-project/Gravity.java
Normal file
40
test/res/bluej-project/Gravity.java
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import schule.ngb.zm.*;
|
||||
|
||||
public class Gravity extends Zeichenmaschine {
|
||||
|
||||
private LinkedList<Mover> movers = new LinkedList<>();
|
||||
|
||||
private LinkedList<Attractor> attractors = new LinkedList<>();
|
||||
|
||||
public void setup(){
|
||||
for( int i = 0; i < 10; i++ ) {
|
||||
Mover m = new Mover(random(10, width-10), random(10, height-10));
|
||||
movers.add(m);
|
||||
shapes.add(m);
|
||||
}
|
||||
|
||||
attractors.add(new Attractor(width/2, height/2, 10));
|
||||
shapes.add(attractors.get(0));
|
||||
}
|
||||
|
||||
public void update( double delta ) {
|
||||
for( Attractor a: attractors ) {
|
||||
for( Mover m: movers ) {
|
||||
a.attract(m);
|
||||
}
|
||||
}
|
||||
|
||||
for( Mover m: movers ) {
|
||||
m.update(delta);
|
||||
}
|
||||
shapes.clear();
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
shapes.clear();
|
||||
}
|
||||
|
||||
}
|
||||
38
test/res/bluej-project/Mover.java
Normal file
38
test/res/bluej-project/Mover.java
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
import schule.ngb.zm.*;
|
||||
import schule.ngb.zm.formen.*;
|
||||
|
||||
public class Mover extends Circle implements Updatable {
|
||||
|
||||
private Vector velocity;
|
||||
private Vector acceleration = new Vector();
|
||||
|
||||
public Mover( int x, int pY ) {
|
||||
this(x, pY, new Vector());
|
||||
}
|
||||
|
||||
public Mover( int x, int pY, Vector pVelocity ) {
|
||||
super(x, pY, 10);
|
||||
this.velocity = pVelocity.copy();
|
||||
}
|
||||
|
||||
public void applyForce( Vector force ) {
|
||||
acceleration.add(force);
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void update( double delta ) {
|
||||
acceleration.scale(delta);
|
||||
velocity.add(acceleration);
|
||||
acceleration.scale(0.0);
|
||||
|
||||
this.x += velocity.x;
|
||||
this.y += velocity.y;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
69
test/res/bluej-project/package.bluej
Normal file
69
test/res/bluej-project/package.bluej
Normal file
@@ -0,0 +1,69 @@
|
||||
#BlueJ package file
|
||||
dependency1.from=BluejTest
|
||||
dependency1.to=ClasspathInspector
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=Gravity
|
||||
dependency2.to=Mover
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=Gravity
|
||||
dependency3.to=Attractor
|
||||
dependency3.type=UsesDependency
|
||||
editor.fx.0.height=728
|
||||
editor.fx.0.width=1037
|
||||
editor.fx.0.x=95
|
||||
editor.fx.0.y=53
|
||||
objectbench.height=94
|
||||
objectbench.width=776
|
||||
package.divider.horizontal=0.6
|
||||
package.divider.vertical=0.8305369127516778
|
||||
package.editor.height=488
|
||||
package.editor.width=661
|
||||
package.editor.x=374
|
||||
package.editor.y=158
|
||||
package.frame.height=660
|
||||
package.frame.width=800
|
||||
package.numDependencies=3
|
||||
package.numTargets=5
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
readme.height=60
|
||||
readme.name=@README
|
||||
readme.width=48
|
||||
readme.x=10
|
||||
readme.y=10
|
||||
target1.height=70
|
||||
target1.name=Mover
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.width=120
|
||||
target1.x=320
|
||||
target1.y=200
|
||||
target2.height=70
|
||||
target2.name=BluejTest
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.width=120
|
||||
target2.x=70
|
||||
target2.y=10
|
||||
target3.height=70
|
||||
target3.name=Attractor
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.width=120
|
||||
target3.x=390
|
||||
target3.y=350
|
||||
target4.height=70
|
||||
target4.name=ClasspathInspector
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.width=130
|
||||
target4.x=380
|
||||
target4.y=30
|
||||
target5.height=70
|
||||
target5.name=Gravity
|
||||
target5.showInterface=false
|
||||
target5.type=ClassTarget
|
||||
target5.width=120
|
||||
target5.x=100
|
||||
target5.y=300
|
||||
@@ -1,114 +1,112 @@
|
||||
package schule.ngb.zm;
|
||||
|
||||
import schule.ngb.zm.formen.Form;
|
||||
import schule.ngb.zm.formen.Rechteck;
|
||||
import schule.ngb.zm.formen.Rectangle;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
public class TestAttraction extends Zeichenfenster {
|
||||
public class TestAttraction extends Zeichenmaschine {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new TestAttraction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void einstellungen() {
|
||||
public void settings() {
|
||||
setSize(800, 600);
|
||||
setTitel("My test Window");
|
||||
setTitle("My test Window");
|
||||
//setFramesPerSecond(5);
|
||||
|
||||
s2dl = new Shape2DEbene();
|
||||
hinzu(s2dl);
|
||||
s2dl = new Shape2DLayer();
|
||||
addLayer(s2dl);
|
||||
}
|
||||
|
||||
Shape2DEbene s2dl;
|
||||
Shape2DLayer s2dl;
|
||||
|
||||
Vektor posA, posB, velB, posC, velC;
|
||||
Vector posA, posB, velB, posC, velC;
|
||||
|
||||
double massA = 500, massB = 1, massC = 4.3, G = 5.0;
|
||||
|
||||
Rechteck recht;
|
||||
Rectangle recht;
|
||||
|
||||
@Override
|
||||
public void vorbereiten() {
|
||||
public void setup() {
|
||||
//zeichnung.hide();
|
||||
zeichnung.clear(200);
|
||||
posA = new Vektor(0, 0);
|
||||
posB = new Vektor(-100, -100);
|
||||
velB = new Vektor(10, -10);
|
||||
posC = new Vektor(200, 100);
|
||||
velC = new Vektor(1, 14);
|
||||
drawing.clear(200);
|
||||
posA = new Vector(0, 0);
|
||||
posB = new Vector(-100, -100);
|
||||
velB = new Vector(10, -10);
|
||||
posC = new Vector(200, 100);
|
||||
velC = new Vector(1, 14);
|
||||
|
||||
zeichnung.translate(breite /2, hoehe /2);
|
||||
zeichnung.shear(0.1, 0.5);
|
||||
drawing.translate(width /2, height /2);
|
||||
drawing.shear(0.1, 0.5);
|
||||
|
||||
recht = new Rechteck(50, 50, 150, 75);
|
||||
recht.setFuellfarbe(200);
|
||||
recht.setKonturFarbe(255, 0, 64);
|
||||
recht.setKonturDicke(2.5);
|
||||
recht.setKonturArt(Form.GESTRICHELT);
|
||||
formen.anzeigen(recht);
|
||||
recht = new Rectangle(50, 50, 150, 75);
|
||||
recht.setFillColor(200);
|
||||
recht.setStrokeColor(255, 0, 64);
|
||||
recht.setStrokeWeight(2.5);
|
||||
recht.setStrokeType(DASHED);
|
||||
shapes.add(recht);
|
||||
|
||||
zeichnung.verstecken();
|
||||
drawing.hide();
|
||||
//schule.ngb.zm.formen.verstecken();
|
||||
|
||||
s2dl.setColor(64,200,128);
|
||||
s2dl.setFillColor(64,200,128);
|
||||
s2dl.add(new Rectangle2D.Double(100, 100, 120, 80));
|
||||
}
|
||||
|
||||
public void zeichnen() {
|
||||
zeichnung.setStrokeColor(255);
|
||||
zeichnung.setStrokeWeight(4.0);
|
||||
zeichnung.setKonturArt(GESTRICHELT);
|
||||
zeichnung.clear(33, 33, 33, 100);
|
||||
public void draw() {
|
||||
drawing.setStrokeColor(255);
|
||||
drawing.setStrokeWeight(4.0);
|
||||
drawing.setStrokeType(DASHED);
|
||||
drawing.clear(33, 33, 33, 100);
|
||||
|
||||
zeichnung.setColor(Color.ORANGE);
|
||||
zeichnung.pie(posA.x, posA.y, 80, 30, 60);
|
||||
zeichnung.setColor(Color.YELLOW);
|
||||
zeichnung.circle(posA.x, posA.y, 60);
|
||||
drawing.setColor(Color.ORANGE);
|
||||
drawing.pie(posA.x, posA.y, 80, 30, 60);
|
||||
drawing.setColor(Color.YELLOW);
|
||||
drawing.circle(posA.x, posA.y, 60);
|
||||
|
||||
Vektor acc = acceleration(posA, posB, massA, massB);
|
||||
velB.addieren(acc);
|
||||
posB.addieren(velB);
|
||||
Vector acc = acceleration(posA, posB, massA, massB);
|
||||
velB.add(acc);
|
||||
posB.add(velB);
|
||||
|
||||
zeichnung.setColor(Color.BLUE);
|
||||
zeichnung.circle(posB.x, posB.y, 20);
|
||||
drawing.setColor(Color.BLUE);
|
||||
drawing.circle(posB.x, posB.y, 20);
|
||||
|
||||
acc = acceleration(posA, posC, massA, massC);
|
||||
velC.addieren(acc);
|
||||
posC.addieren(velC);
|
||||
velC.add(acc);
|
||||
posC.add(velC);
|
||||
|
||||
zeichnung.setColor(Color.GREEN);
|
||||
zeichnung.circle(posC.x, posC.y, 20);
|
||||
drawing.setColor(Color.GREEN);
|
||||
drawing.circle(posC.x, posC.y, 20);
|
||||
|
||||
zeichnung.rotate(1);
|
||||
drawing.rotate(1);
|
||||
|
||||
formen.leeren();
|
||||
shapes.clear();
|
||||
double x = recht.getX();
|
||||
x = (x+100*delta)% breite;
|
||||
x = (x+100*delta)% width;
|
||||
recht.setX(x);
|
||||
}
|
||||
|
||||
Vektor acceleration(Vektor a, Vektor b, double ma, double mb ) {
|
||||
Vektor acc = Vektor.subtrahieren(a, b);
|
||||
double draw = (G*ma*mb)/acc.laengeQuad();
|
||||
acc.setLaenge(draw*delta);
|
||||
acc.beschraenken(3, 30);
|
||||
Vector acceleration( Vector a, Vector b, double ma, double mb ) {
|
||||
Vector acc = Vector.sub(a, b);
|
||||
double draw = (G*ma*mb)/acc.lenSq();
|
||||
acc.setLen(draw*delta);
|
||||
acc.limit(3, 30);
|
||||
return acc;
|
||||
}
|
||||
|
||||
public void mouseDragged() {
|
||||
zeichnung.translate(mausX - lmausX, mausY - lmausY);
|
||||
drawing.translate(mouseX - pmouseX, mouseY - pmouseY);
|
||||
}
|
||||
|
||||
boolean zoom = true;
|
||||
public void mouseClicked() {
|
||||
//canvas.translateToCanvas(mouseX-width/2.0, mouseY-height/2.0);
|
||||
if( zoom ) {
|
||||
zeichnung.scale(2.0);
|
||||
drawing.scale(2.0);
|
||||
} else {
|
||||
zeichnung.scale(.5);
|
||||
drawing.scale(.5);
|
||||
}
|
||||
zoom = !zoom;
|
||||
}
|
||||
|
||||
145
test/src/schule/ngb/zm/TestColor.java
Normal file
145
test/src/schule/ngb/zm/TestColor.java
Normal file
@@ -0,0 +1,145 @@
|
||||
package schule.ngb.zm;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TestColor {
|
||||
|
||||
@Test
|
||||
public void colors() {
|
||||
Color c;
|
||||
|
||||
c = new Color();
|
||||
assertEquals(0, c.getRed());
|
||||
assertEquals(0, c.getGreen());
|
||||
assertEquals(0, c.getBlue());
|
||||
assertEquals(255, c.getAlpha());
|
||||
|
||||
c = Color.BLUE;
|
||||
assertEquals(0, c.getRed());
|
||||
assertEquals(0, c.getGreen());
|
||||
assertEquals(255, c.getBlue());
|
||||
assertEquals(255, c.getAlpha());
|
||||
|
||||
c = new Color(50, 133, 64, 33);
|
||||
assertEquals(50, c.getRed());
|
||||
assertEquals(133, c.getGreen());
|
||||
assertEquals(64, c.getBlue());
|
||||
assertEquals(33, c.getAlpha());
|
||||
|
||||
c = new Color(255, 0, 0);
|
||||
assertEquals(Color.RED, c);
|
||||
|
||||
c = new Color(33, 50);
|
||||
assertEquals(33, c.getRed());
|
||||
assertEquals(33, c.getGreen());
|
||||
assertEquals(33, c.getBlue());
|
||||
assertEquals(50, c.getAlpha());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseColors() {
|
||||
Color c;
|
||||
|
||||
c = Color.parseRGB(0x00FF00FF);
|
||||
assertEquals(0x00FF00FF, c.getRGBA());
|
||||
assertEquals(255, c.getRed());
|
||||
assertEquals(0, c.getGreen());
|
||||
assertEquals(255, c.getBlue());
|
||||
assertEquals(0, c.getAlpha());
|
||||
|
||||
c = Color.parseRGB(0x33FF3333);
|
||||
assertEquals(0x33FF3333, c.getRGBA());
|
||||
assertEquals(255, c.getRed());
|
||||
assertEquals(51, c.getGreen());
|
||||
assertEquals(51, c.getBlue());
|
||||
assertEquals(51, c.getAlpha());
|
||||
|
||||
c = Color.parseHexcode("FF00FF");
|
||||
assertEquals(0xFFFF00FF, c.getRGBA());
|
||||
assertEquals(255, c.getRed());
|
||||
assertEquals(0, c.getGreen());
|
||||
assertEquals(255, c.getBlue());
|
||||
assertEquals(255, c.getAlpha());
|
||||
|
||||
c = Color.parseHexcode("#FF00FF00");
|
||||
assertEquals(0x00FF00FF, c.getRGBA());
|
||||
assertEquals(255, c.getRed());
|
||||
assertEquals(0, c.getGreen());
|
||||
assertEquals(255, c.getBlue());
|
||||
assertEquals(0, c.getAlpha());
|
||||
|
||||
c = Color.parseHexcode("#333");
|
||||
assertEquals(0xFF333333, c.getRGBA());
|
||||
assertEquals(51, c.getRed());
|
||||
assertEquals(51, c.getGreen());
|
||||
assertEquals(51, c.getBlue());
|
||||
assertEquals(255, c.getAlpha());
|
||||
|
||||
c = Color.parseHexcode("#33FF0033");
|
||||
assertEquals(0x3333FF00, c.getRGBA());
|
||||
assertEquals(51, c.getRed());
|
||||
assertEquals(255, c.getGreen());
|
||||
assertEquals(0, c.getBlue());
|
||||
assertEquals(51, c.getAlpha());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hsl() {
|
||||
Color c;
|
||||
float[] hsl;
|
||||
|
||||
c = Color.RED;
|
||||
hsl = Color.RGBtoHSL(c.getRGBA(), null);
|
||||
assertArrayEquals(new float[]{0f,1f,.5f}, hsl, 0.0001f);
|
||||
|
||||
c = new Color(255, 33, 64);
|
||||
hsl = Color.RGBtoHSL(c.getRGBA(), null);
|
||||
assertEquals(352, hsl[0], 1.0f);
|
||||
assertEquals(1.0f, hsl[1], .0001f);
|
||||
assertEquals(.5647f, hsl[2], .0001f);
|
||||
}
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new ColorPalette();
|
||||
}
|
||||
|
||||
static class ColorPalette extends Zeichenmaschine {
|
||||
public static final int SIZE = 10, COLORS = 16;
|
||||
|
||||
public void setup() {
|
||||
setSize(SIZE*COLORS, SIZE*COLORS);
|
||||
setTitle("Colors");
|
||||
|
||||
drawing.noStroke();
|
||||
drawing.setAnchor(NORTHWEST);
|
||||
|
||||
int steps = (int) (255.0/COLORS);
|
||||
Color c;
|
||||
for( int i = 0; i < COLORS; i++ ) {
|
||||
for( int j = 0; j < COLORS; j++ ) {
|
||||
c = new Color(i * steps, j * steps, (i+j)/2 * steps);
|
||||
drawing.setColor(c);
|
||||
drawing.rect(i*SIZE, j*SIZE, SIZE, SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
Color c = Color.HGGREEN;
|
||||
drawing.setColor(c);
|
||||
drawing.rect(0, 0, width/2, height);
|
||||
|
||||
for( int p = 10; p < 100; p += 10 ) {
|
||||
drawing.setColor(c.brighter(p));
|
||||
drawing.rect(width / 2, 0, width / 2, height / 2);
|
||||
drawing.setColor(c.darker(p));
|
||||
drawing.rect(width / 2, height / 2, width / 2, height / 2);
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
73
test/src/schule/ngb/zm/TestDrawing.java
Normal file
73
test/src/schule/ngb/zm/TestDrawing.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package schule.ngb.zm;
|
||||
|
||||
import schule.ngb.zm.util.List;
|
||||
|
||||
public class TestDrawing extends Zeichenmaschine {
|
||||
|
||||
private final double w = 100, h = 50;
|
||||
|
||||
private double xa = 50, ya = 50;
|
||||
|
||||
private double x2 = 200, y2 = 50;
|
||||
|
||||
int frames = 0;
|
||||
long start = 0;
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new TestDrawing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
drawing.setFont("AvenirNext-Medium", 14);
|
||||
drawing.setAnchor(NORTHWEST);
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
ya = (ya+1)%350;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
long ms = System.currentTimeMillis();
|
||||
|
||||
drawing.clear();
|
||||
|
||||
// x2 = mouseX;
|
||||
// y2 = mouseY;
|
||||
|
||||
drawing.resetStroke();
|
||||
drawing.rect(xa, ya, w, h);
|
||||
|
||||
//drawing.image("WitchCraftIcons_122_t.PNG", width/2, height/2, .5, CENTER);
|
||||
|
||||
for( int i = 0; i < 4; i++ ) {
|
||||
//delay(1000);
|
||||
drawing.resetStroke();
|
||||
drawing.rect(x2 + i*10, y2 + i * 75, w, h);
|
||||
connect(xa + w, ya + h / 2.0, x2 + i*10, y2 + i * 75 + h / 2.0);
|
||||
drawing.text("Rect " + i, x2 + i*10 + w / 2.0, y2 + i * 75 + h / 2.0, CENTER);
|
||||
}
|
||||
|
||||
|
||||
if( (System.currentTimeMillis()-start) >= 1000 ) {
|
||||
System.out.printf("FPS: %d\n", frames);
|
||||
frames = 0;
|
||||
start = System.currentTimeMillis();
|
||||
} else {
|
||||
frames += 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void connect( double x1, double y1, double x2, double y2 ) {
|
||||
double midx = (x1 + x2) / 2.0;
|
||||
drawing.setStrokeType(DASHED);
|
||||
drawing.setStrokeWeight(2.4);
|
||||
drawing.curve(x1, y1, midx, y1, midx, y2, x2, y2);
|
||||
//drawing.curve(x1, y1, x2, y1, x1, y2, x2, y2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,57 +1,104 @@
|
||||
package schule.ngb.zm;
|
||||
|
||||
import schule.ngb.zm.formen.*;
|
||||
import schule.ngb.zm.formen.Point;
|
||||
import schule.ngb.zm.formen.Polygon;
|
||||
import schule.ngb.zm.formen.Rectangle;
|
||||
import schule.ngb.zm.formen.Shape;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.Random;
|
||||
|
||||
public class TestFormen extends Zeichenfenster {
|
||||
public class TestFormen extends Zeichenmaschine {
|
||||
|
||||
Random rand = new Random();
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new TestFormen();
|
||||
}
|
||||
|
||||
|
||||
Kurve k;
|
||||
|
||||
@Override
|
||||
public void vorbereiten() {
|
||||
public void setup() {
|
||||
setSize(400, 400);
|
||||
|
||||
k = new Kurve(50, 50, 100, 50, 100, 100,150, 100);
|
||||
//formen.anzeigen(new Kurve(50, 50, 100, 50, 150, 100));
|
||||
formen.anzeigen(k);
|
||||
add(new Rectangle(20, 10, 40, 20));
|
||||
add(new Ellipse(40, 50, 40, 20));
|
||||
add(new Circle(40, 80, 10));
|
||||
|
||||
k.verschiebeNach(200, 200);
|
||||
k.skalieren(1.1);
|
||||
add(new Line(40, 100, 100, 40));
|
||||
add(new Arrow(200, 200, 105, 45));
|
||||
|
||||
showDot(k.getStartpunkt());
|
||||
showDot(k.getKontrollpunkt1());
|
||||
showDot(k.getKontrollpunkt2());
|
||||
showDot(k.getEndpunkt());
|
||||
shapes.add(new Point(200, 200));
|
||||
|
||||
add(new Rhombus(40, 200, 50, 120));
|
||||
add(new Kite(40, 200, 50, 120, .75));
|
||||
add(new Kite(40, 200, 50, 120, .25));
|
||||
|
||||
add(new RoundedRectangle(20, 300, 100, 60, 30));
|
||||
|
||||
add(new Arc(200, 200, 60, 90, 120));
|
||||
|
||||
add(new Polygon(250, 40, 300, 55, 321, 83, 200, 300));
|
||||
shapes.add(new Point(250, 40));
|
||||
shapes.add(new Point(300, 55));
|
||||
shapes.add(new Point(321, 83));
|
||||
shapes.add(new Point(200, 300));
|
||||
|
||||
add(new Triangle(300, 55, 355, 75, 345, 25));
|
||||
add(new Quad(300, 55, 355, 75, 345, 25, 300, 10));
|
||||
|
||||
add(new Curve(50, 50, 350, 50, 350, 350));
|
||||
add(new Curve(50, 50, 50, 350, 350, 50, 350, 350));
|
||||
|
||||
shapes.add(new Picture(300, 300, "WitchCraftIcons_122_t.PNG"));
|
||||
|
||||
add(new Text(200, 40, "Shapes 😊"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void aktualisieren( double delta ) {
|
||||
|
||||
public void update( double delta ) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void zeichnen() {
|
||||
formen.leeren();
|
||||
public void mouseClicked() {
|
||||
for( Shape s : shapes.getShapes() ) {
|
||||
randomizeShape(s);
|
||||
s.move(10, 10);
|
||||
}
|
||||
}
|
||||
|
||||
private void add( Shape s ) {
|
||||
shapes.add(randomizeShape(s));
|
||||
}
|
||||
|
||||
private Shape randomizeShape( Shape s ) {
|
||||
if( !(s instanceof Arc) && !(s instanceof Curve) && !(s instanceof Line) && !(s instanceof Arrow) ) {
|
||||
s.setFillColor(randomColor());
|
||||
}
|
||||
s.setStrokeColor(randomColor());
|
||||
s.setStrokeWeight(random(.75, 2.25));
|
||||
if( randomBool(20) ) {
|
||||
s.setStrokeType(DASHED);
|
||||
} else {
|
||||
s.setStrokeType(SOLID);
|
||||
}
|
||||
|
||||
//s.moveTo(random(20, 380), random(20, 380));
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private void showDot( Point2D p ) {
|
||||
showDot(p.getX(), p.getY(), randomColor());
|
||||
}
|
||||
private void showDot( double x, double y, Color clr ) {
|
||||
Punkt p = new Punkt(x, y);
|
||||
p.setFuellfarbe(clr);
|
||||
p.setKonturFarbe(clr);
|
||||
formen.anzeigen(p);
|
||||
}
|
||||
|
||||
Random rand = new Random();
|
||||
private void showDot( double x, double y, Color clr ) {
|
||||
Point p = new Point(x, y);
|
||||
p.setFillColor(clr);
|
||||
p.setStrokeColor(clr);
|
||||
shapes.add(p);
|
||||
}
|
||||
|
||||
private Color randomColor() {
|
||||
return new Color(
|
||||
|
||||
5
test/src/schule/ngb/zm/TestVector.java
Normal file
5
test/src/schule/ngb/zm/TestVector.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package schule.ngb.zm;
|
||||
|
||||
public class TestVector {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user