Advertisement
Guest User

Untitled

a guest
Apr 14th, 2020
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.85 KB | None | 0 0
  1. final int windowWidth = 480;
  2. final int windowHeight = windowWidth;
  3. int timer;
  4.  
  5. void settings() {
  6.  
  7. size(windowWidth, windowHeight);
  8.  
  9. }
  10.  
  11.  
  12.  
  13. //////////////////////////////////////
  14. /////////////////////////////////////
  15.  
  16. class Rectangle{
  17.  
  18. float x;
  19. float y;
  20. float width_rect;
  21. float height_rect;
  22. color c;
  23.  
  24. Rectangle(float x, float y, float width_rect, float height_rect, color c){
  25. this.x = x;
  26. this.y = y;
  27. this.width_rect = width_rect;
  28. this.height_rect = height_rect;
  29. this.c = c;
  30. }
  31.  
  32. void draw_rect(){
  33. rectMode(CENTER); // Set rectMode to CENTER
  34. fill(this.c);
  35. noStroke();
  36. rect(this.x,this.y,this.width_rect,this.height_rect);
  37.  
  38. }
  39.  
  40. }
  41.  
  42. class Flag {
  43. String name;
  44. float x; // horizontal coordinate of upper left corner
  45. float y; // vertical coordinate of upper left corner
  46. float width_flag; // lenght of side
  47. float height_flag;
  48. color c;
  49. Rectangle r[] = new Rectangle[1000];
  50. int nr_rects;
  51.  
  52. Flag (float x, float y, float width_flag, color c, int nr_rects) {
  53. //this.name = name;
  54. this.x = x;
  55. this.y = y;
  56. this.width_flag = width_flag;
  57. this.height_flag = width_flag*(2.0/3.0);
  58. this.c = c;
  59. this.nr_rects = nr_rects;
  60.  
  61. }
  62.  
  63. void draw_Flag(){
  64.  
  65. rectMode(CENTER); // Set rectMode to CENTER
  66. fill(this.c); // Set fill to gray
  67. noStroke();
  68. rect(this.x, this.y, this.width_flag, this.height_flag); // Draw gray rect using CENTER mode
  69. for(int i = 0; i < this.nr_rects; i++){
  70. r[i].draw_rect();
  71. }
  72.  
  73. //draw(this.r[i]);
  74.  
  75.  
  76. }
  77. }
  78. ////////////////////////////////////////
  79. ///////////////////////////////////////
  80.  
  81.  
  82. ////////////////////////////////////////
  83. // //
  84. // Nivel 1 //
  85. // //
  86. ////////////////////////////////////
  87.  
  88. Flag make_Iceland_flag(Flag f){
  89.  
  90. //Bandeira da Islandia
  91. f.name = "Islandia";
  92. f.c = color(0,0,255);
  93.  
  94. //barra branca vertical
  95. float b_b_v_width = f.width_flag/7;
  96. float b_b_v_height = f.height_flag;
  97. float b_b_v_x = (f.x+f.width_flag/2) - (f.width_flag/3)*2;
  98. float b_b_v_y = (f.y);
  99. color white = color(255,255,255);
  100.  
  101. f.r[0] = new Rectangle(b_b_v_x,b_b_v_y,b_b_v_width,b_b_v_height,white);
  102.  
  103.  
  104. //
  105.  
  106. //barra branca horizontal
  107. float b_b_h_width = f.width_flag;
  108. float b_b_h_height = f.width_flag/7;
  109. float b_b_h_x = (f.x);
  110. float b_b_h_y = (f.y);
  111. //color red = color(255,0,0);
  112.  
  113. f.r[1] = new Rectangle(b_b_h_x,b_b_h_y,b_b_h_width,b_b_h_height,white);
  114. //
  115.  
  116. //
  117.  
  118. ////barra vermelha vertical
  119. float b_v_v_width = f.width_flag/15;
  120. float b_v_v_height = f.height_flag;
  121. float b_v_v_x = (f.x+f.width_flag/2) - (f.width_flag/3)*2;
  122. float b_v_v_y = (f.y);
  123. color red = color(255,0,0);
  124.  
  125. f.r[2] = new Rectangle(b_v_v_x,b_v_v_y,b_v_v_width,b_v_v_height,red);//mudar ordem
  126. //
  127.  
  128. ///barra vermelha horizontal
  129. float b_v_h_width = f.width_flag;
  130. float b_v_h_height = f.width_flag/15;
  131. float b_v_h_x = (f.x);
  132. float b_v_h_y = (f.y);
  133. //color red = color(255,0,0);
  134.  
  135. f.r[3] = new Rectangle(b_v_h_x,b_v_h_y,b_v_h_width,b_v_h_height,red);//mudar ordem
  136. //
  137.  
  138. f.nr_rects = 4;
  139.  
  140. return f;
  141.  
  142. }
  143.  
  144. void nivel_1(){
  145.  
  146. float width_flag = windowWidth/3;
  147. float center_x = windowWidth/2;
  148. float center_y = windowHeight/2;
  149. color blue = color(0, 0, 255);
  150.  
  151. //Bandeira da Islandia
  152.  
  153. Flag f = new Flag(center_x,center_y,width_flag,blue,0);
  154.  
  155. f = make_Iceland_flag(f);
  156.  
  157. f.draw_Flag();
  158.  
  159. }
  160. ///////////////////////////////////
  161. //////////////////////////////////
  162.  
  163. ////////////////////////////////
  164. // //
  165. // Nivel 2 //
  166. // //
  167. ////////////////////////////
  168.  
  169. class Coords{
  170.  
  171. float x;
  172. float y;
  173.  
  174. Coords(float x, float y){
  175. this.x = x;
  176. this.y = y;
  177. }
  178.  
  179. }
  180.  
  181. void get_coords_nivel_2(Coords cr[]){
  182.  
  183. cr[0] = new Coords(windowWidth/4,windowHeight/4);
  184.  
  185. cr[1] = new Coords(windowWidth/4*3,windowHeight/4);
  186.  
  187. cr[2] = new Coords(windowWidth/4,windowHeight/4*3);
  188.  
  189. cr[3] = new Coords(windowWidth/4*3,windowHeight/4*3);
  190.  
  191.  
  192. }
  193.  
  194. void nivel_2(){
  195.  
  196.  
  197. float width_flag = windowWidth/3;
  198. //float x = windowWidth/4;
  199. //float y = windowHeight/4;
  200. //float coords[][] = {{windowWidth/4,windowHeight/4}};
  201. color blue = color(0, 0, 255);
  202.  
  203. Coords cr[] = new Coords[4];
  204. get_coords_nivel_2(cr);
  205.  
  206.  
  207. Flag f[] = new Flag[4];
  208. //Flag f;
  209. for(int i = 0; i < 4; i++){
  210. f[i] = new Flag(cr[i].x,cr[i].y,width_flag,blue,4);
  211. f[i] = make_Iceland_flag(f[i]);
  212. f[i].draw_Flag();
  213. }
  214.  
  215. }
  216.  
  217. ///////////////////////////////////
  218. //////////////////////////////////
  219.  
  220. ////////////////////////////////
  221. // //
  222. // Nivel 3 //
  223. // //
  224. ////////////////////////////
  225.  
  226. Flag make_Swedish_flag(Flag f){
  227.  
  228.  
  229. //Bandeira da Suecia
  230.  
  231. f.name = "Suecia";
  232. f.c = color(0,0,255);
  233.  
  234. //barra branca vertical
  235. float b_b_v_width = f.width_flag/7;
  236. float b_b_v_height = f.height_flag;
  237. float b_b_v_x = (f.x+f.width_flag/2) - (f.width_flag/3)*2;
  238. float b_b_v_y = (f.y);
  239. color yellow = color(255,255,0);
  240.  
  241. f.r[0] = new Rectangle(b_b_v_x,b_b_v_y,b_b_v_width,b_b_v_height,yellow);
  242.  
  243.  
  244. //
  245.  
  246. //barra branca horizontal
  247. float b_b_h_width = f.width_flag;
  248. float b_b_h_height = f.width_flag/7;
  249. float b_b_h_x = (f.x);
  250. float b_b_h_y = (f.y);
  251. //color red = color(255,0,0);
  252.  
  253. f.r[1] = new Rectangle(b_b_h_x,b_b_h_y,b_b_h_width,b_b_h_height,yellow);
  254. //
  255.  
  256.  
  257. f.nr_rects = 2;
  258.  
  259. return f;
  260.  
  261.  
  262. }
  263.  
  264. Flag make_Russian_flag(Flag f){
  265.  
  266. //Bandeira da Russia
  267.  
  268. f.name = "Russia";
  269. f.c = color(255,255,255);
  270.  
  271. //barra branca horizontal
  272. float b_b_h_width = f.width_flag;
  273. float b_b_h_height = f.height_flag/3;
  274. float b_b_h_x = (f.x);
  275. float b_b_h_y = (f.y);
  276. color blue = color(0,0,255);
  277.  
  278. f.r[0] = new Rectangle(b_b_h_x,b_b_h_y,b_b_h_width,b_b_h_height,blue);
  279. //
  280.  
  281. //f.c = color(255,0,0);
  282.  
  283. //barra vermelha horizontal
  284.  
  285. float b_v_h_width = f.width_flag;
  286. float b_v_h_height = f.height_flag/3;
  287. float b_v_h_x = (f.x);
  288. float b_v_h_y = (f.y) + (f.height_flag/3);
  289. color red = color(255,0,0);
  290.  
  291. f.r[1] = new Rectangle(b_v_h_x,b_v_h_y,b_v_h_width,b_v_h_height,red);
  292. //
  293.  
  294.  
  295. f.nr_rects = 2;
  296.  
  297. return f;
  298.  
  299. }
  300.  
  301. Flag make_Italian_flag(Flag f){
  302.  
  303. //Bandeira da Italia
  304.  
  305. f.name = "Italia";
  306. f.c = color(0,255,0);
  307.  
  308. //barra branca vertical
  309. float b_b_v_width = f.width_flag/3;
  310. float b_b_v_height = f.height_flag;
  311. float b_b_v_x = (f.x);
  312. float b_b_v_y = (f.y);
  313. color white = color(255,255,255);
  314.  
  315. f.r[0] = new Rectangle(b_b_v_x,b_b_v_y,b_b_v_width,b_b_v_height,white);
  316.  
  317.  
  318. //
  319.  
  320.  
  321. ////barra vermelha vertical
  322. float b_v_v_width = f.width_flag/3;
  323. float b_v_v_height = f.height_flag;
  324. float b_v_v_x = (f.x) + (f.width_flag/3);
  325. float b_v_v_y = (f.y);
  326. color red = color(255,0,0);
  327.  
  328. f.r[1] = new Rectangle(b_v_v_x,b_v_v_y,b_v_v_width,b_v_v_height,red);//mudar ordem
  329. //
  330.  
  331. f.nr_rects = 2;
  332.  
  333. return f;
  334.  
  335. }
  336.  
  337.  
  338. void nivel_3(){
  339.  
  340. float width_flag = windowWidth/3;
  341.  
  342. Coords cr[] = new Coords[4];
  343. get_coords_nivel_2(cr);
  344.  
  345.  
  346. Flag f[] = new Flag[4];
  347.  
  348. for(int i = 0; i < 4; i++){
  349. f[i] = new Flag(cr[i].x,cr[i].y,width_flag,0,0);
  350. }
  351.  
  352. f[0] = make_Iceland_flag(f[0]);
  353. f[0].draw_Flag();
  354.  
  355. f[1] = make_Italian_flag(f[1]);
  356. f[1].draw_Flag();
  357.  
  358. f[2] = make_Russian_flag(f[2]);
  359. f[2].draw_Flag();
  360.  
  361. f[3] = make_Swedish_flag(f[3]);
  362. f[3].draw_Flag();
  363.  
  364. }
  365.  
  366. //////////////////////////////////
  367. /////////////////////////////////
  368.  
  369. ////////////////////////////////
  370. // //
  371. // Nivel 4 //
  372. // //
  373. /////////////////////////////
  374.  
  375. void flags_exchange(Flag f[], int x, int y)
  376. {
  377. Flag m = f[x];
  378. f[x] = f[y];
  379. f[y] = m;
  380. }
  381.  
  382. void flags_isort(Flag f[], int n)
  383. {
  384. for (int i = 1; i < n; i++)
  385. {
  386. int j = i;
  387. // int j = n-1;
  388. while (j > 0)
  389. {
  390. flags_exchange(f, j-1, j);
  391. j--;
  392. }
  393. }
  394. }
  395. void update(Flag f[], int n, Coords cr[],float width_flag) {
  396.  
  397. //int i = 0;
  398.  
  399.  
  400.  
  401.  
  402. flags_isort(f,n);
  403. for(int i = 0; i < n; i++){
  404. //f[i] = new Flag(cr[i].x,cr[i].y,width_flag,0,0);
  405. if(f[i].name == "Islandia"){
  406. f[i] = new Flag(cr[i].x,cr[i].y,width_flag,0,0);
  407. f[i] = make_Iceland_flag(f[i]);
  408. }
  409. else if(f[i].name == "Italia"){
  410. f[i] = new Flag(cr[i].x,cr[i].y,width_flag,0,0);
  411. f[i] = make_Italian_flag(f[i]);
  412. }
  413. else if(f[i].name == "Russia"){
  414. f[i] = new Flag(cr[i].x,cr[i].y,width_flag,0,0);
  415. f[i] = make_Russian_flag(f[i]);
  416. }
  417. else if(f[i].name == "Suecia"){
  418. f[i] = new Flag(cr[i].x,cr[i].y,width_flag,0,0);
  419. f[i] = make_Swedish_flag(f[i]);
  420. }
  421. //f[i].x = cr[i].x;
  422. //f[i].y = cr[i].y;
  423. }
  424.  
  425. // for(int i = 0; i < n; i++){
  426. //print(i+" " + f[i].name+"\n");
  427. // }
  428. // print("\n\n");
  429.  
  430. //}
  431.  
  432.  
  433.  
  434. }
  435.  
  436. void flags_draw(Flag f[], int n){
  437.  
  438. // f[0] = make_Iceland_flag(f[0]);
  439. //f[1] = make_Italian_flag(f[1]);
  440. // f[2] = make_Russian_flag(f[2]);
  441. // f[3] = make_Swedish_flag(f[3]);
  442.  
  443. for(int i = 0; i < n; i++){
  444. f[i].draw_Flag();
  445. print(i+" " + f[i].name+"\n");
  446. }
  447. print("\n\n");
  448.  
  449. }
  450.  
  451. void nivel_4(){
  452.  
  453. float width_flag = windowWidth/3;
  454.  
  455. Coords cr[] = new Coords[4];
  456. get_coords_nivel_2(cr);
  457.  
  458. int n=4;
  459.  
  460. Flag f[] = new Flag[n];
  461. for(int i = 0; i < n; i++){
  462. f[i] = new Flag(cr[i].x,cr[i].y,width_flag,0,0);
  463. }
  464.  
  465. f[0] = make_Iceland_flag(f[0]);
  466. f[1] = make_Italian_flag(f[1]);
  467. f[2] = make_Russian_flag(f[2]);
  468. f[3] = make_Swedish_flag(f[3]);
  469.  
  470. background(100);
  471. flags_draw(f, n);
  472. update(f,n,cr,width_flag);
  473.  
  474. while(true){
  475. if (millis() - timer >= 2000) {
  476. //nivel_4();
  477.  
  478. background(100);
  479. flags_draw(f, n);
  480. update(f,n,cr,width_flag);
  481.  
  482. }
  483. timer = millis();
  484.  
  485. }
  486.  
  487. }
  488.  
  489. ////////////////////////////////
  490.  
  491. void draw() {
  492.  
  493. //Nivel 1
  494. //nivel_1();
  495.  
  496. //Nivel 2
  497. //nivel_2();
  498.  
  499. //Nivel 3
  500. //nivel_3();
  501.  
  502. //Nivel 4
  503. //if (millis() - timer >= 2000) {
  504. nivel_4();
  505. //timer = millis();
  506. //nivel_4();
  507. //}
  508. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement