@@ -20,7 +20,7 @@ import nub.core.*;
2020import nub.processing.* ;
2121
2222Scene scene;
23- Node [] shapes;
23+ Torus [] shapes;
2424PFont font36;
2525int totalShapes;
2626
@@ -32,58 +32,15 @@ void settings() {
3232}
3333
3434void setup () {
35+ font36 = loadFont (" FreeSans-36.vlw" );
3536 scene = new Scene (this );
3637 scene. enableHint(Scene . AXES | Scene . BACKGROUND );
3738 scene. configHint(Scene . BACKGROUND , color (0 ));
3839 scene. fit(1 );
39- shapes = new Node [10 ];
40+ shapes = new Torus [10 ];
4041 for (int i = 0 ; i < shapes. length; i++ ) {
41- shapes[i] = new Node () {
42- int _id = totalShapes++ , _faces = randomFaces(), _color = randomColor();
43-
44- @Override
45- public void graphics (PGraphics pg ) {
46- pg. pushStyle();
47- pg. fill(_color);
48- Scene . drawTorusSolenoid(pg, _faces, scene. radius() / 20 );
49- scene. beginHUD();
50- Vector position = scene. screenLocation(position());
51- pg. fill(isTagged(scene) ? 0 : 255 , isTagged(scene) ? 255 : 0 , isTagged(scene) ? 0 : 255 );
52- pg. textFont(font36);
53- pg. text(_id, position. x(), position. y());
54- scene. endHUD();
55- pg. popStyle();
56- }
57-
58- @Override
59- public void interact (Object [] gesture ) {
60- if (gesture. length == 0 )
61- _color = randomColor();
62- if (gesture. length == 1 )
63- if (gesture[0 ] instanceof String ) {
64- if (((String ) gesture[0 ]). matches(" mas" ))
65- _faces++ ;
66- else if (((String ) gesture[0 ]). matches(" menos" ))
67- if (_faces > 2 )
68- _faces-- ;
69- } else if (gesture[0 ] instanceof Integer ) {
70- int delta = (Integer ) gesture[0 ];
71- if (_faces + delta > 1 )
72- _faces = _faces + delta;
73- }
74- }
75- };
76- scene. randomize(shapes[i]);
42+ shapes[i] = new Torus ();
7743 }
78- font36 = loadFont (" FreeSans-36.vlw" );
79- }
80-
81- int randomColor () {
82- return color (random (255 ), random (255 ), random (255 ), random (125 , 255 ));
83- }
84-
85- int randomFaces () {
86- return (int ) random (3 , 15 );
8744}
8845
8946void draw () {
@@ -93,7 +50,7 @@ void draw() {
9350void keyPressed () {
9451 int value = Character . getNumericValue(key );
9552 if (value >= 0 && value < 10 )
96- scene. tag(" key" , shapes[value]);
53+ scene. tag(" key" , shapes[value]. node );
9754 if (key == ' ' )
9855 scene. removeTag(" key" );
9956 if (key == CODED )
@@ -125,4 +82,4 @@ void mouseClicked(MouseEvent event) {
12582 scene. interactTag(" key" );
12683 if (event. getCount() == 2 )
12784 scene. mouseTag(" key" );
128- }
85+ }
0 commit comments