def draw_big(x: int, y: int, dwg: svgwrite.Drawing, weather: WeatherForecast, air_quality: AirQuality, icons_location: str): shapes = dwg.add(dwg.g(id='shapes')) shapes.add(dwg.rect(insert=(x, y), size=(360 * px, 300 * px), fill='white', stroke='black', stroke_width=1)) paragraph = dwg.add(dwg.g(font_size=120)) paragraph.add(dwg.text(f"{weather.temperature}°", (x + 240, y + 110), text_anchor="middle")) location = os.path.abspath(f"{icons_location}/{weather.summary.value}.svg") image = dwg.add( dwg.image(href=location, insert=(x + 5, y + 5), size=(120 * px, 120 * px))) feels_like_text = dwg.add(dwg.g(font_size=36, font_family="Helvetica")) feels_like_text.add(dwg.text(f"Air quality: {air_quality}", (x + 10, y + 165))) wind_text = dwg.add(dwg.g(font_size=36, font_family="Helvetica")) wind_text.add(dwg.text(f"{weather.wind_name} {weather.wind_mps} m/s", (x + 10, y + 205), textLength=340)) precipitation_text = dwg.add(dwg.g(font_size=36, font_family="Helvetica")) precipitation_text.add(dwg.text(f"{weather.precip_name} {weather.precip_mm} mm/h", (x + 10, y + 245))) pressure_text = dwg.add(dwg.g(font_size=36, font_family="Helvetica")) pressure_text.add(dwg.text(f"{int(weather.air_pressure)} hPa", (x + 10, y + 285)))
def render(self, d: Drawing) -> Group: g = d.g() r = d.image(href=self.href) r["xlink:href"] = self.href r["width"] = "%dpx" % self.width r["height"] = "%dpx" % self.height g.add(r) return g
def render(self, d: Drawing) -> Group: g = d.g() href = "data:image/jpeg;base64,%s" % base64.b64encode( self.data).decode() r = d.image(href=href) r["xlink:href"] = href r["width"] = "%dpx" % self.width r["height"] = "%dpx" % self.height g.add(r) return g
def draw_small(x: int, y: int, dwg: svgwrite.Drawing, time: str, weather: WeatherForecast, icons_location: str): shapes = dwg.add(dwg.g()) shapes.add(dwg.rect(insert=(x, y), size=(220 * px, 145 * px), fill='white', stroke='black', stroke_width=1)) date_text = dwg.add(dwg.g(font_size=35, font_family="Helvetica")) date_text.add(dwg.text(time, (10 + x, 35 + y))) paragraph = dwg.add(dwg.g(font_size=55)) paragraph.add(dwg.text(f"{weather.temperature}°", (x + 135, y + 90), text_anchor="middle")) location = os.path.abspath(f"{icons_location}/{weather.summary.value}.svg") image = dwg.add( dwg.image(href=location, insert=(10 + x, 45 + y), size=(55 * px, 55 * px))) pressure_text = dwg.add(dwg.g(font_size=36, font_family="Helvetica")) pressure_text.add(dwg.text(f"{int(weather.air_pressure)} hPa", (10 + x, 130 + y)))
def render(self, dwg: Drawing) -> Group: width, height, scale, x_translate, y_translate = self.random_configuration() image_url = "/assets/%s" % self.img if self.local_paths: image_url = "file://%s" % os.path.join(ASSET_DIR, self.img) g = dwg.g() r = dwg.image(href=self.img) r["xlink:href"] = image_url r["width"] = "%dpx" % width r["height"] = "%dpx" % height r.scale(scale) r.translate(- x_translate, - y_translate) g.add(r) return g
def diode_svg_frame(illuminated, num_across=9, num_down=8, frame=0, single_route=-1): filename = "diode{:03d}.svg".format(frame) led_symbol = "resources/Symbol_LED.svg" image_width = 600 image_height = 400 right_margin = 30 bottom_margin = 30 dwg = Drawing(filename, size=(image_width+right_margin, image_height+bottom_margin), style="background-color:white") # create a white background rectangle dwg.add(dwg.rect(size=(image_width+right_margin, image_height+bottom_margin), insert=(0, 0), fill="white")) LED_dimensions = [106.0, 71.0] LED_points = [[35, 68], [35, 31], [66, 50]] LED_entries = [[4, 50], [103, 50]] aspect_ratio = LED_dimensions[1]/LED_dimensions[0] new_width = image_width/num_across new_height = new_width*aspect_ratio LED_scale = 0.75 LED_offsets = [new_width*LED_scale/2, new_height*LED_scale] junction_radius = 0.8 elements = [] for i in range(0, num_across): x_pos = new_width*(num_across-i-1) if illuminated[1] >= illuminated[0]: incoming_wire = illuminated[1] + 1 else: incoming_wire = illuminated[1] if i == incoming_wire: connection = "+" text_fill = "red" elif i == illuminated[0]: connection = "-" text_fill = "black" else: connection = "NC" text_fill = "gray" wire_label = "{} {}".format(i+1, connection) # the input wire title dwg.add(dwg.text(wire_label, insert=(x_pos+new_width-10, 10), fill=text_fill)) for j in range(0, num_down): y_pos = (image_height/num_down)*j position = [x_pos+LED_offsets[0], y_pos+LED_offsets[1]] scale = [LED_scale*new_width/LED_dimensions[0], LED_scale*new_height/LED_dimensions[1]] # the led svg dwg.add(dwg.image(led_symbol, insert=position, size=(new_width*LED_scale, new_height*LED_scale))) if i == illuminated[0] and j == illuminated[1] and single_route == -1: points = [] for point in LED_points: points.append(transform_point(point, scale, position)) # the illuminated svg box dwg.add(dwg.polygon(points=points, fill="yellow")) line_fill = "green" stroke_width = 1 insert_pos = -1 else: line_fill = "black" insert_pos = 0 stroke_width = 0.5 # for each LED, we want to generate a line going from the input # to its output entry_point = transform_point(LED_entries[0], scale, position) if i > j: incoming_line_points = [[new_width*(num_across-j)-LED_offsets[0], 0], [new_width*(num_across-j)-LED_offsets[0], y_pos+20], [entry_point[0], y_pos+20], entry_point] elif j > i: incoming_line_points = [ [new_width * (num_across - j - 1) - LED_offsets[0], 0], [new_width * (num_across - j - 1) - LED_offsets[0], entry_point[1] + LED_offsets[1]], [entry_point[0], entry_point[1]+LED_offsets[1]], entry_point] elif i == j: incoming_line_points = [ [new_width * (num_across - j - 1) - LED_offsets[0], 0], [new_width * (num_across - j - 1) - LED_offsets[0], entry_point[1]], entry_point] else: incoming_line_points = [] elements.insert(insert_pos, make_junction_line(dwg, incoming_line_points, junction_radius, line_fill, stroke_width)) # outgoing line exit_point = transform_point(LED_entries[1], scale, position) outgoing_line_points = [exit_point, [x_pos+new_width-LED_offsets[0], exit_point[1]], [x_pos+new_width-LED_offsets[0], 0]] elements.insert(insert_pos, make_junction_line(dwg, outgoing_line_points, junction_radius, line_fill, stroke_width)) route_points = [[new_width * (num_across - j - 1) - LED_offsets[0], 0]] for point in range(0, single_route+1): if point < i: route_points.append([new_width * (num_across - j - 1) - LED_offsets[0], 0]) # now create the network nodes = [] for i in range(0, num_across): for j in range(0, num_down): nodes.append(entry_point) nodes.append(exit_point) # flatten the elements structure elements = sum(elements, []) print(elements) # the lines should be drawn last so that they are layered on top of all # other elements #for element in elements: # dwg.add(element) dwg.save() return convert(image_width, filename)