Text Size
Text Size
Exit Full Screen
Python Mini
Show
Source Code
View Source Code in Full Screen
Open in New Tab
from processing import * from math import cos,sin def setup(): size(500,500,P3D) kickback = 0 prevk = 0 a = 0 keys = [] camx=-200 camy=-100 camz=200 class Laser: instances = [] def __init__(self,r,yy): self.x=30 self.yy = yy self.rotato=r Laser.instances.append(self) def keyPressed(): global kickback, a, keys if keyboard.keyCode not in keys: keys.append(keyboard.keyCode) if keyboard.keyCode == 32: kickback = -PI/4 Laser(prevk,a) def keyReleased(): global keys if keyboard.keyCode in keys: keys.remove(keyboard.keyCode) def draw(): global kickback, prevk, a, camx,camy,camz if LEFT in keys: a += 0.1 if RIGHT in keys: a -= 0.1 background(0) if 68 in keys: camx -= PI/100 if 65 in keys: camx += PI/100 camx %= TAU if 83 in keys and camy < 1000: camy += 2 if 87 in keys and camy > -1000: camy -= 2 if 69 in keys and camz < 1000: camz += 2 if 81 in keys and camz > 2: camz -= 2 fill(255) stroke(50) lights() camera(cos(camx)*camz, camy, sin(camx)*camz, 0.0, 0.0, 0.0,0.0, 1.0, 0.0) pushMatrix() rotateY(a) rotateZ(kickback) translate(-4.5, -12.5, 0.0) box(8.0, 10.0, 10.5) translate(19.5, 5.5, 0.0) box(10.0, 10.0, 10.0) translate(30.0, -5.5, 0.0) box(0.5, 25.0, 23.5) translate(-9.5, 0.0, 0.0) box(0.5, 25.0, 23.5) fill(255,150,150) translate(22.5, 0.0, 0.0) box(10.0, 10.0, 10.0) fill(255) translate(-24.5, 0.0, 0.0) box(46.0, 5.0, 4.0) translate(-9.5, 0.0, 0.0) box(8.0, 10.0, 10.5) translate(-16.5, 0.0, 0.0) box(30.5, 16.0, 16.0) translate(-7.5, 9.5, 0.0) box(13.5, 20.0, 12.0) popMatrix() noStroke() for i in Laser.instances: pushMatrix() rotateY(i.yy) rotateZ(i.rotato) fill(255,150,150) translate(-4.5, -12.5, 0.0) translate(19.5, 5.5, 0.0) translate(-9.5, 0.0, 0.0) translate(22.5, 0.0, 0.0) translate(i.x,-10,0) box(25,5,5) i.x += 5 popMatrix() if i.x > 500: Laser.instances.remove(i) prevk = kickback kickback %= -TAU if kickback < 0: kickback += 0.05 if kickback > 0: kickback = 0 stroke(255,0,0) line(100,0,0,0,0,0) stroke(0,255,0) line(0,100,0,0,0,0) stroke(0,0,255) pushMatrix() translate(0,0,50) box(.1,.1,100) popMatrix() stroke(255) noFill() box(50) run()
laser.py
( around 112 lines python code )
Published By:
luyfru
Published on
2023-09-21T19:00:03Z
Python Mini
- an
OYOclass
application,
own your own class today
.
Run
Result
×
Error message shows here