awacke1 commited on
Commit
8437049
·
verified ·
1 Parent(s): facffbf

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +35 -15
index.html CHANGED
@@ -25,21 +25,44 @@
25
  var world = new CANNON.World();
26
  world.gravity.set(0, -9.82, 0); // Apply gravity in the negative y direction
27
 
28
- // Card geometry
29
- var cardGeometry = new THREE.BoxGeometry(5, 0.1, 7);
30
- var cardMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff });
31
- var cards = [];
32
- var cardBodies = [];
33
-
34
  // Lighting
35
- var ambientLight = new THREE.AmbientLight(0x404040);
36
  scene.add(ambientLight);
37
  var directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
38
  directionalLight.position.set(0, 1, 1);
39
  scene.add(directionalLight);
40
 
41
- // Card creation
42
- function addCard(x, y, z) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  var card = new THREE.Mesh(cardGeometry, cardMaterial);
44
  card.position.set(x, y, z);
45
  scene.add(card);
@@ -47,21 +70,18 @@
47
 
48
  // Physics for card
49
  var cardShape = new CANNON.Box(new CANNON.Vec3(2.5, 0.05, 3.5));
50
- var cardBody = new CANNON.Body({ mass: 1 });
51
  cardBody.addShape(cardShape);
52
  cardBody.position.set(x, y, z);
53
  world.addBody(cardBody);
54
  cardBodies.push(cardBody);
55
  }
56
 
57
- // Example: Add a stack of cards
58
  for (let i = 0; i < 52; i++) {
59
- addCard(0, i * 0.2, 0); // Adjust position as needed
60
  }
61
 
62
- // Drag and drop functionality (simplified)
63
- // You will need to implement raycasting to pick up and move cards
64
-
65
  function animate() {
66
  requestAnimationFrame(animate);
67
 
 
25
  var world = new CANNON.World();
26
  world.gravity.set(0, -9.82, 0); // Apply gravity in the negative y direction
27
 
 
 
 
 
 
 
28
  // Lighting
29
+ var ambientLight = new THREE.AmbientLight(0x404040); // Soft white light
30
  scene.add(ambientLight);
31
  var directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
32
  directionalLight.position.set(0, 1, 1);
33
  scene.add(directionalLight);
34
 
35
+ // Table surface
36
+ var tableGeometry = new THREE.BoxGeometry(100, 1, 100);
37
+ var tableMaterial = new THREE.MeshLambertMaterial({ color: 0x8B4513 }); // Brown color for the table
38
+ var table = new THREE.Mesh(tableGeometry, tableMaterial);
39
+ table.position.set(0, -1, 0); // Position the table slightly below where the cards will be
40
+ scene.add(table);
41
+
42
+ // Card geometry
43
+ var cardGeometry = new THREE.BoxGeometry(5, 0.1, 7); // Generic card size
44
+ var cards = [];
45
+ var cardBodies = []; // For physics bodies
46
+
47
+ // Shuffle and color assignment
48
+ var colors = []; // Array to hold colors
49
+ // Generate unique colors for each card
50
+ for (let i = 0; i < 52; i++) {
51
+ colors.push(Math.random() * 0xffffff); // Generate random color
52
+ }
53
+
54
+ function shuffleArray(array) {
55
+ for (let i = array.length - 1; i > 0; i--) {
56
+ const j = Math.floor(Math.random() * (i + 1));
57
+ [array[i], array[j]] = [array[j], array[i]]; // Swap
58
+ }
59
+ }
60
+
61
+ shuffleArray(colors); // Shuffle the colors array to simulate shuffling cards
62
+
63
+ // Card creation with physics and color based on shuffle
64
+ function addCard(x, y, z, colorIndex) {
65
+ var cardMaterial = new THREE.MeshLambertMaterial({ color: colors[colorIndex] });
66
  var card = new THREE.Mesh(cardGeometry, cardMaterial);
67
  card.position.set(x, y, z);
68
  scene.add(card);
 
70
 
71
  // Physics for card
72
  var cardShape = new CANNON.Box(new CANNON.Vec3(2.5, 0.05, 3.5));
73
+ var cardBody = new CANNON.Body({ mass: 0.1 }); // Cards are lightweight
74
  cardBody.addShape(cardShape);
75
  cardBody.position.set(x, y, z);
76
  world.addBody(cardBody);
77
  cardBodies.push(cardBody);
78
  }
79
 
80
+ // Create a stack of cards
81
  for (let i = 0; i < 52; i++) {
82
+ addCard(0, i * 0.2 + 1, 0, i); // Position cards in a stack, slightly offset in the y direction
83
  }
84
 
 
 
 
85
  function animate() {
86
  requestAnimationFrame(animate);
87