kopia lustrzana https://github.com/villares/sketch-a-day
				
				
				
			first step!
							rodzic
							
								
									6aa0dcb224
								
							
						
					
					
						commit
						b7154d15a0
					
				|  | @ -30,7 +30,6 @@ PlatonicSolid PlatonicFactory(int type, color c) { | |||
| } | ||||
| class Icosahedron extends PlatonicSolid { | ||||
|   // icosahedron | ||||
|   float x, y, z; | ||||
|   float radius; | ||||
|   PVector topPoint; | ||||
|   PVector[] topPent = new PVector[5]; | ||||
|  | @ -44,13 +43,10 @@ class Icosahedron extends PlatonicSolid { | |||
|   // constructor | ||||
|   Icosahedron(float radius) { | ||||
|     this.radius = radius; | ||||
| 
 | ||||
|     c = dist(cos(0)*radius, sin(0)*radius, cos(radians(72))*radius, sin(radians(72))*radius); | ||||
|     b = radius; | ||||
|     a = (float)(Math.sqrt(((c*c)-(b*b)))); | ||||
| 
 | ||||
|     triHt = (float)(Math.sqrt((c*c)-((c/2)*(c/2)))); | ||||
| 
 | ||||
|     for (int i=0; i<topPent.length; i++) { | ||||
|       topPent[i] = new PVector(cos(angle)*radius, sin(angle)*radius, triHt/2.0f); | ||||
|       angle+=radians(72); | ||||
|  | @ -71,26 +67,26 @@ class Icosahedron extends PlatonicSolid { | |||
|       // icosahedron top | ||||
|       beginShape(); | ||||
|       if (i<topPent.length-1) { | ||||
|         vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z); | ||||
|         vertex(x+topPoint.x, y+topPoint.y, z+topPoint.z); | ||||
|         vertex(x+topPent[i+1].x, y+topPent[i+1].y, z+topPent[i+1].z); | ||||
|         vertex(topPent[i].x, topPent[i].y, topPent[i].z); | ||||
|         vertex(topPoint.x, topPoint.y, topPoint.z); | ||||
|         vertex(topPent[i+1].x, topPent[i+1].y, topPent[i+1].z); | ||||
|       } else { | ||||
|         vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z); | ||||
|         vertex(x+topPoint.x, y+topPoint.y, z+topPoint.z); | ||||
|         vertex(x+topPent[0].x, y+topPent[0].y, z+topPent[0].z); | ||||
|         vertex(topPent[i].x, topPent[i].y, topPent[i].z); | ||||
|         vertex(topPoint.x, topPoint.y, topPoint.z); | ||||
|         vertex(topPent[0].x, topPent[0].y, topPent[0].z); | ||||
|       } | ||||
|       endShape(CLOSE); | ||||
| 
 | ||||
|       // icosahedron bottom | ||||
|       beginShape(); | ||||
|       if (i<bottomPent.length-1) { | ||||
|         vertex(x+bottomPent[i].x, y+bottomPent[i].y, z+bottomPent[i].z); | ||||
|         vertex(x+bottomPoint.x, y+bottomPoint.y, z+bottomPoint.z); | ||||
|         vertex(x+bottomPent[i+1].x, y+bottomPent[i+1].y, z+bottomPent[i+1].z); | ||||
|         vertex(bottomPent[i].x, bottomPent[i].y, bottomPent[i].z); | ||||
|         vertex(bottomPoint.x, bottomPoint.y, bottomPoint.z); | ||||
|         vertex(bottomPent[i+1].x, bottomPent[i+1].y, bottomPent[i+1].z); | ||||
|       } else { | ||||
|         vertex(x+bottomPent[i].x, y+bottomPent[i].y, z+bottomPent[i].z); | ||||
|         vertex(x+bottomPoint.x, y+bottomPoint.y, z+bottomPoint.z); | ||||
|         vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z); | ||||
|         vertex(bottomPent[i].x, bottomPent[i].y, bottomPent[i].z); | ||||
|         vertex(bottomPoint.x, bottomPoint.y, bottomPoint.z); | ||||
|         vertex(bottomPent[0].x, bottomPent[0].y, bottomPent[0].z); | ||||
|       } | ||||
|       endShape(CLOSE); | ||||
|     } | ||||
|  | @ -99,39 +95,39 @@ class Icosahedron extends PlatonicSolid { | |||
|     for (int i=0; i<topPent.length; i++) { | ||||
|       if (i<topPent.length-2) { | ||||
|         beginShape(); | ||||
|         vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z); | ||||
|         vertex(x+bottomPent[i+1].x, y+bottomPent[i+1].y, z+bottomPent[i+1].z); | ||||
|         vertex(x+bottomPent[i+2].x, y+bottomPent[i+2].y, z+bottomPent[i+2].z); | ||||
|         vertex(topPent[i].x, topPent[i].y, topPent[i].z); | ||||
|         vertex(bottomPent[i+1].x, bottomPent[i+1].y, bottomPent[i+1].z); | ||||
|         vertex(bottomPent[i+2].x, bottomPent[i+2].y, bottomPent[i+2].z); | ||||
|         endShape(CLOSE); | ||||
| 
 | ||||
|         beginShape(); | ||||
|         vertex(x+bottomPent[i+2].x, y+bottomPent[i+2].y, z+bottomPent[i+2].z); | ||||
|         vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z); | ||||
|         vertex(x+topPent[i+1].x, y+topPent[i+1].y, z+topPent[i+1].z); | ||||
|         vertex(bottomPent[i+2].x, bottomPent[i+2].y, bottomPent[i+2].z); | ||||
|         vertex(topPent[i].x, topPent[i].y, topPent[i].z); | ||||
|         vertex(topPent[i+1].x, topPent[i+1].y, topPent[i+1].z); | ||||
|         endShape(CLOSE); | ||||
|       } else if (i==topPent.length-2) { | ||||
|         beginShape(); | ||||
|         vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z); | ||||
|         vertex(x+bottomPent[i+1].x, y+bottomPent[i+1].y, z+bottomPent[i+1].z); | ||||
|         vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z); | ||||
|         vertex(topPent[i].x, topPent[i].y, topPent[i].z); | ||||
|         vertex(bottomPent[i+1].x, bottomPent[i+1].y, bottomPent[i+1].z); | ||||
|         vertex(bottomPent[0].x, bottomPent[0].y, bottomPent[0].z); | ||||
|         endShape(CLOSE); | ||||
| 
 | ||||
