| 1 | import { ProcessingView } from "expo-processing"; |
| 2 | |
| 3 | const sketch = (p) => { |
| 4 | p.setup = () => { |
| 5 | p.strokeWeight(7); |
| 6 | }; |
| 7 | |
| 8 | const harom = (ax, ay, bx, by, level, ratio) => { |
| 9 | if (level <= 0) { |
| 10 | return; |
| 11 | } |
| 12 | |
| 13 | const vx = bx - ax; |
| 14 | const vy = by - ay; |
| 15 | const nx = p.cos(p.PI / 3) * vx - p.sin(p.PI / 3) * vy; |
| 16 | const ny = p.sin(p.PI / 3) * vx + p.cos(p.PI / 3) * vy; |
| 17 | const cx = ax + nx; |
| 18 | const cy = ay + ny; |
| 19 | p.line(ax, ay, bx, by); |
| 20 | p.line(ax, ay, cx, cy); |
| 21 | p.line(cx, cy, bx, by); |
| 22 | |
| 23 | harom( |
| 24 | ax * ratio + cx * (1 - ratio), |
| 25 | ay * ratio + cy * (1 - ratio), |
| 26 | ax * (1 - ratio) + bx * ratio, |
| 27 | ay * (1 - ratio) + by * ratio, |
| 28 | level - 1, |
| 29 | ratio |
| 30 | ); |
| 31 | }; |
| 32 | |
| 33 | p.draw = () => { |
| 34 | p.background(240); |
| 35 | harom( |
| 36 | p.width - 142, |
| 37 | p.height - 142, |
| 38 | 142, |
| 39 | p.height - 142, |
| 40 | 12, |
| 41 | (p.sin((0.0005 * Date.now()) % (2 * p.PI)) + 1) / 2 |
| 42 | ); |
| 43 | }; |
| 44 | }; |
| 45 | |
| 46 | export default function App() { |
| 47 | return <ProcessingView style={{ flex: 1 }} sketch={sketch} />; |