Beispielprojekte

This commit is contained in:
ngb
2022-01-02 22:12:21 +01:00
parent c712826c07
commit ba9d3e9fe3
12 changed files with 526 additions and 0 deletions

58
examples/zm_tixy/Dot.java Normal file
View File

@@ -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);
}
}

View File

@@ -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;
}
}
}

View File

@@ -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

View File

@@ -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();
}
}

View File

@@ -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