|
12 | 12 | models: {type: 'array', oneOf: ['one', 'two', 'three', 'four']} |
13 | 13 | } |
14 | 14 | }) |
| 15 | + |
| 16 | + AFRAME.registerComponent('draw-smiley', { |
| 17 | + schema: { |
| 18 | + canvas: {type: 'selector'} |
| 19 | + }, |
| 20 | + init() { |
| 21 | + var canvas = this.data.canvas; |
| 22 | + var ctx = canvas.getContext('2d'); |
| 23 | + |
| 24 | + // Clear canvas and fill with white background |
| 25 | + ctx.fillStyle = 'white'; |
| 26 | + ctx.fillRect(0, 0, canvas.width, canvas.height); |
| 27 | + |
| 28 | + // Center point of canvas |
| 29 | + var centerX = canvas.width / 2; |
| 30 | + var centerY = canvas.height / 2; |
| 31 | + |
| 32 | + // Smiley parameters |
| 33 | + var faceRadius = 200; |
| 34 | + var eyeRadius = 20; |
| 35 | + var eyeOffsetX = 60; |
| 36 | + var eyeOffsetY = 50; |
| 37 | + var mouthRadius = 120; |
| 38 | + |
| 39 | + // Draw face |
| 40 | + ctx.beginPath(); |
| 41 | + ctx.arc(centerX, centerY, faceRadius, 0, Math.PI * 2, true); // Outer circle |
| 42 | + ctx.fillStyle = 'yellow'; |
| 43 | + ctx.fill(); |
| 44 | + ctx.strokeStyle = 'black'; |
| 45 | + ctx.lineWidth = 4; |
| 46 | + ctx.stroke(); |
| 47 | + |
| 48 | + // Draw eyes |
| 49 | + ctx.beginPath(); |
| 50 | + ctx.arc(centerX - eyeOffsetX, centerY - eyeOffsetY, eyeRadius, 0, Math.PI * 2, true); // Left eye |
| 51 | + ctx.arc(centerX + eyeOffsetX, centerY - eyeOffsetY, eyeRadius, 0, Math.PI * 2, true); // Right eye |
| 52 | + ctx.fillStyle = 'black'; |
| 53 | + ctx.fill(); |
| 54 | + |
| 55 | + // Draw smile |
| 56 | + ctx.beginPath(); |
| 57 | + ctx.arc(centerX, centerY + 30, mouthRadius, 0, Math.PI, false); // Mouth (smile) |
| 58 | + ctx.lineWidth = 8; |
| 59 | + ctx.strokeStyle = 'black'; |
| 60 | + ctx.stroke(); |
| 61 | + } |
| 62 | + }) |
15 | 63 | </script> |
16 | 64 | </head> |
17 | 65 | <body> |
18 | 66 | <a-scene debug="true"> |
19 | 67 | <a-assets> |
| 68 | + <canvas id="canvasTexture" width="512" height="512" /> |
20 | 69 | <a-mixin id="blue" material="color: #4CC3D9"></a-mixin> |
21 | 70 | <a-mixin id="blueBox" geometry="primitive: box; depth: 2; height: 5; width: 1" material="color: #4CC3D9"></a-mixin> |
22 | 71 | <a-mixin id="box" geometry="primitive: box; depth: 1; height: 1; width: 1"></a-mixin> |
|
40 | 89 | <a-entity id="yellowSphere" geometry="primitive: sphere" material="color: #ff0; roughness: 1" position="-2 2 -2" models-array="models:one,two"></a-entity> |
41 | 90 | <a-box src="https://aframe.io/sample-assets/assets/images/bricks/brick_bump.jpg" position="-5 5 -2" width="1" color="#F16745"></a-box> |
42 | 91 | <a-box id="aBox" position="0 2 0" height="2" color="#FFC65D"></a-box> |
| 92 | + <a-plane id="smiley" position="2.5 2 0" width="1" height="1" material="src: #canvasTexture" draw-smiley="canvas: #canvasTexture"></a-plane> |
43 | 93 |
|
44 | 94 | <!-- Models. --> |
45 | 95 | <a-entity class="boxClass" geometry="primitive: box" material="src: #crateImg" position="3 4 0"></a-entity> |
|
0 commit comments