def __init__(self, step=3, x=370, y=205, camera=graphics.CAMERA, shader=graphics.MATSH): shape = [[], [], []] self.wifi_lines = [] for x1 in range(-45, 45, step): s, c = sin(radians(x1)), cos(radians(x1)) shape[0].append((7 * s, 7 * c, 0.1)) shape[1].append((14 * s, 14 * c, 0.1)) shape[2].append((21 * s, 21 * c, 0.1)) self.wifi_lines.append( pi3d.Disk(radius=2, sides=7, z=0.1, rx=90, x=x, y=y, camera=camera)) self.wifi_lines[0].set_shader(shader) self.wifi_lines[0].set_material((1, 1, 1)) for x1 in range(3): self.wifi_lines.append( pi3d.Lines(vertices=shape[x1], line_width=3, x=x, y=y, strip=True)) self.wifi_lines[x1 + 1].set_shader(shader) self.wifi_lines[x1 + 1].set_material((1, 1, 1))
def __init__(self, x=0, y=-235, radius=4, camera=graphics.CAMERA, shader=graphics.MATSH): self.x = x - ((10 * len(config.slides)) / 2) + radius self.status = [] self.md = pi3d.MergeShape(name="merged dots", camera=graphics.CAMERA) disk = pi3d.Disk(radius=radius, sides=7, z=0.2, rx=90, x=x, y=y, camera=camera) for x1 in range(len(config.slides)): self.md.add(disk.buf[0], x=self.x + (10 * x1), y=y, z=0.2, rx=90) self.md.set_shader(graphics.MATSH) self.md.set_material((1.0, 1.0, 1.0)) self.md.set_alpha(0.5) self.actslide = pi3d.Disk(radius=radius, sides=7, z=0.1, x=self.x + (10 * config.slide), rx=90, y=y, camera=camera) self.actslide.set_shader(shader) self.actslide.set_material((1, 1, 1)) self.actslide.set_alpha(1)
(r, g, b) = colorsys.hsv_to_rgb(resultInDegrees / 360, distanceToCenter, 1) r = int(r * 255) g = int(g * 255) b = int(b * 255) image.putpixel((x, y), (r, g, b)) #image.save("/home/pi/circulargradient.png") tex2 = pi3d.Texture(image) dot = pi3d.Disk(radius=220, sides=50, x=0, y=0, z=0.2, rx=90, camera=graphics.CAMERA) dot.set_textures([tex2]) dot.set_shader(graphics.SHADER) dot2 = pi3d.Disk(radius=222, sides=50, x=0, y=0, z=0.3, rx=90, camera=graphics.CAMERA) dot2.set_shader(graphics.MATSH) dot2.set_material((0, 0, 0))
for x in range(0, 365, 5): s, c = sin(radians(x)), cos(radians(x)) shape.append((150 * s, 150 * c, 2)) if x % 30 == 0: # 30 degrees between hours shape.append((140 * s, 140 * c, 2)) shape.append((150 * s, 150 * c, 2)) #myTime = time.strftime("%-I:%M %p") # shape.append((0,0,2)) background = pi3d.Sprite(camera=graphics.CAMERA, w=780, h=460, z=2.5, x=0, y=0) background.set_shader(graphics.MATSH) background.set_material((0.0, 0.0, 0.0)) background.set_alpha(0.7) # default orientated in x,z plane so rotate ball = pi3d.Disk(radius=150, sides=24, z=2.5, rx=90, camera=graphics.CAMERA) ball.set_shader(graphics.MATSH) ball.set_material((1, 1, 1)) ball.set_alpha(0.6) # default orientated in x,z plane so rotate dot = pi3d.Disk(radius=8, sides=8, z=0.1, rx=90, camera=graphics.CAMERA) dot.set_shader(graphics.MATSH) dot.set_material((1, 0, 0)) dot.set_alpha(1) edge_line = pi3d.Lines(vertices=shape, line_width=5, strip=True) edge_line.set_shader(graphics.MATSH) edge_line.set_material((0.3, 0.1, 0)) edge_line.set_alpha(1)
def __init__(self, width=600, step=20, x=-300, y=0, thickness=50, min_t=1, max_t=31): self.width = width self.step = step self.thickness = thickness self.min_t = min_t self.max_t = max_t self.x = x self.y = y self.value = max_t tick_verts = [] dial_verts = [] bline_verts = [] # first make tick vertices for x2 in range(0, self.width, self.step): tick_verts.extend([(x2, -self.thickness / 2, 0.2), (x2, self.thickness / 2, 0.2)]) bline_verts.append((x2, 0, 0.5)) for x2 in range(self.x - 9, self.x + self.width + 3, self.step): dial_verts.append((x2, 0, 0.5)) tex = pi3d.Texture( resource_filename("shpi", "sprites/color_gradient.jpg")) self.ticks = pi3d.PolygonLines(camera=graphics.CAMERA, x=self.x, y=self.y, vertices=tick_verts, strip=False, line_width=15) self.ticks.set_shader(graphics.MATSH) self.ticks.set_alpha(0.6) self.bline = pi3d.PolygonLines(camera=graphics.CAMERA, x=self.x, y=self.y, vertices=bline_verts, line_width=self.thickness) self.bline.set_textures([tex]) self.bline.set_alpha(0.5) self.bline.set_shader(graphics.SHADER) self.bline.set_material((0.5, 0.5, 0.5)) self.dial = pi3d.PolygonLines(camera=graphics.CAMERA, x=0, y=self.y, vertices=dial_verts, line_width=self.thickness + 6) self.dial.set_alpha(0.4) self.dial.set_shader(graphics.MATSH) self.dial.set_material((0, 0, 0)) self.actval = pi3d.PointText(graphics.pointFont, graphics.CAMERA, max_chars=8, point_size=100) self.temp_set = pi3d.TextBlock(self.x, self.y + 50, 0.1, 0.0, 2, text_format="00", size=0.6, spacing="F", space=0.02, colour=(0.0, 0.0, 0.0, 1), justify=1) self.actval.add_text_block(self.temp_set) self.dot2 = pi3d.Disk(radius=int(self.thickness / 2) + 3, sides=30, x=self.x, y=self.y, z=0.2, rx=90, camera=graphics.CAMERA) self.dot2.set_shader(graphics.MATSH) self.dot2.set_material((1, 1, 1)) self.dot2.set_alpha(0.8) self.valuex = 0 self.changed = 0
def __init__(self, angle_fr=-135, angle_to=135, step=5, outer=240, inner=200, min_t=15, max_t=35, shader=None, camera=None): self.angle_fr = angle_fr self.angle_to = angle_to self.step = step self.outer = outer self.inner = inner self.mid = (outer + inner) / 2 self.min_t = min_t self.max_t = max_t gpio.setmode(gpio.BCM) gpio.setwarnings(False) gpio.setup(26, gpio.IN, pull_up_down=gpio.PUD_DOWN) self.bus = i2c.I2C(2) try: self.bus.read(1, 0x5c) self.bus.write([0x6e, 0b00001110], 0x5c) self.bus.write([0x70, 0b00000000], 0x5c) except: print('Error: no touchscreen found') tick_verts = [] dial_verts = [] # first make tick vertices for x in range(self.angle_fr, self.angle_to, self.step): (s, c) = (sin(radians(x)), cos(radians(x)) ) # re-use for brevity below tick_verts.extend([(self.inner * s, self.inner * c, 0.1), (self.outer * s, self.outer * c, 0.1)]) dial_verts.append((self.mid * s, self.mid * c, 2.0)) if shader is None: shader = pi3d.Shader('mat_flat') if camera is None: camera = pi3d.Camera(is_3d=False) uv_shader = pi3d.Shader('uv_flat') tex = pi3d.Texture('color_gradient.jpg') self.ticks = pi3d.PolygonLines(camera=camera, vertices=tick_verts, strip=False, line_width=5) self.ticks.set_shader(shader) self.ticks.set_alpha(0.8) self.sensorticks = pi3d.PolygonLines(camera=camera, vertices=tick_verts, line_width=5, strip=False) self.sensorticks.set_shader(shader) self.bline = pi3d.PolygonLines(camera=camera, vertices=dial_verts, line_width=40) self.bline.set_textures([tex]) self.bline.set_alpha(0.8) self.bline.set_shader(uv_shader) self.bline.set_material((0.5, 0.5, 0.5)) self.dial = pi3d.PolygonLines(camera=camera, vertices=dial_verts, line_width=8) self.dial.set_alpha(0.2) self.dial.set_shader(shader) font = pi3d.Font('opensans.ttf', codepoints='0123456789.-°', grid_size=5) self.actval = pi3d.PointText(font, camera, max_chars=10, point_size=100) self.temp_block = pi3d.TextBlock(0, 0, 0.1, 0.0, 6, justify=0.5, text_format="0°", size=0.79, spacing="F", space=0.02, colour=(1.0, 1.0, 1.0, 1.0)) self.actval.add_text_block(self.temp_block) self.dot2 = pi3d.Disk(radius=20, sides=20, z=0.1, rx=90, camera=camera) self.dot2.set_shader(shader) self.dot2.set_material((1, 1, 1)) self.dot2_alpha = 1.0 self.value = 25.0 self.sensorvalue = 18.0 degree = (self.angle_fr + (self.angle_to - self.angle_fr) * (self.value - self.min_t) / (self.max_t - self.min_t)) self.x1 = self.mid * sin(radians(degree)) self.y1 = self.mid * cos(radians(degree))
def __init__(self, angle_fr=-140, angle_to=140, step=8, x=0, y=0, outer=250, inner=180, min_v=15, max_v=30, text_format="{:4.1f}°", set_field="set_temp", act_field="act_temp", shader=None, camera=None): self.angle_fr = angle_fr self.angle_to = ((angle_to - angle_fr) // step + 1) * step + angle_fr self.step = step self.outer = outer self.inner = inner self.mid = (outer + inner) / 2 self.min_v = min_v self.max_v = max_v self.x = x self.y = y self.set_field = set_field self.act_field = act_field self.text_format = text_format tick_verts = [] dial_verts = [] # first make tick vertices for x2 in range(self.angle_fr, self.angle_to, self.step): (s, c) = (sin(radians(x2)), cos(radians(x2)) ) # re-use for brevity below tick_verts.extend([(self.inner * s, self.inner * c, 0.1), (self.outer * s, self.outer * c, 0.1)]) dial_verts.append((self.mid * s, self.mid * c, 2.0)) tex = pi3d.Texture( resource_filename("shpi", "sprites/color_gradient.jpg")) self.ticks = pi3d.PolygonLines(camera=graphics.CAMERA, x=self.x, y=self.y, vertices=tick_verts, strip=False, line_width=8) self.ticks.set_shader(graphics.MATSH) self.ticks.set_alpha(0.8) self.sensorticks = pi3d.PolygonLines(camera=graphics.CAMERA, x=self.x, y=self.y, vertices=tick_verts, line_width=8, strip=False) self.sensorticks.set_shader(graphics.MATSH) self.bline = pi3d.PolygonLines(camera=graphics.CAMERA, x=self.x, y=self.y, vertices=dial_verts, line_width=80) self.bline.set_textures([tex]) self.bline.set_alpha(0.8) self.bline.set_shader(graphics.SHADER) self.bline.set_material((0.5, 0.5, 0.5)) self.trian = pi3d.Triangle(camera=graphics.CAMERA, x=self.x, y=self.y, z=0.1, corners=((-15, self.inner - 20, 0), (0, self.inner + 5, 0), (15, self.inner - 20, 0))) self.trian.set_shader(graphics.MATSH) self.trian.set_material((0.3, 0.1, 0)) self.trian.set_alpha(1) self.dial = pi3d.PolygonLines(camera=graphics.CAMERA, x=self.x, y=self.y, vertices=dial_verts, line_width=84) self.dial.set_alpha(0.2) self.dial.set_shader(graphics.MATSH) self.dial.set_material((0, 0, 0)) self.actval = pi3d.PointText(graphics.pointFont, graphics.CAMERA, max_chars=23, point_size=100) self.val_block = pi3d.TextBlock(self.x, self.y + 10, 0.1, 0.0, 11, justify=0.6, text_format=text_format, size=0.99, spacing="F", space=0.02, colour=(1.0, 1.0, 1.0, 1.0)) self.actval.add_text_block(self.val_block) self.value = getattr(peripherals.eg_object, self.set_field) self.sensorvalue = getattr(peripherals.eg_object, self.act_field) self.set_block = pi3d.TextBlock(0, self.inner - 30, 0.1, 0, 11, text_format=self.text_format.format( self.value), size=0.35, spacing="F", space=0.02, colour=(1.0, 1.0, 1.0, 1), justify=0.6) self.actval.add_text_block(self.set_block) self.dot1 = pi3d.Disk(radius=130, sides=30, x=self.x, y=self.y, z=2, rx=90, camera=graphics.CAMERA) self.dot1.set_shader(graphics.MATSH) self.dot1.set_material((0, 0, 0)) self.dot1.set_alpha(0.4) self.dot2 = pi3d.Disk(radius=30, sides=20, x=self.x, y=self.y, z=0.1, rx=90, camera=graphics.CAMERA) self.dot2.set_shader(graphics.MATSH) self.dot2.set_material((1, 1, 1)) self.dot2_alpha = 1.0 self.degree = (self.angle_fr + (self.angle_to - self.angle_fr) * (self.value - self.min_v) / (self.max_v - self.min_v)) self.trian.rotateToZ(-self.degree + self.step) if self.sensorvalue < self.min_v: self.sensorvalue = self.min_v if self.sensorvalue > self.max_v: self.sensorvalue = self.max_v self.sensordegree = (self.angle_fr + (self.angle_to - self.angle_fr) * (self.sensorvalue - self.min_v) / (self.max_v - self.min_v)) self.x1 = self.mid * sin(radians(self.degree)) + self.x self.y1 = self.mid * cos(radians(self.degree)) + self.y self.changed = 0 self.dot2.position(self.x1, self.y1, 0.5) self.dot2_alpha = 1.0 self.set_block.set_position( x=(self.inner - 33) * sin(radians(self.degree - self.step)) + self.x, y=(self.inner - 33) * cos(radians(self.degree - self.step)) + self.y, rot=-self.degree + self.step)