mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-10-12 01:45:18 +02:00
Viele weitere Beispielprojekt für verschiedene Anwendungen
This commit is contained in:
77
examples/zm_generative/BouncingLine.java
Normal file
77
examples/zm_generative/BouncingLine.java
Normal file
@@ -0,0 +1,77 @@
|
||||
import schule.ngb.zm.Vector;
|
||||
import schule.ngb.zm.Zeichenmaschine;
|
||||
|
||||
public class BouncingLine extends Zeichenmaschine {
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new BouncingLine();
|
||||
}
|
||||
|
||||
private Vector start, end, dStart, dEnd;
|
||||
|
||||
private int r, g, b;
|
||||
|
||||
private boolean mouseFollow = false;
|
||||
|
||||
public BouncingLine() {
|
||||
super(800, 800, "Bouncing Lines");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
start = Vector.random(0, width, 0, height);
|
||||
end = Vector.random(0, width, 0, height);
|
||||
dStart = Vector.random(-5, 5);
|
||||
dEnd = Vector.random(-5, 5);
|
||||
|
||||
r = random(255);
|
||||
g = random(255);
|
||||
b = random(255);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
start.add(dStart);
|
||||
end.add(dEnd);
|
||||
|
||||
if( start.x > width || start.x < 0 ) {
|
||||
dStart.x *= -1;
|
||||
}
|
||||
if( end.x > width || end.x < 0 ) {
|
||||
dEnd.x *= -1;
|
||||
}
|
||||
if( start.y > width || start.y < 0 ) {
|
||||
dStart.y *= -1;
|
||||
}
|
||||
if( end.y > width || end.y < 0 ) {
|
||||
dEnd.y *= -1;
|
||||
}
|
||||
|
||||
r += limit(random(-5, 5), 0, 255);
|
||||
g += limit(random(-5, 5), 0, 255);
|
||||
b += limit(random(-5, 5), 0, 255);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
drawing.setStrokeColor(r, g, b);
|
||||
drawing.line(start.x, start.y, end.x, end.y);
|
||||
// bezier(0, 0, startX, startY, endX, endY, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked() {
|
||||
mouseFollow = !mouseFollow;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved() {
|
||||
if( mouseFollow ) {
|
||||
dStart = new Vector(mouseX - start.x, mouseY - start.y);
|
||||
dStart.setLength(5);
|
||||
dEnd = new Vector(mouseX - end.x, mouseY - end.y);
|
||||
dEnd.setLength(5);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
40
examples/zm_generative/GenColors.java
Normal file
40
examples/zm_generative/GenColors.java
Normal file
@@ -0,0 +1,40 @@
|
||||
import schule.ngb.zm.Color;
|
||||
import schule.ngb.zm.Zeichenmaschine;
|
||||
|
||||
public class GenColors extends Zeichenmaschine {
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new GenColors();
|
||||
}
|
||||
|
||||
public GenColors() {
|
||||
super(800, 800, "Nice Colors");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
genPattern();
|
||||
}
|
||||
|
||||
public void genPattern() {
|
||||
drawing.noStroke();
|
||||
|
||||
int SIZE = 40;
|
||||
for( int i = 0; i < width/SIZE; i++ ) {
|
||||
for( int j = 0; j < height/SIZE; j++ ) {
|
||||
Color c = randomNiceColor();
|
||||
float[] hsl = Color.RGBtoHSL(c.getRGBA(), null);
|
||||
System.out.printf("%f, %f, %f\n", hsl[0], hsl[1], hsl[2]);
|
||||
drawing.setFillColor(c);
|
||||
drawing.square(i*SIZE, j*SIZE, SIZE, NORTHWEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked() {
|
||||
genPattern();
|
||||
redraw();
|
||||
}
|
||||
|
||||
}
|
||||
122
examples/zm_generative/GenHitomezashi.java
Normal file
122
examples/zm_generative/GenHitomezashi.java
Normal file
@@ -0,0 +1,122 @@
|
||||
import schule.ngb.zm.Color;
|
||||
import schule.ngb.zm.Constants;
|
||||
import schule.ngb.zm.Options;
|
||||
import schule.ngb.zm.Zeichenmaschine;
|
||||
|
||||
public class GenHitomezashi extends Zeichenmaschine {
|
||||
|
||||
public static final int TILE_SIZE = 20;
|
||||
|
||||
public static final int COLUMNS = 30;
|
||||
|
||||
public static final int ROWS = 30;
|
||||
|
||||
public static final double P = 0.5;
|
||||
|
||||
public static final Color[] colors = new Color[]{
|
||||
randomNiceColor(),
|
||||
randomNiceColor(),
|
||||
color(241, 124, 55),
|
||||
color(62, 156, 191)
|
||||
};
|
||||
|
||||
private int[] stitchesX, stitchesY;
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new GenHitomezashi();
|
||||
}
|
||||
|
||||
|
||||
public GenHitomezashi() {
|
||||
super(TILE_SIZE*COLUMNS, TILE_SIZE*ROWS, "Hitomezashi Pattern");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
drawing.setStrokeColor(0);
|
||||
drawing.setFillColor(0);
|
||||
|
||||
generatePattern();
|
||||
|
||||
pause();
|
||||
}
|
||||
|
||||
public void generatePattern() {
|
||||
stitchesX = new int[COLUMNS];
|
||||
for ( int i = 0; i < COLUMNS; i++ ) {
|
||||
stitchesX[i] = random(0, 1) < P ? 1 : 0;
|
||||
}
|
||||
stitchesY = new int[COLUMNS];
|
||||
for ( int j = 0; j < ROWS; j++ ) {
|
||||
stitchesY[j] = random(0, 1) < P ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasStitch( int i, int j, Options.Direction dir ) {
|
||||
switch( dir ) {
|
||||
case UP:
|
||||
return (j > 0 && (stitchesY[j-1]+i)%2 == 1);
|
||||
case DOWN:
|
||||
return (j >= 0 && (stitchesY[j]+i)%2 == 1);
|
||||
case LEFT:
|
||||
return (i > 0 && (stitchesX[i-1]+j)%2 == 1);
|
||||
case RIGHT:
|
||||
return (i >= 0 && (stitchesX[i]+j)%2 == 1);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
drawing.clear(200);
|
||||
|
||||
int clr = random(1), clr2 = clr;
|
||||
drawing.noStroke();
|
||||
for ( int i = 0; i < COLUMNS; i++ ) {
|
||||
if ( hasStitch(i, 0, LEFT) ) {
|
||||
clr = (clr2+1)%2;
|
||||
clr2 = clr;
|
||||
} else {
|
||||
clr = clr2;
|
||||
}
|
||||
|
||||
for ( int j = 0; j < ROWS; j++ ) {
|
||||
drawing.setFillColor(colors[clr]);
|
||||
drawing.rect(i*TILE_SIZE, j*TILE_SIZE, TILE_SIZE, TILE_SIZE, NORTHWEST);
|
||||
|
||||
if ( hasStitch(i, j, DOWN) ) {
|
||||
clr = (clr+1)%2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drawing.setStrokeColor(0);
|
||||
drawing.setStrokeWeight(2);
|
||||
for ( int i = 0; i < COLUMNS; i++ ) {
|
||||
for ( int j = 0; j < ROWS; j++ ) {
|
||||
boolean stitchX = (stitchesX[i]+j)%2 == 1;
|
||||
if ( i < COLUMNS-1 && stitchX ) {
|
||||
drawing.line((i+1)*TILE_SIZE, j*TILE_SIZE, (i+1)*TILE_SIZE, (j+1)*TILE_SIZE);
|
||||
}
|
||||
|
||||
boolean stitchY = (stitchesY[j]+i)%2 == 1;
|
||||
if ( j < ROWS-1 && stitchY ) {
|
||||
drawing.line(i*TILE_SIZE, (j+1)*TILE_SIZE, (i+1)*TILE_SIZE, (j+1)*TILE_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed() {
|
||||
generatePattern();
|
||||
redraw();
|
||||
}
|
||||
|
||||
}
|
||||
62
examples/zm_generative/GenLines.java
Normal file
62
examples/zm_generative/GenLines.java
Normal file
@@ -0,0 +1,62 @@
|
||||
import schule.ngb.zm.Color;
|
||||
import schule.ngb.zm.Zeichenmaschine;
|
||||
|
||||
public class GenLines extends Zeichenmaschine {
|
||||
|
||||
public static final int BORDER = 16;
|
||||
|
||||
public static final int SIZE = 400;
|
||||
|
||||
public static Color[] colors = new Color[]{
|
||||
color(62, 156, 191),
|
||||
color(167, 236, 242),
|
||||
color(242, 196, 61),
|
||||
color(241, 124, 55),
|
||||
color(242, 109, 80)
|
||||
};
|
||||
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new GenLines();
|
||||
}
|
||||
|
||||
|
||||
private int i = 0;
|
||||
|
||||
public GenLines() {
|
||||
super(SIZE, SIZE, "Lines");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setFramesPerSecond(10);
|
||||
drawing.clear(33);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
int a = random(BORDER, SIZE-BORDER);
|
||||
|
||||
//drawing.setStrokeColor(random(50, 200));
|
||||
drawing.setStrokeColor(colors[random(colors.length-1)]);
|
||||
drawing.setStrokeWeight(random(4,12));
|
||||
|
||||
int d;
|
||||
if( a > SIZE*0.5 ) {
|
||||
d = random(1, (SIZE - a) - BORDER);
|
||||
} else {
|
||||
d = random(1, a - BORDER);
|
||||
}
|
||||
drawing.line(a - d, a + d, a + d, a - d);
|
||||
|
||||
i += 1;
|
||||
if( i == SIZE ) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
60
examples/zm_generative/GenSpiral.java
Normal file
60
examples/zm_generative/GenSpiral.java
Normal file
@@ -0,0 +1,60 @@
|
||||
import schule.ngb.zm.Color;
|
||||
import schule.ngb.zm.Zeichenmaschine;
|
||||
|
||||
public class GenSpiral extends Zeichenmaschine {
|
||||
|
||||
public static final int SIZE = 800;
|
||||
|
||||
public static final double D_SCALE = .33;
|
||||
public static final double A_SCALE = 6.0;
|
||||
|
||||
public static Color[] colors = new Color[]{
|
||||
color(62, 156, 191, 44),
|
||||
color(167, 236, 242, 44),
|
||||
color(242, 196, 61, 44),
|
||||
color(241, 124, 55, 44),
|
||||
color(242, 109, 80, 44)
|
||||
};
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new GenSpiral();
|
||||
}
|
||||
|
||||
|
||||
private int i = 0;
|
||||
|
||||
public GenSpiral() {
|
||||
super(SIZE, SIZE, "Lines");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setFramesPerSecond(60);
|
||||
drawing.clear(33);
|
||||
drawing.translate(SIZE/2, SIZE/2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
double d = (tick * D_SCALE); // + random(0,3);
|
||||
double a = radians(tick * tick / A_SCALE);
|
||||
// a = radians(tick * A_SCALE / D_SCALE);
|
||||
// a = radians(d * A_SCALE);
|
||||
|
||||
int x = (int)(d * cos(a));
|
||||
int y = (int)(d * sin(a));
|
||||
|
||||
drawing.setFillColor(colors[random(colors.length - 1)]);
|
||||
drawing.noStroke();
|
||||
drawing.circle(x, y, 10);
|
||||
|
||||
if( d > SIZE+SIZE ) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
43
examples/zm_generative/GenWalk.java
Normal file
43
examples/zm_generative/GenWalk.java
Normal file
@@ -0,0 +1,43 @@
|
||||
import schule.ngb.zm.DrawingLayer;
|
||||
import schule.ngb.zm.Zeichenmaschine;
|
||||
|
||||
public class GenWalk extends Zeichenmaschine {
|
||||
|
||||
public static final int N_WALKERS = 8;
|
||||
|
||||
private Walker[] walkers;
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new GenWalk();
|
||||
}
|
||||
|
||||
public GenWalk() {
|
||||
super(800, 800, "Randomwalk");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
this.walkers = new Walker[N_WALKERS];
|
||||
for( int i = 0; i < walkers.length; i++ ) {
|
||||
this.walkers[i] = new Walker(width/2, height/2, drawing);
|
||||
}
|
||||
|
||||
drawing.clear(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
for( Walker walker: walkers ) {
|
||||
walker.update();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
drawing.clear(0, 5);
|
||||
for( Walker walker: walkers ) {
|
||||
walker.draw();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
12
examples/zm_generative/README.TXT
Normal file
12
examples/zm_generative/README.TXT
Normal file
@@ -0,0 +1,12 @@
|
||||
# Zeichenmaschine: GenLines
|
||||
|
||||
GenLines 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
|
||||
|
||||
|
||||
50
examples/zm_generative/Walker.java
Normal file
50
examples/zm_generative/Walker.java
Normal file
@@ -0,0 +1,50 @@
|
||||
import schule.ngb.zm.*;
|
||||
|
||||
// TODO: Build Interface (like Drawable) that uses DrawingLayer instead of Graphics2D ?
|
||||
|
||||
public class Walker extends Constants {
|
||||
|
||||
public static final int SIZE = 8;
|
||||
|
||||
public static final int STEP = 6;
|
||||
|
||||
private static final Color[] colors = new Color[]{
|
||||
Color.parseHexcode("#b13254"),
|
||||
Color.parseHexcode("#ff5349"),
|
||||
Color.parseHexcode("#ff7249"),
|
||||
Color.parseHexcode("#ff9248")
|
||||
};
|
||||
|
||||
private int x;
|
||||
|
||||
private int y;
|
||||
|
||||
private Color color;
|
||||
|
||||
private DrawingLayer drawing;
|
||||
|
||||
public Walker(DrawingLayer drawing) {
|
||||
this(0, 0, drawing);
|
||||
}
|
||||
|
||||
public Walker( int x, int y, DrawingLayer drawing) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.color = choice(colors);
|
||||
this.drawing = drawing;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
x += random(-STEP, STEP);
|
||||
y += random(-STEP, STEP);
|
||||
x = limit(x, 10, drawing.getWidth() - 10);
|
||||
y = limit(y, 10, drawing.getHeight() - 10);
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
drawing.setFillColor(color);
|
||||
drawing.noStroke();
|
||||
drawing.square(x, y, SIZE, MIDDLE);
|
||||
}
|
||||
|
||||
}
|
||||
58
examples/zm_generative/package.bluej
Normal file
58
examples/zm_generative/package.bluej
Normal file
@@ -0,0 +1,58 @@
|
||||
#BlueJ package file
|
||||
dependency1.from=GenLines
|
||||
dependency1.to=MyTIXY
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=GenLines
|
||||
dependency2.to=Dot
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=MyTIXY
|
||||
dependency3.to=Dot
|
||||
dependency3.type=UsesDependency
|
||||
dependency4.from=Dot
|
||||
dependency4.to=GenLines
|
||||
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=GenLines
|
||||
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
|
||||
Reference in New Issue
Block a user