Skip to content

Commit

Permalink
Add spiral example
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmilano committed Nov 30, 2024
1 parent 2971f5f commit 6e6f54b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions examples/helper/spiral
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#! /usr/bin/env python3
import numpy as np
from com.dtmilano.android.viewclient import ViewClient

def toint(n):
return n.item()

def npint(a):
return np.round(a).astype(int)

def spiral(t):
a = 0.5 # Controls the tightness of the spiral
b = 0.5 # Controls the spacing between turns
g = 40 # Factor
dx = 400 # Delta x
dy = 600 # Delta y
x = g * a * t * np.cos(t + b) + dx
y = g * a * t * np.sin(t + b) + dy
return list(zip(map(toint, npint(x)), map(toint, npint(y))))

# get helper
helper = ViewClient.view_client_helper()

# generate values for the parameter t
t = np.linspace(0, 4 * np.pi, 100)

# calculate (x, y) coordinates
segments = spiral(t)

# assume google keep is open so we can see it drawing
# see spiral.gif
helper.ui_device.swipe(segments=segments, segment_steps=3)
Binary file added examples/helper/spiral.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6e6f54b

Please sign in to comment.