|         beginShape(); | ||||
|         vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z); | ||||
|         vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z); | ||||
|         vertex(x+topPent[i+1].x, y+topPent[i+1].y, z+topPent[i+1].z); | ||||
|         vertex(bottomPent[0].x, bottomPent[0].y, bottomPent[0].z); | ||||
|         vertex(topPent[i].x, topPent[i].y, topPent[i].z); | ||||
|         vertex(topPent[i+1].x, topPent[i+1].y, topPent[i+1].z); | ||||
|         endShape(CLOSE); | ||||
|       } else if (i==topPent.length-1) { | ||||
|         beginShape(); | ||||
|         vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z); | ||||
|         vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z); | ||||
|         vertex(x+bottomPent[1].x, y+bottomPent[1].y, z+bottomPent[1].z); | ||||
|         vertex(topPent[i].x, topPent[i].y, topPent[i].z); | ||||
|         vertex(bottomPent[0].x, bottomPent[0].y, bottomPent[0].z); | ||||
|         vertex(bottomPent[1].x, bottomPent[1].y, bottomPent[1].z); | ||||
|         endShape(CLOSE); | ||||
| 
 | ||||
|         beginShape(); | ||||
|         vertex(x+bottomPent[1].x, y+bottomPent[1].y, z+bottomPent[1].z); | ||||
|         vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z); | ||||
|         vertex(x+topPent[0].x, y+topPent[0].y, z+topPent[0].z); | ||||
|         vertex(bottomPent[1].x, bottomPent[1].y, bottomPent[1].z); | ||||
|         vertex(topPent[i].x, topPent[i].y, topPent[i].z); | ||||
|         vertex(topPent[0].x, topPent[0].y, topPent[0].z); | ||||
|         endShape(CLOSE); | ||||
|       } | ||||
|     } | ||||
|  | @ -142,7 +138,6 @@ class Icosahedron extends PlatonicSolid { | |||
| class Tetrahedron extends PlatonicSolid { | ||||
| 
 | ||||
|   // Tetrahedron | ||||
|   float x, y, z; | ||||
|   float radius; | ||||
|   float a; | ||||
|   PVector[] vert = new PVector[4]; | ||||
|  | @ -268,11 +263,8 @@ class Octahedron extends PlatonicSolid { | |||
| } | ||||
| 
 | ||||
| class Dodecahedron extends PlatonicSolid { | ||||
| 
 | ||||
|   // Dodecahedron | ||||
|   float x, y, z; | ||||
|   float radius; | ||||
| 
 | ||||
|   float a, b, c; | ||||
|   PVector[] vert; | ||||
|   int[][] faces; | ||||
|  | @ -280,7 +272,6 @@ class Dodecahedron extends PlatonicSolid { | |||
|   // constructor | ||||
|   Dodecahedron(float radius) { | ||||
|     this.radius = radius; | ||||
| 
 | ||||
|     a = radius/1.618033989; | ||||
|     b = radius; | ||||
|     c = 0.618033989*a; | ||||
|  |  | |||
										
											Plik binarny nie jest wyświetlany.
										
									
								
							|  | @ -0,0 +1,106 @@ | |||
| class Icosahedron(): | ||||
| 
 | ||||
|     def __init__(self, radius): | ||||
|         topPent = [PVector()] * 5  # PVector[5] | ||||
|         bottomPent = [PVector()] * 5  # PVector[5] | ||||
|         angle = 0 | ||||
|         c = dist(cos(0) * radius, | ||||
|                  sin(0) * radius, | ||||
|                  cos(radians(72)) * radius, | ||||
|                  sin(radians(72)) * radius) | ||||
|         b = radius | ||||
|         a = sqrt(((c * c) - (b * b))) | ||||
|         triHt = sqrt((c * c) - ((c / 2) * (c / 2))) | ||||
|         for i in range(5): | ||||
|             topPent[i] = PVector(cos(angle) * radius, | ||||
|                                  sin(angle) * radius, | ||||
|                                  triHt / 2.0) | ||||
|             angle += radians(72) | ||||
|         topPoint = PVector(0, 0, triHt / 2.0 + a) | ||||
|         angle = 72.0 / 2.0 | ||||
|         for i in range(5): | ||||
|             bottomPent[i] = PVector(cos(angle) * radius, | ||||
|                                     sin(angle) * radius, | ||||
|                                     -triHt / 2.0) | ||||
|             angle += radians(72) | ||||
|         bottomPoint = PVector(0, 0, -(triHt / 2.0 + a)) | ||||
|         self.topPent, self.bottomPent = topPent, bottomPent | ||||
|         self.topPoind, self.bottomPoint = topPoint, bottomPoint | ||||
| 
 | ||||
|         # draws icosahedron | ||||
|     def create(self): | ||||
|         topPent, bottomPent = self.topPent, self.bottomPent | ||||
|         topPoint, bottomPoint = self.topPoind, self.bottomPoint | ||||
|         for i in range(5): | ||||
|             # icosahedron top | ||||
|             beginShape() | ||||
|             if (i < 5 - 1): | ||||
|                 vertex(topPent[i].x, topPent[i].y, topPent[i].z) | ||||
|                 vertex(topPoint.x, topPoint.y, topPoint.z) | ||||
|                 vertex( | ||||
|                     topPent[i + 1].x, topPent[i + 1].y, topPent[i + 1].z) | ||||
|             else: | ||||
|                 vertex(topPent[i].x, topPent[i].y, topPent[i].z) | ||||
|                 vertex(topPoint.x, topPoint.y, topPoint.z) | ||||
|                 vertex(topPent[0].x, topPent[0].y, topPent[0].z) | ||||
| 
 | ||||
|             endShape(CLOSE) | ||||
| 
 | ||||
|             # icosahedron bottom | ||||
|             beginShape() | ||||
|             if (i < len(bottomPent) - 1): | ||||
|                 vertex(bottomPent[i].x, bottomPent[i].y, bottomPent[i].z) | ||||
|                 vertex(bottomPoint.x, bottomPoint.y, bottomPoint.z) | ||||
|                 vertex( | ||||
|                     bottomPent[i + 1].x, bottomPent[i + 1].y, bottomPent[i + 1].z) | ||||
|             else: | ||||
|                 vertex(bottomPent[i].x, bottomPent[i].y, bottomPent[i].z) | ||||
|                 vertex(bottomPoint.x, bottomPoint.y, bottomPoint.z) | ||||
|                 vertex(bottomPent[0].x, bottomPent[0].y, bottomPent[0].z) | ||||
| 
 | ||||
|             endShape(CLOSE) | ||||
| 
 | ||||
|         # icosahedron body | ||||
|         for i in range(5): | ||||
|             if i < 3: | ||||
|                 beginShape() | ||||
|                 vertex(topPent[i].x, topPent[i].y, topPent[i].z) | ||||
|                 vertex( | ||||
|                     bottomPent[i + 1].x, bottomPent[i + 1].y, bottomPent[i + 1].z) | ||||
|                 vertex( | ||||
|                     bottomPent[i + 2].x, bottomPent[i + 2].y, bottomPent[i + 2].z) | ||||
|                 endShape(CLOSE) | ||||
| 
 | ||||
|                 beginShape() | ||||
|                 vertex( | ||||
|                     bottomPent[i + 2].x, bottomPent[i + 2].y, bottomPent[i + 2].z) | ||||
|                 vertex(topPent[i].x, topPent[i].y, topPent[i].z) | ||||
|                 vertex( | ||||
|                     topPent[i + 1].x, topPent[i + 1].y, topPent[i + 1].z) | ||||
|                 endShape(CLOSE) | ||||
|             elif i == 3: | ||||
|                 beginShape() | ||||
|                 vertex(topPent[i].x, topPent[i].y, topPent[i].z) | ||||
|                 vertex( | ||||
|                     bottomPent[i + 1].x, bottomPent[i + 1].y, bottomPent[i + 1].z) | ||||
|                 vertex(bottomPent[0].x, bottomPent[0].y, bottomPent[0].z) | ||||
|                 endShape(CLOSE) | ||||
| 
 | ||||
|                 beginShape() | ||||
|                 vertex(bottomPent[0].x, bottomPent[0].y, bottomPent[0].z) | ||||
|                 vertex(topPent[i].x, topPent[i].y, topPent[i].z) | ||||
|                 vertex( | ||||
|                     topPent[i + 1].x, topPent[i + 1].y, topPent[i + 1].z) | ||||
|                 endShape(CLOSE) | ||||
|             elif i == 4: | ||||
|                 beginShape() | ||||
|                 vertex(topPent[i].x, topPent[i].y, topPent[i].z) | ||||
|                 vertex(bottomPent[0].x, bottomPent[0].y, bottomPent[0].z) | ||||
|                 vertex(bottomPent[1].x, bottomPent[1].y, bottomPent[1].z) | ||||
|                 endShape(CLOSE) | ||||
| 
 | ||||
|                 beginShape() | ||||
|                 vertex(bottomPent[1].x, bottomPent[1].y, bottomPent[1].z) | ||||
|                 vertex(topPent[i].x, topPent[i].y, topPent[i].z) | ||||
|                 vertex(topPent[0].x, topPent[0].y, topPent[0].z) | ||||
|                 endShape(CLOSE) | ||||
|  | @ -0,0 +1,42 @@ | |||
| from PlatonicSolids import * | ||||
| 
 | ||||
| NUM_COLS, NUM_ROWS = 5, 5 | ||||
| NUM_CELLS = NUM_COLS * NUM_ROWS | ||||
| solids = [] | ||||
| r_x = 0 | ||||
| r_y = 0 | ||||
| 
 | ||||
| def setup(): | ||||
|     global CELL_SIZE | ||||
|     size(500, 500, P3D) | ||||
|     CELL_SIZE = width / NUM_COLS | ||||
|     strokeWeight(5) | ||||
|     noFill() | ||||
|     colorMode(HSB) | ||||
|     for i in range(NUM_CELLS): | ||||
|         s = Icosahedron(CELL_SIZE / 2.5) | ||||
|         c = color(random(256), 200, 200, 128)  # random HSB translucent colors | ||||
|         solids.append((s, c))  # (solid, color) | ||||
| 
 | ||||
| def draw(): | ||||
|     global r_x, r_y | ||||
|     # translate(-width/2, -height/2) # may need to use with PeasyCam | ||||
|     r_x += 0.02  # x rotation speed | ||||
|     r_y += 0.01  # y rotation speed | ||||
|     background(255)  # clear frame with white | ||||
|     # lights() # use this with filled faces | ||||
|     for i in range(NUM_CELLS): | ||||
|         x, y = x_y_from_i(i, NUM_COLS, NUM_ROWS) | ||||
|         cx, cy = CELL_SIZE / 2 + x * CELL_SIZE, CELL_SIZE / 2 + y * CELL_SIZE | ||||
|         with pushMatrix(): | ||||
|             d = dist(mouseX, mouseY, cx, cy) | ||||
|             translate(cx, cy) | ||||
|             if d < 80: | ||||
|                 rotateX(r_y) | ||||
|                 rotateY(r_x) | ||||
|             stroke(solids[i][1]) | ||||
|             solids[i][0].create() | ||||
|     # if (frameCouNUM_CELLS < 200): saveFrame("###.tga") | ||||
| 
 | ||||
| def x_y_from_i(i, max_x, max_y): | ||||
|     return i % max_x, (i / max_x) % max_y | ||||
		Ładowanie…
	
		Reference in New Issue
	
	 Alexandre B A Villares
						Alexandre B A Villares