-
Notifications
You must be signed in to change notification settings - Fork 1
/
drawimage.py
53 lines (37 loc) · 1.44 KB
/
drawimage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from ursina import *
from PIL import Image
import parameters
app = Ursina()
class Canvas(Entity):
def __init__(self, add_to_scene_entities=True, **kwargs):
super().__init__(add_to_scene_entities, **kwargs)
self.dx = 0
self.dy = 0
def update(self):
res = 64
m = mouse.point
if mouse.left and m:
x = int(Vec2((Vec2(m.x,m.z)+Vec2(0.5,0.5))).x * res)
y = int(Vec2((Vec2(m.x,m.z)+Vec2(0.5,0.5))).y * res)
print((x,y))
self.texture.set_pixel(x,y, color.black)
self.dx = x
self.dy = y
if mouse.right and m:
x = int(Vec2((Vec2(m.x,m.z)+Vec2(0.5,0.5))).x * res)
y = int(Vec2((Vec2(m.x,m.z)+Vec2(0.5,0.5))).y * res)
print((x,y))
self.texture.set_pixel(x,y, color.white)
self.dx = x
self.dy = y
self.texture.apply()
# # uvtex = Texture(Image.new(mode="RGBA", size=(resolution,resolution), color=(255,0,0,255)))
canvtex = Texture(Image.new(mode="RGBA", size=(64,64), color=(255,255,255,255)))
# canvas = Entity(model='plane', texture=canvtex)
# uvtex = Texture(Image.new(mode="RGBA", size=(64,64), color=(255,0,0,255)))
# uv = Entity(model='plane', texture=uvtex) # set a PIL texture
c = Canvas(model='plane', texture=canvtex, collider='box')
cam = camera
cam.position = Vec3(0,4,0)
cam.look_at(Vec3(0,0,0), axis='forward')
app.run()