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 random import randint, choice, random def setup(): size(500,500,P3D) class Tree: instances = [] def __init__(self,x,y,z): self.x=x self.y=y self.z=z Tree.instances.append(self) print("la lalalalalala la la katamari damacuy") print("press space and shift") c = 30#int(input("tree")) for i in range(c): Tree(random()*TAU,random()*TAU,random()*TAU) a = 0.0 b = 1.0 colored = False stepps = False def keyPressed(): global colored, stepps if keyboard.keyCode == 32: if colored: colored = False else: colored = True if keyboard.keyCode == 16: if stepps: stepps = False else: stepps = True def exphone(var,target,mult,snap): if var < snap+target and var > target-snap and var != target: var = target else: var += (target-var)/mult return var def tree(): pushMatrix() if colored: fill(0,100,0) translate(0,-240,0) translate(-5.5, -24.0, -11.0) box(30.0, 30.0, 30.0) translate(4.0, -23.5, 17.0) box(30.0, 30.0, 30.0) translate(-5.5, 14.5, 11.5) box(30.0, 30.0, 30.0) translate(-13.5, 3.0, -12.5) box(30.0, 30.0, 30.0) translate(36.5, -6.5, -15.5) box(30.0, 30.0, 30.0) translate(-27.0, -5.5, -4.5) box(30.0, 30.0, 30.0) translate(35.5, 11.5, 21.0) box(30.0, 30.0, 30.0) translate(-12.0, -5.5, 12.0) box(30.0, 30.0, 30.0) if colored: fill(100,50,0) translate(-12.5, 36.0, -18.0) box(20.0, 75.0, 10.0) translate(0.0, 0.0, 0.0) box(10.0, 74.0, 20.0) translate(0.0, 33.0, 0.0) box(7.0, 7.5, 40.0) translate(0.0, 0.0, 0.0) box(40.5, 8.5, 7.0) popMatrix() def car(): pushMatrix() if colored: fill(100) translate(0,-170,0) translate(-4.5, -117.5, 0.0) box(7.5, 1.5, 45.5) translate(41.0, 4.5, 0.0) box(10.0, 7.0, 32.0) translate(-36.5, 4.0, 0.0) box(71.5, 9.5, 33.5) translate(26.0, 5.5, 0.0) box(10.0, 10.0, 43.0) translate(-52.5, 0.0, 0.0) box(10.0, 10.0, 43.0) if colored: fill(200,200,250) translate(10.5, -25.0, 0.0) box(27.0, 10.0, 41.5) translate(12.0, 5.5, 0.0) box(32.5, 16.5, 34.5) if colored: fill(200,0,0) translate(-12.0, -2.0, 0.0) box(42.5, 23.0, 35.5) translate(15.5, 11.0, 0.0) box(78.0, 17.0, 41.0) popMatrix() def plane(): if colored: fill(255) pushMatrix() translate(0,-470,0) translate(0.0, 4.0, -93.5) box(52.0, 8.0, 3.5) translate(0.0, 0.5, 0.0) box(8.5, 50.0, 3.5) translate(0.0, 0.0, 1.5) box(8.5, 9.0, 10.0) if colored: fill(150) translate(0.0, 0.0, 6.5) box(22.5, 20.0, 10.0) if colored: fill(200,200,250) translate(0.0, -15.5, 45.5) box(17.5, 15.0, 62.5) if colored: fill(150) translate(0.0, 0.0, 77.5) box(5.0, 42.0, 41.5) translate(0.0, 16.0, -63.0) box(31.5, 31.5, 117.0) translate(0.0, -5.0, -37.0) box(172.5, 3.5, 26.5) translate(0.0, 0.0, 0.0) box(138.0, 4.5, 31.0) popMatrix() def draw(): global a, c, b background(10) stroke(1) fill(255) lights() #camera(295.1967405286, -277.0, 362.11594799, 0, 0, 0, 0, 1, 0) camera(495.1967405286, -477.0, 562.11594799, 0, 0, 0, 0, 1, 0) noStroke() #noFill()# #stroke(255)# if colored: fill(0,150,0) sphere(205) stroke(1) pushMatrix() rotateY(a/-2) for i in Tree.instances: pushMatrix() rotateZ(i.z) rotateY(i.y) rotateX(i.x) tree() ''' if randint(0,3) != 0: i.z += (random())/50 if randint(0,3) != 0: i.y += (random())/50 if randint(0,3) != 0: i.x += (random())/50 ''' popMatrix() #stroke(1)# #fill(255)# pushMatrix() rotateZ(a) scale(.75,.75,.75) for i in range(7): rotateZ(PI/4) car() popMatrix() popMatrix() pushMatrix() rotateX(a*1.5) scale(.75,.75,.75) for i in range(5): rotateX(PI/3) plane() popMatrix() if stepps: a = exphone(a,b,15,0.1) if a == b: b += PI/4 else: a += 0.03 run()
trees.py
( around 184 lines python code )
Published By:
luyfru
Published on
2023-09-21T19:00:48Z
Python Mini
- an
OYOclass
application,
own your own class today
.
Run
Result
×
Error message shows here