Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
83
Task/Hilbert-curve/Processing/hilbert-curve.processing
Normal file
83
Task/Hilbert-curve/Processing/hilbert-curve.processing
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
int iterations = 7;
|
||||
float strokeLen = 600;
|
||||
int angleDeg = 90;
|
||||
String axiom = "L";
|
||||
StringDict rules = new StringDict();
|
||||
String sentence = axiom;
|
||||
int xo, yo;
|
||||
|
||||
void setup() {
|
||||
size(700, 700);
|
||||
xo= 50;
|
||||
yo = height - 50;
|
||||
strokeWeight(1);
|
||||
noFill();
|
||||
|
||||
rules.set("L", "+RF-LFL-FR+");
|
||||
rules.set("R", "-LF+RFR+FL-");
|
||||
|
||||
generate(iterations);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
translate(xo, yo);
|
||||
plot(radians(angleDeg));
|
||||
}
|
||||
|
||||
void generate(int n) {
|
||||
for (int i=0; i < n; i++) {
|
||||
strokeLen *= 0.5;
|
||||
String nextSentence = "";
|
||||
for (int j=0; j < sentence.length(); j++) {
|
||||
char c = sentence.charAt(j);
|
||||
String ruleResult = rules.get(str(c), str(c));
|
||||
nextSentence += ruleResult;
|
||||
}
|
||||
sentence = nextSentence;
|
||||
}
|
||||
}
|
||||
|
||||
void plot(float angle) {
|
||||
for (int i=0; i < sentence.length(); i++) {
|
||||
char c = sentence.charAt(i);
|
||||
if (c == 'F') {
|
||||
stroke(255);
|
||||
line(0, 0, 0, -strokeLen);
|
||||
translate(0, -strokeLen);
|
||||
} else if (c == '+') {
|
||||
rotate(angle);
|
||||
} else if (c == '-') {
|
||||
rotate(-angle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
if (key == '-') {
|
||||
angleDeg -= 1;
|
||||
println("Angle: " + angleDeg);
|
||||
}
|
||||
if (key == '=' || key == '+') {
|
||||
angleDeg += 1;
|
||||
println("Angle: " + angleDeg);
|
||||
}
|
||||
if (key == 'a') {
|
||||
strokeLen *= 2;
|
||||
}
|
||||
if (key == 'z') {
|
||||
strokeLen /= 2;
|
||||
}
|
||||
if (keyCode == LEFT) {
|
||||
xo -= 25;
|
||||
}
|
||||
if (keyCode == RIGHT) {
|
||||
xo += 25;
|
||||
}
|
||||
if (keyCode == UP) {
|
||||
yo -= 25;
|
||||
}
|
||||
if (keyCode == DOWN) {
|
||||
yo += 25;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue