PFont font; color trait = color(0); color rempl = color(230, 50); color surb = color(255); color backg = color(200); float Ox = 400, Oy = 50; // origine de la zone de dessin class Triangle { //--- Triangles Equilateraux, positionnables et orientables ---\\ PVector pos; float h; float ori; Triangle () { pos = new PVector(Ox+300,Oy+300); h = 60; ori = PI; } Triangle (Triangle t) { pos = t.pos; h = t.h; ori = t.ori; } Triangle (PVector pos_i, float h_i, float ori_i) { pos = pos_i; h = h_i; ori = ori_i; } float cote() { return((float)(2*h/(sqrt(3)))); } void affiche() { translate(pos.x, pos.y); rotate(ori); stroke(trait); fill(rempl); if (isSelected() == true) fill(surb); ellipseMode(CENTER); //Dessiner le triangle beginShape(); vertex (-(int)(cote()/2.0), (int)(-1.0/3.0*h)); vertex (+(int)(cote()/2.0), (int)(-1.0/3.0*h)); vertex (0, (int)(+2/3.0*h)); endShape(CLOSE); rotate(-ori); translate(-pos.x, -pos.y); } boolean isSelected() { return((sq(mouseX-pos.x)+sq(mouseY-pos.y)=0) && (i<6)) { triangles[i].pos = new PVector(Ox+75*(i+1), Oy+100); } if ((i>=6) && (i<11)) { triangles[i].pos = new PVector(Ox+75*((i-6)+1), Oy+250); } triangles[i].ori=PI; } } } PImage fond; void setup() { size(800, 500); font = loadFont("MicrosoftSansSerif-24.vlw"); textFont(font, 18); smooth(); background(backg); for (int i = 0; i < triangles.length; i++) triangles[i] = new Triangle(); new_triangle(); //dessine_fond(); saveFrame("fond.png");fond = loadImage("fond.png"); } void draw() { dessine_fond(); //image(fond,0,0); for (int i = 0; i < Ncur; i++) triangles[i].affiche(); } void dessine_fond() { background(backg); fill(0); text("HEXATRIANGLES (2002)",30,30); line(30,40,780,40); text("Pour faire un hexamino, il faut 6 triangles équilatéraux",30,70); text("que l'on peut disposer comme ceci par exemple (deux",30,100); text("triangles ont toujours un côté commun) :",30,130); noFill(); rect(500,75,250,380); fill(255); int x = 0 ; int y = 100 ; Triangle[] Demo = new Triangle[6]; for (int i=0 ; i < Demo.length ; i++) { float hauteur=60; float cote = hauteur*2/sqrt(3); Demo[i] = new Triangle(new PVector (i*cote/2+100,200+(i%2)*hauteur/3) ,hauteur,(i%2)*PI) ; Demo[i].affiche() ; } fill(0); text("A vous de chercher tous les hexaminos possibles. ",30,300); text("Attention à ne pas les fournir en double.",30,330); text("Utilise le cadre pour trouver d'autres possibilités (clic",30,360); text("droit pour obtenir un nouveau triangle, flèche droite ou",30,390); text("gauche pour le faire tourner quand il est blanc ( si la",30,420); text("souris est dedans), entrée pour écarter des triangles",30,450); text("collés, clic droit maintenu et souris pour bouger un triangle).",30,480); }