Oscillating Box in Python - EricEisaman/cs1-ide GitHub Wiki

Oscillating Box in Python


from browser import window
from javascript import this

def init():
  window.CS1.log(this().el.tagName)

def tick(t,dt):
  this().el.object3D.position.y = 2 * window.Math.sin(t/1000) + 3

window.AFRAME.registerComponent('pyframe', {'init': init, 'tick': tick})

box = window.document.createElement('a-box')
box.setAttribute('pyframe','')
box.object3D.position.set(-9,4,-14)
box.setAttribute('color','maroon')

def game_start(e):
  window.CS1.scene.appendChild(box)
  window.CS1.log('Python in action!')

window.document.addEventListener('gameStart', game_start)