Beispielprojekte
This commit is contained in:
parent
c712826c07
commit
ba9d3e9fe3
|
@ -0,0 +1,27 @@
|
|||
|
||||
import schule.ngb.zm.*;
|
||||
|
||||
public class Attractor extends Mover {
|
||||
|
||||
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*Gravity.G).limit(0, 50*Gravity.G);
|
||||
pMover.applyForce(force);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import schule.ngb.zm.*;
|
||||
|
||||
public class Gravity extends Zeichenmaschine {
|
||||
|
||||
|
||||
public static final int G = 1;
|
||||
|
||||
|
||||
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 ) {
|
||||
Attractor mouseFollow = attractors.get(0);
|
||||
mouseFollow.moveTo(mouseX, mouseY);
|
||||
|
||||
for( Attractor a: attractors ) {
|
||||
for( Mover m: movers ) {
|
||||
a.attract(m);
|
||||
}
|
||||
}
|
||||
|
||||
for( Mover m: movers ) {
|
||||
m.update(delta);
|
||||
}
|
||||
shapes.clear();
|
||||
}
|
||||
|
||||
public void mouseClicked() {
|
||||
for( Mover m: movers ) {
|
||||
m.moveTo(random(10, width-10), random(10, height-10));
|
||||
m.setVelocity(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
|
||||
import schule.ngb.zm.*;
|
||||
import schule.ngb.zm.shapes.*;
|
||||
|
||||
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 setVelocity(double dx, double dy) {
|
||||
velocity.set(dx, dy);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
#BlueJ package file
|
||||
dependency1.from=Attractor
|
||||
dependency1.to=Gravity
|
||||
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=3
|
||||
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=380
|
||||
target1.y=220
|
||||
target2.height=70
|
||||
target2.name=Attractor
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.width=120
|
||||
target2.x=380
|
||||
target2.y=350
|
||||
target3.height=70
|
||||
target3.name=Gravity
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.width=120
|
||||
target3.x=120
|
||||
target3.y=120
|
|
@ -0,0 +1,10 @@
|
|||
# Zeichenmaschine: Skyline
|
||||
|
||||
Skyline ist ein Projekt mit der Turtle-Ebene der Zeichenmaschine. Jede
|
||||
Schüler:in programmiert ein Haus der Skyline. Dazu müssen vorher
|
||||
gemeinsam Vorgaben festgelegt werden. Wichtig ist, dass die Turtle immer in der
|
||||
unteren linken Ecke des Hauses startet und in der rechten unteren Ecke endet
|
||||
(damit dort dann das nächste Haus gezeichnet werden kann).
|
||||
|
||||
Wenn jede Schüler:in ihr Haus in eine eigene Methode schreibt, können diese
|
||||
nacheinander aufgerufen werden, um die finale Skyline zu erstellen.
|
|
@ -0,0 +1,65 @@
|
|||
import schule.ngb.zm.Color;
|
||||
import schule.ngb.zm.Zeichenmaschine;
|
||||
import schule.ngb.zm.turtle.TurtleLayer;
|
||||
|
||||
public class Skyline extends Zeichenmaschine {
|
||||
|
||||
TurtleLayer turtle;
|
||||
|
||||
public void setup() {
|
||||
setSize(1000, 600);
|
||||
setTitle("Zeichenmaschine: Skyline");
|
||||
|
||||
// Turtle-Ebene erstellen
|
||||
turtle = new TurtleLayer();
|
||||
addLayer(turtle);
|
||||
|
||||
// Hintergrund schwarz
|
||||
background.setColor(BLACK);
|
||||
turtle.noStroke();
|
||||
|
||||
turtle.penUp();
|
||||
turtle.lt(90);
|
||||
turtle.fd(300);
|
||||
turtle.rt(90);
|
||||
turtle.penDown();
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
for( int i = 0; i < 6; i++ ) {
|
||||
haus1(randomColor());
|
||||
}
|
||||
turtle.setStrokeColor(BLUE);
|
||||
}
|
||||
|
||||
public void haus1( Color clr ) {
|
||||
turtle.setFillColor(clr);
|
||||
quad(100, 80);
|
||||
turtle.fill();
|
||||
turtle.fd(100);
|
||||
turtle.rt(45);
|
||||
turtle.fd(80/sqrt(2));
|
||||
turtle.rt(90);
|
||||
turtle.fd(80/sqrt(2));
|
||||
turtle.rt(45);
|
||||
turtle.fill();
|
||||
turtle.fd(100);
|
||||
turtle.rt(180);
|
||||
}
|
||||
|
||||
public void quad( int a, int b ) {
|
||||
turtle.fd(a);
|
||||
turtle.rt(90);
|
||||
turtle.fd(b);
|
||||
turtle.rt(90);
|
||||
turtle.fd(a);
|
||||
turtle.rt(90);
|
||||
turtle.fd(b);
|
||||
turtle.rt(90);
|
||||
}
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new Skyline();
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
|
@ -0,0 +1,58 @@
|
|||
import schule.ngb.zm.Color;
|
||||
import schule.ngb.zm.Constants;
|
||||
import schule.ngb.zm.Drawable;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
|
||||
public class Dot implements Drawable {
|
||||
|
||||
public static final Color DOT_RED = new Color(244, 32, 65);
|
||||
|
||||
public static final Color DOT_WHITE = new Color(255);
|
||||
|
||||
public static final int SIZE = TIXY.DOT_SIZE;
|
||||
|
||||
public static final int RADIUS = TIXY.DOT_SIZE / 2;
|
||||
|
||||
public static final int GAP = TIXY.DOT_GAP;
|
||||
|
||||
public final int x, y, i;
|
||||
|
||||
public int size = SIZE;
|
||||
|
||||
public Color color;
|
||||
|
||||
|
||||
public Dot( int x, int y, int i ) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.i = i;
|
||||
|
||||
color = DOT_WHITE;
|
||||
}
|
||||
|
||||
public void setValue( double value ) {
|
||||
if( value < 0 ) {
|
||||
color = DOT_RED;
|
||||
value = value * -1;
|
||||
} else {
|
||||
color = DOT_WHITE;
|
||||
}
|
||||
|
||||
value = Constants.limit(value, 1.0);
|
||||
size = (int) (SIZE * value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw( Graphics2D graphics ) {
|
||||
graphics.setColor(color.getColor());
|
||||
graphics.fillOval(GAP + x * (SIZE + GAP) + RADIUS - (size / 2), GAP + y * (SIZE + GAP) + RADIUS - (size / 2), size, size);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
import schule.ngb.zm.Color;
|
||||
import schule.ngb.zm.Constants;
|
||||
|
||||
public class MyTIXY extends Constants {
|
||||
|
||||
public double update( double t, int i, int x, int y ) {
|
||||
return sin(t-sqrt(pow((x-7.5),2)+pow((y-6),2)));
|
||||
}
|
||||
|
||||
public void update( double t, Dot dot ) {
|
||||
if( dot.color.equals(Dot.DOT_RED) ) {
|
||||
dot.color = BLUE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
# Zeichenmaschine: TIXY
|
||||
|
||||
TIXY ist ein kreatives Projekt, bei dem ein Feld von Punkten durch geschickt
|
||||
gewählte mathematische Formeln animiert wird.
|
||||
|
||||
Die Idee stammt von der Seite http://tixy.land
|
||||
|
||||
Dort finden sich auch weitere Beispiele für interessante Animationen.
|
||||
|
||||
## Verwendung
|
||||
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
import schule.ngb.zm.DrawableLayer;
|
||||
import schule.ngb.zm.Zeichenmaschine;
|
||||
|
||||
public class TIXY extends Zeichenmaschine {
|
||||
|
||||
public static final int FIELD_SIZE = 16;
|
||||
|
||||
public static final int DOT_SIZE = 16;
|
||||
|
||||
public static final int DOT_GAP = 4;
|
||||
|
||||
|
||||
private Dot[][] dots;
|
||||
|
||||
private MyTIXY tixy;
|
||||
|
||||
public TIXY() {
|
||||
super(
|
||||
DOT_GAP + FIELD_SIZE * (DOT_SIZE + DOT_GAP),
|
||||
DOT_GAP + FIELD_SIZE * (DOT_SIZE + DOT_GAP),
|
||||
"tixy"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
background.setColor(BLACK);
|
||||
|
||||
addLayer(new DrawableLayer());
|
||||
DrawableLayer dl = canvas.getLayer(DrawableLayer.class);
|
||||
|
||||
tixy = new MyTIXY();
|
||||
|
||||
dots = new Dot[FIELD_SIZE][FIELD_SIZE];
|
||||
for( int i = 0; i < FIELD_SIZE; i++ ) {
|
||||
for( int j = 0; j < FIELD_SIZE; j++ ) {
|
||||
dots[i][j] = new Dot(i, j, i*FIELD_SIZE + j);
|
||||
dl.add(dots[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
for( int i = 0; i < FIELD_SIZE; i++ ) {
|
||||
for( int j = 0; j < FIELD_SIZE; j++ ) {
|
||||
Dot d = dots[i][j];
|
||||
double value = tixy.update(runtime/1000.0, d.i, d.x, d.y);
|
||||
dots[i][j].setValue(value);
|
||||
|
||||
tixy.update(runtime/1000.0, dots[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new TIXY();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
#BlueJ package file
|
||||
dependency1.from=TIXY
|
||||
dependency1.to=MyTIXY
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=TIXY
|
||||
dependency2.to=Dot
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=MyTIXY
|
||||
dependency3.to=Dot
|
||||
dependency3.type=UsesDependency
|
||||
dependency4.from=Dot
|
||||
dependency4.to=TIXY
|
||||
dependency4.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=4
|
||||
package.numTargets=3
|
||||
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=TIXY
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.width=120
|
||||
target1.x=120
|
||||
target1.y=60
|
||||
target2.height=70
|
||||
target2.name=MyTIXY
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.width=120
|
||||
target2.x=200
|
||||
target2.y=210
|
||||
target3.height=70
|
||||
target3.name=Dot
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.width=120
|
||||
target3.x=420
|
||||
target3.y=140
|
Loading…
Reference in New Issue