def draw_triangle(x, y, size, num_remaining): if num_remaining > 0: canvas.set_fill_color(*shade_of(random.choice(palette.colors))) canvas.set_stroke_color(*shade_of(random.choice(palette.colors))) canvas.set_line_width(random.random() * 0.5 + 0.5) step = math.sqrt(size**2 - (size / 2.0)**2) canvas.move_to(x - step, y - (size / 2.0)) canvas.add_line(x, y + size) canvas.add_line(x + step, y - (size / 2.0)) canvas.add_line(x - step, y - (size / 2.0)) canvas.fill_path() canvas.draw_line(x - step, y - (size / 2.0), x, y + size) canvas.draw_line(x, y + size, x + step, y - (size / 2.0)) canvas.draw_line(x + step, y - (size / 2.0), x - step, y - (size / 2.0)) canvas.draw_line(x, y, x - (step / 2.0), y + (size / 4.0)) canvas.draw_line(x, y, x + (step / 2.0), y + (size / 4.0)) canvas.draw_line(x, y, x, y - (size / 2.0)) canvas.draw_line(x - (step / 2.0), y + (size / 4.0), x + (step / 2.0), y + (size / 4.0)) canvas.draw_line(x + (step / 2.0), y + (size / 4.0), x, y - (size / 2.0)) canvas.draw_line(x, y - (size / 2.0), x - (step / 2.0), y + (size / 4.0)) draw_triangle(random.random() * width, random.random() * height, random.random() * triangle_side, num_remaining - 1)
def show_moon(mr, mg, mb): canvas.save_gstate() canvas.set_fill_color(mr, mg, mb) rad = moonrad * inz.radscale diam = 2.0 * rad canvas.fill_ellipse(moonx - rad, moony - rad, diam, diam) canvas.restore_gstate()
def hexacircle(start_x, start_y): r, g, b = random.choice(palette) canvas.set_fill_color(r, g, b, random.random() * 0.75 + 0.25) canvas.set_stroke_color(1.0, 1.0, 1.0, random.random() * 0.50 + 0.50) canvas.set_line_width(random.random() * 0.75 + 0.25) circle = (start_x - (0.5 * circle_size), start_y - (0.5 * circle_size), circle_size, circle_size) canvas.draw_ellipse(*circle) canvas.fill_ellipse(*circle) # draw lines rstrokedline(start_x, start_y - circle_size, start_x, start_y + circle_size) rstrokedline(start_x - step, start_y, start_x + step, start_y) rstrokedline(start_x - step, start_y - (0.5 * circle_size), start_x + step, start_y + (0.5 * circle_size)) rstrokedline(start_x - step, start_y + (0.5 * circle_size), start_x + step, start_y - (0.5 * circle_size)) rstrokedline(start_x - step, start_y + (1.5 * circle_size), start_x + step, start_y - (1.5 * circle_size)) rstrokedline(start_x - step, start_y - (1.5 * circle_size), start_x + step, start_y + (1.5 * circle_size)) rstrokedline(start_x - step, start_y + (2.5 * circle_size), start_x + step, start_y - (2.5 * circle_size)) rstrokedline(start_x - step, start_y - (2.5 * circle_size), start_x + step, start_y + (2.5 * circle_size)) rstrokedline(start_x - (3.0 * step), start_y + (0.5 * circle_size), start_x + (3.0 * step), start_y - (0.5 * circle_size)) rstrokedline(start_x - (3.0 * step), start_y - (0.5 * circle_size), start_x + (3.0 * step), start_y + (0.5 * circle_size))
def show_earth(er, eg, eb): canvas.save_gstate() canvas.set_fill_color(er, eg, eb) rad = earthrad * inz.radscale diam = 2.0 * rad canvas.fill_ellipse(earthx - rad, earthy - rad, diam, diam) canvas.restore_gstate()
def draw_heart(outline = False): first = True for t in xrange(int(2*pi * detail)): t = t * detail # heart equation x = 16*(sin(t) ** 3) y = 13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t) # scale result x = origin + x * scale y = origin + y * scale + scale*2 # hide first line if first: canvas.move_to(x, y) first = False else: canvas.add_line(x, y) # set color canvas.set_fill_color(1,0.5,0.5) canvas.set_stroke_color(0.5,0,0) canvas.set_line_width(detail/2) # draw heart if outline: canvas.draw_path() else: canvas.close_path() canvas.fill_path()
def hide_old_moon(): canvas.save_gstate() canvas.set_fill_color(0, 0, 0) # paint it as black as outer space rad = moonrad * inz.radscale diam = 2.0 * rad canvas.fill_ellipse(oldmx - rad, oldmy - rad, diam, diam) canvas.restore_gstate()
def plot_spectra(self): # calculate scale and axis label steps: scale_x = (688.0 - 2 * self.x_offset) / (self.x_max - self.x_min) scale_y = (688.0 - 2 * self.y_offset) / (self.y_max - self.y_min) step_x = scale_x * (self.x_max - self.x_min) / 10 step_y = scale_y * (self.y_max - self.y_min) / 10 # Draw x and y axix: canvas.set_stroke_color(0, 0, 0) # x-axis canvas.draw_line(self.x_offset, self.y_offset, 688, self.y_offset) # y-axis canvas.draw_line(self.x_offset, self.y_offset, self.x_offset, 688) # label and mark the axes.. for i in range(11): canvas.set_fill_color(0, 0, 0) # x-axis... label = self.x_axis_format.format(self.x_min + i * (self.x_max - self.x_min) / 10) canvas.draw_text(label, self.x_offset + step_x * i, 0, font_name='Helvetica', font_size=16) canvas.draw_line(self.x_offset + step_x * i, self.y_offset - 5, self.x_offset + step_x * i, self.y_offset) # y-axis... label = self.y_axis_format.format(self.y_min + i * (self.y_max - self.y_min) / 10) canvas.draw_text(label, 0, self.y_offset + step_y * i, font_name='Helvetica', font_size=16) canvas.draw_line(self.x_offset - 5, self.y_offset + step_y * i, self.x_offset, self.y_offset + step_y * i) # draw each dataset... for j in range(len(self.x_set)): temp_x = [] temp_y = [] temp_colour = [] temp_x = self.x_set[j] temp_y = self.y_set[j] canvas.set_stroke_color(*self.spectrum_colour[j]) canvas.set_line_width(2) canvas.move_to(self.x_offset + scale_x * (temp_x[0] - self.x_min), self.y_offset + scale_y * (temp_y[0] - self.y_min)) for i in range(len(temp_x)): draw_x = self.x_offset + scale_x * (temp_x[i] - self.x_min) draw_y = self.y_offset + scale_y * (temp_y[i] - self.y_min) if (self.style[j] == '-'): canvas.add_line(draw_x, draw_y) if (self.style[j] == 'o'): canvas.add_ellipse(draw_x - 3, draw_y - 3, 6, 6) canvas.draw_path()
def draw_tree(x, y, trunk_thickness, leaf_h, tree_w, trunk_h): canvas.begin_path() canvas.move_to(x - tree_w / 2, y + trunk_h) canvas.add_line(x + tree_w / 2, y + trunk_h) canvas.add_line(x, y + trunk_h + leaf_h) canvas.close_path() canvas.set_fill_color(0.25, 0.50, 0.00) canvas.fill_path() canvas.set_stroke_color(0.50, 0.25, 0.00) canvas.set_line_width(trunk_thickness) canvas.draw_line(x, y + trunk_h, x, y)
def show_render(image): canvas.set_aa_enabled(False) canvas.set_size(image.width, image.height) for y, pixel in enumerate(image.pixels): for x, pixel in enumerate(image.pixels[y]): try: canvas.set_fill_color(pixel.x, pixel.y, pixel.z) canvas.fill_rect(x, y, 1, 1) except: pass
def drawMinorTickmarks(): for i in range(60): canvas.save_gstate() canvas.translate(centerX, centerY) canvas.rotate(-2 * pi / 60.0 * i) canvas.set_fill_color(0.4, 0.4, 0.4, 0.6) width = 1 height = 5 canvas.set_line_width(1) canvas.draw_rect(-width/2, clockWidth * 0.505, width, height) canvas.restore_gstate()
def drawMajorTickmarks2(): for i in range(12): canvas.save_gstate() canvas.set_fill_color(0.3, 0.3, 0.3, 0.6) width = height = 5 angle = -2 * pi / 12.0 * (i - 3) length = clockWidth * 0.52 rads = radians(angle) x = int(cos(angle) * length) + centerX y = int(sin(angle) * length) + centerY canvas.draw_rect(x - width/2, y - height/2, width, height) canvas.restore_gstate()
def drawNumbers2(): for i in range(12): canvas.save_gstate() canvas.translate(centerX, centerY) canvas.rotate(-2 * pi / 12.0 * i) canvas.set_fill_color(0.3, 0.3, 0.3, 0.6) fontSize = 30 fontName = 'Helvetica-Bold' number = str(12 if i == 0 else i) width, height = canvas.get_text_size(number, fontName, fontSize) canvas.draw_text(number, -width/2, 115, fontName, fontSize) canvas.restore_gstate()
def main(): import canvas canvas.set_size(1000,1000) x=0 y=0 colors=distinct_colors(1,[(0,0,0),(1,1,1)]) for c in colors: canvas.set_fill_color(*c) canvas.fill_rect(x,y,50,50) x=x+60 if x>900: x=0 y=y+60
def drawNumbers(): for i in range(12): canvas.save_gstate() canvas.set_fill_color(0.3, 0.3, 0.3, 0.6) fontSize = 30 fontName = 'Helvetica-Bold' number = str(12 if i == 0 else i) width, height = canvas.get_text_size(number, fontName, fontSize) hour = i angle = -2 * pi / 12.0 * (hour - 3) length = clockWidth * 0.43 rads = radians(angle) x = int(cos(angle) * length) + centerX y = int(sin(angle) * length) + centerY canvas.draw_text(number, x - width/2, y - height/2, fontName, fontSize) canvas.restore_gstate()
def fill_triangles(x, y, size, theme): # fill upper triangle canvas.set_fill_color(*shade_of(random.choice(theme.colors))) canvas.begin_path() canvas.move_to(x, y) canvas.add_line(x, y + size) canvas.add_line(x + size, y + size) canvas.add_line(x, y) canvas.fill_path() # fill lower triangle canvas.set_fill_color(*shade_of(random.choice(theme.colors))) canvas.begin_path() canvas.move_to(x, y) canvas.add_line(x + size, y + size) canvas.add_line(x + size, y) canvas.add_line(x, y) canvas.fill_path()
def plot_function(func, color, min_x, max_x, min_y, max_y): #Calculate scale, set line width and color: w, h = canvas.get_size() origin_x, origin_y = w * 0.5, h * 0.5 scale_x = w / (max_x - min_x) scale_y = h / (max_y - min_y) canvas.set_stroke_color(*color) canvas.set_line_width(2) canvas.move_to(origin_x + scale_x * min_x, origin_y + func(min_x) * scale_y) #Draw the graph line: x = min_x while x <= max_x: x += 0.05 draw_x = origin_x + scale_x * x draw_y = origin_y + func(x) * scale_y canvas.add_line(draw_x, draw_y) canvas.set_fill_color(*color) canvas.draw_path()
def main(): console.alert('Motion Experiment 2', 'yo gang gang, we gonna measure this motion', 'Continue') motion.start_updates() sleep(0.2) print('Capturing motion data...') num_samples = 100 w = 512 h = 512 for nums in range(num_samples): canvas.set_size(w, h) sleep(0.05) current = motion.get_gravity() newMotion = [0,0,0] for i in range(len(current)): newMotion[i] = (current[i]*(10**3))//1 print(newMotion) canvas.set_fill_color(1, 0, 0) canvas.fill_ellipse(0, 0, newMotion[1], newMotion[2]) motion.stop_updates() print('Capture finished, plotting...')
def draw_heart(scale = 18): # 18 = full canvas #print(scale) # useful for debugging first_time = True (xorigin, yorigin) = canvas.get_size() xorigin *= 0.5 # in the center yorigin *= 0.588 # north of center detail = 100 canvas.begin_path() for t in range(int(2 * math.pi * detail)): t *= detail x = scale * (16 * math.sin(t) ** 3) y = scale * (13 * math.cos(t) - 5*math.cos(2*t) - 2*math.cos(3*t) - math.cos(4 * t)) if first_time: # hide the seams canvas.move_to(x + xorigin, y + yorigin) first_time = False canvas.add_line(x + xorigin, y + yorigin) canvas.set_line_width(1) canvas.close_path() canvas.draw_path() # try commenting out this line... canvas.set_fill_color(1, 0, 0) canvas.fill_path() # how do I fill just the inner part?
def draw_triangle(x, y, size, num_remaining): r, g, b = random.choice(palette) canvas.set_fill_color(r, g, b, random.random() * 0.75 + 0.25) r, g, b = random.choice(palette) canvas.set_stroke_color(r, g, b, random.random() * 0.5 + 0.5) canvas.set_line_width(random.random() * 2.5 + 0.5) step = math.sqrt(size**2 - (size / 2.0)**2) canvas.move_to(x - step, y - (size / 2.0)) canvas.add_line(x, y + size) canvas.add_line(x + step, y - (size / 2.0)) canvas.add_line(x - step, y - (size / 2.0)) canvas.fill_path() canvas.draw_line(x - step, y - (size / 2.0), x, y + size) canvas.draw_line(x, y + size, x + step, y - (size / 2.0)) canvas.draw_line(x + step, y - (size / 2.0), x - step, y - (size / 2.0)) canvas.draw_line(x, y, x - (step / 2.0), y + (size / 4.0)) canvas.draw_line(x, y, x + (step / 2.0), y + (size / 4.0)) canvas.draw_line(x, y, x, y - (size / 2.0)) canvas.draw_line(x - (step / 2.0), y + (size / 4.0), x + (step / 2.0), y + (size / 4.0)) canvas.draw_line(x + (step / 2.0), y + (size / 4.0), x, y - (size / 2.0)) canvas.draw_line(x, y - (size / 2.0), x - (step / 2.0), y + (size / 4.0))
def draw_heart(scale = 18): # 18 = full canvas #print(scale) # useful for debugging first_time = True (xorigin, yorigin) = canvas.get_size() xorigin *= 0.5 # in the center yorigin *= 0.588 # north of center detail = 100 canvas.begin_path() for t in xrange(int(2 * math.pi * detail)): t *= detail x = scale * (16 * math.sin(t) ** 3) y = scale * (13 * math.cos(t) - 5*math.cos(2*t) - 2*math.cos(3*t) - math.cos(4 * t)) if first_time: # hide the seams canvas.move_to(x + xorigin, y + yorigin) first_time = False canvas.add_line(x + xorigin, y + yorigin) canvas.set_line_width(1) canvas.close_path() canvas.draw_path() # try commenting out this line... canvas.set_fill_color(1, 0, 0) canvas.fill_path() # how do I fill just the inner part?
def main(): console.alert('Motion Experiment 2', 'yo gang gang, we gonna measure this motion', 'Continue') motion.start_updates() sleep(0.2) print('Capturing motion data...') w = 1000 h = 1200 goalX = w / 2 goalY = h / 2 moalX = w / 2 - 100 moalY = h / 2 - 100 while True: sleep(0.01) current = motion.get_gravity() newMotion = [0, 0, 0] for i in range(len(current)): newMotion[i] = (current[i] * (10**2)) // 1 #print(newMotion) x = newMotion[0] + 100 y = newMotion[1] + 100 z = newMotion[2] + 100 goalX += (x - 100) goalY += (y - 100) moalX += (x - 102) * 2 moalY += (y - 102) * 2 if goalX <= 0 or goalY <= 0 or goalX >= w or goalY >= h: goalX -= (x - 100) goalY -= (y - 100) if moalX <= 0 or moalY <= 0 or moalX >= w or moalY >= h: moalX -= (x - 102) * 2 moalY -= (y - 102) * 2 canvas.set_size(w, h) canvas.set_fill_color(0, 0, 0) canvas.fill_ellipse(goalX, goalY, 30, 30) canvas.set_fill_color(0, 0, 1) canvas.fill_ellipse(moalX, moalY, 30, 30) motion.stop_updates() print('Capture finished, plotting...')
def main(): console.alert('Motion Experiment 2', 'yo gang gang, we gonna measure this motion', 'Continue') motion.start_updates() sleep(0.2) print('Capturing motion data...') w = 512 h = 512 while True: sleep(0.1) current = motion.get_gravity() newMotion = [0, 0, 0] for i in range(len(current)): newMotion[i] = (current[i] * (10**3)) // 1 #print(newMotion) if newMotion[0] < 1001 and newMotion[0] > 900 and newMotion[ 1] > -50 and newMotion[1] < 50 and newMotion[ 2] > -50 and newMotion[2] < 50: canvas.set_size(w, h) canvas.set_fill_color(1, 0, 0) canvas.fill_ellipse(0, 0, w, h) if newMotion[0] > -1001 and newMotion[0] < -900 and newMotion[ 1] > -50 and newMotion[1] < 50 and newMotion[ 2] > -50 and newMotion[2] < 50: canvas.set_size(w, h) canvas.set_fill_color(0, 1, 0) canvas.fill_ellipse(0, 0, w, h) if newMotion[0] > -50 and newMotion[0] < 50 and newMotion[ 1] > -50 and newMotion[1] < 50 and newMotion[ 2] > -1001 and newMotion[2] < -900: canvas.set_size(w, h) canvas.set_fill_color(0, 0, 1) canvas.fill_ellipse(0, 0, w, h) motion.stop_updates() print('Capture finished, plotting...')
def main(): console.alert('Motion Experiment 2', 'yo gang gang, we gonna measure this motion', 'Continue') motion.start_updates() sleep(0.2) print('Capturing motion data...') w = 1000 h = 1200 while True: sleep(0.01) current = motion.get_gravity() newMotion = [0,0,0] for i in range(len(current)): newMotion[i] = (current[i]*(10**3))//1 #print(newMotion) x = newMotion[0]+500 y = newMotion[1]+500 z = newMotion[2]+1000 goalX = w/2 goalY = h/2 canvas.set_size(w, h) canvas.set_fill_color(0, 0, 0) canvas.fill_ellipse(goalX, goalY, 30, 30) if (abs(goalX-x) < 10 and abs(goalY-y) < 10): canvas.set_fill_color(0, 1, 0) canvas.fill_ellipse(x, y, 30, 30) else: canvas.set_fill_color(1, 0, 0) canvas.fill_ellipse(x, y, 30, 30) motion.stop_updates() print('Capture finished, plotting...')
def drawClockBackground(): canvas.set_fill_color(0.8, 0.6, 0.1) canvas.fill_ellipse(clockX - border, clockY - border, clockWidth + border*2, clockHeight + border*2) canvas.set_fill_color(1.0, 0.8, 0.3) canvas.fill_ellipse(clockX, clockY, clockWidth, clockHeight) canvas.set_fill_color(0.0, 0.0, 0.0) canvas.fill_ellipse(centerX - 5, centerY - 5, 10, 10)
def render(self, scene, samples): width = scene.width height = scene.height canvas.set_size(width, height) aspect_ratio = float(width) / height x0 = -1.0 x1 = +1.0 xstep = (x1 - x0) / (width - 1) y0 = -1.0 / aspect_ratio y1 = +1.0 / aspect_ratio ystep = (y1 - y0) / (height - 1) camera = scene.camera pixels = Image(width, height) heightRange = list(range(height)) widthRange = list(range(width)) #random.shuffle(heightRange) #random.shuffle(widthRange) for j in heightRange: y = y0 + j * ystep for i in widthRange: x = x0 + i * xstep renderedSamples = [] for _ in range(samples): if samples > 1: ray = Ray(camera, Point(x+random.uniform(xstep*-1,xstep),y+random.uniform(xstep*-1,ystep)) - camera) else: ray = Ray(camera, Point(x,y) - camera) raytracedColorSample = self.ray_trace(ray, scene) renderedSamples.append(raytracedColorSample) finalPixel = sum(renderedSamples, Color(0,0,0)) / len(renderedSamples) pixels.set_pixel(i, j, finalPixel) canvas.set_fill_color(finalPixel.x, finalPixel.y, finalPixel.z) canvas.fill_rect(i, j, 1, 1) return pixels
def plot_function(t_, color, min_x,max_x,min_y,max_y): #Calculate scale, set line width and color: w, h = canvas.get_size() scale_x = w / (max_x - min_x) scale_y = h / (max_y - min_y) scale_x = min(scale_x,scale_y) scale_y=scale_x origin_x, origin_y = -scale_x*min_x,-scale_y*min_y canvas.set_stroke_color(*color) canvas.set_line_width(2) #Draw the graph line: x = t_[0][0] y = t_[0][1] canvas.move_to(origin_x + scale_x * x, origin_y + scale_y * y) for p in t_[1:]: x=p[0] y=p[1] draw_x = origin_x + scale_x * x draw_y = origin_y + scale_y * y canvas.add_line(*(draw_x, draw_y)) canvas.set_fill_color(*color) canvas.draw_path()
# https://gist.github.com/omz/5087533 import canvas canvas.set_size(512, 512) from_point = (10, 10) cp1 = (40, 200) #control point 1 cp2 = (350, 50) #control point 2 to_point = (300, 300) # Draw the actual curve: canvas.begin_path() canvas.move_to(from_point[0], from_point[1]) canvas.add_curve(cp1[0], cp1[1], cp2[0], cp2[1], to_point[0], to_point[1]) canvas.set_line_width(2) canvas.draw_path() # Draw the red dots and lines to illustrate what's happening: canvas.set_stroke_color(1, 0, 0) canvas.set_fill_color(1, 0, 0) # Draw straight lines between the control points and the end points: canvas.draw_line(from_point[0], from_point[1], cp1[0], cp1[1]) canvas.draw_line(to_point[0], to_point[1], cp2[0], cp2[1]) # Draw red squares on all the points: canvas.fill_rect(from_point[0]-4, from_point[1]-4, 8, 8) canvas.fill_rect(to_point[0]-4, to_point[1]-4, 8, 8) canvas.fill_rect(cp1[0]-4, cp1[1]-4, 8, 8) canvas.fill_rect(cp2[0]-4, cp2[1]-4, 8, 8)
from urbanape import common_devices from kuler import * random.seed() width, height = common_devices['ipad_r'] circle_size = 192.0 step = math.sqrt(circle_size**2 - (circle_size / 2.0)**2) palette = let_the_rays_fall_on_the_earth canvas.begin_updates() canvas.set_size(width, height) canvas.set_fill_color(*random.choice(palette)) canvas.fill_rect(0, 0, width, height) for x in range(100): r, g, b = random.choice(palette) a = random.random() * 0.5 + 0.25 canvas.set_fill_color(r, g, b, a) origin_x = random.random() * width origin_y = random.random() * height csize = random.random() * (width / 8.0) + (width / 16.0) canvas.fill_ellipse(origin_x, origin_y, csize, csize) def rstrokedline(start_x, start_y, end_x, end_y): line_width = random.random() * 0.75 + 0.25 canvas.set_line_width(line_width)
#Draw a red circle filling the entire canvas import canvas w = h = 512 canvas.set_size(w, h) canvas.set_fill_color(1, 0, 0) canvas.fill_ellipse(0, 0, w/2, h/2)
import canvas import random from math import pi w = h = 500 canvas.set_size(w, h) canvas.set_aa_enabled(True) canvas.set_fill_color(0.4, 0, 0) canvas.fill_ellipse(0, 0, w, h) canvas.set_fill_color(0.8, 0, 0) canvas.fill_ellipse(20, 20, w - 40, h - 40) #canvas.draw_text("Computer Generated Art", 65, 440, font_size=33) originX = w / 2 originY = h / 2 for i in range(1, 300, 5): x1 = originX y1 = originY x2 = 100 + i y2 = 0 canvas.draw_line(x1, y1, x2, y2) for i in range(1, 500, 5): x1 = originX y1 = originY x2 = i y2 = canvas.get_size()[0] canvas.draw_line(x1, y1, x2, y2)
import random import math from devices import * from kuler import * random.seed() width, height = iphone_5_ios7 triangle_side = 256.0 palette = random.choice(themes) canvas.begin_updates() canvas.set_size(width, height) canvas.set_fill_color(*palette.darkest) canvas.fill_rect(0, 0, width, height) def draw_triangle(x, y, size, num_remaining): if num_remaining > 0: canvas.set_fill_color(*shade_of(random.choice(palette.colors))) canvas.set_stroke_color(*shade_of(random.choice(palette.colors))) canvas.set_line_width(random.random() * 0.5 + 0.5) step = math.sqrt(size**2 - (size / 2.0)**2) canvas.move_to(x - step, y - (size / 2.0)) canvas.add_line(x, y + size) canvas.add_line(x + step, y - (size / 2.0)) canvas.add_line(x - step, y - (size / 2.0)) canvas.fill_path() canvas.draw_line(x - step, y - (size / 2.0), x, y + size)
# https://forum.omz-software.com/topic/3238/the-color-of-the-text-that-is-drawn-with-draw_text import canvas canvas.set_size(600, 600) canvas.set_fill_color(1, 0, 0) #red text = 'OK' x = 0 y = 400 font_family = 'Helvetica-Bold' font_size = 40 canvas.draw_text(text, x, y, font_family, font_size)
def coloredCircle(inColor, inX, inY): canvas.set_fill_color(*inColor) canvas.fill_ellipse(inX, inY, circleHeight, circleHeight)
import canvas import random import math from urbanape import common_devices from kuler import * random.seed() width, height = common_devices['ipad_r'] palette = robots_are_cool canvas.begin_updates() canvas.set_size(width, height) canvas.set_fill_color(*palette['darkest']) canvas.fill_rect(0, 0, width, height) canvas.set_fill_color(*random.choice(palette['palette'])) canvas.set_stroke_color(*palette['lightest']) start_x, start_y = (width / 2.0, height / 2.0) lollipop_points = [] for x in xrange(64): end_x, end_y = (random.random() * (width * 0.8) + (width * 0.1), random.random() * (height * 0.8) + (height * 0.1)) lollipop_points.append((end_x, end_y)) canvas.set_line_width(random.random() * 0.75 + 0.25) canvas.draw_line(start_x, start_y, end_x, end_y) for x in xrange(64):
def fill_square(x, y, size, theme): canvas.set_fill_color(*shade_of(random.choice(theme.colors))) canvas.draw_rect(x, y, x + size, y + size)
from devices import * from kuler import * random.seed() width, height = cinema circle_size = 256.0 step = math.sqrt(circle_size**2 - (circle_size / 2.0)**2) palette = random.choice(themes) canvas.begin_updates() canvas.set_size(width, height) canvas.set_fill_color(*palette.darkest) canvas.fill_rect(0, 0, width, height) for x in range(100): r, g, b = random.choice(palette.colors) a = random.random() * 0.5 + 0.25 canvas.set_fill_color(r, g, b, a) origin_x = random.random() * width origin_y = random.random() * height csize = random.random() * (width / 8.0) + (width / 16.0) canvas.fill_ellipse(origin_x, origin_y, csize, csize) def rstrokedline(start_x, start_y, end_x, end_y): line_width = random.random() * 0.25 + 0.25 canvas.set_line_width(line_width) r, g, b = palette.lightest
from urbanape import common_devices from kuler import * random.seed() width, height = common_devices['ipad_r'] circle_size = 192.0 step = math.sqrt(circle_size**2 - (circle_size / 2.0)**2) palette = let_the_rays_fall_on_the_earth canvas.begin_updates() canvas.set_size(width, height) canvas.set_fill_color(*random.choice(palette)) canvas.fill_rect(0, 0, width, height) for x in range(100): r, g, b = random.choice(palette) a = random.random() * 0.5 + 0.25 canvas.set_fill_color(r, g, b, a) origin_x = random.random() * width origin_y = random.random() * height csize = random.random() * (width / 8.0) + (width / 16.0) canvas.fill_ellipse(origin_x, origin_y, csize, csize) def rstrokedline(start_x, start_y, end_x, end_y): line_width = random.random() * 0.75 + 0.25 canvas.set_line_width(line_width) a = random.random() * 0.25 + 0.05
import canvas import random import math from urbanape import common_devices from kuler import * random.seed() width, height = common_devices['ipad_r'] palette = robots_are_cool canvas.begin_updates() canvas.set_size(width, height) canvas.set_fill_color(*palette.darkest) canvas.fill_rect(0, 0, width, height) canvas.set_fill_color(*random.choice(palette)) canvas.set_stroke_color(*palette.lightest) start_x, start_y = (width / 2.0, height / 2.0) lollipop_points = [] for x in xrange(64): end_x, end_y = (random.random() * (width * 0.8) + (width * 0.1), random.random() * (height * 0.8) + (height * 0.1)) lollipop_points.append((end_x, end_y)) canvas.set_line_width(random.random() * 0.75 + 0.25) canvas.draw_line(start_x, start_y, end_x, end_y) for x in xrange(64):
import math from urbanape import common_devices from kuler import * random.seed() width, height = common_devices['ipad_r'] triangle_side = 1024.0 palette = robots_are_cool canvas.begin_updates() canvas.set_size(width, height) #canvas.set_fill_color(*random.choice(palette)) canvas.set_fill_color(.25, .25, .25) canvas.fill_rect(0, 0, width, height) def draw_triangle(x, y, size, num_remaining): r, g, b = random.choice(palette) canvas.set_fill_color(r, g, b, random.random() * 0.75 + 0.25) r, g, b = random.choice(palette) canvas.set_stroke_color(r, g, b, random.random() * 0.5 + 0.5) canvas.set_line_width(random.random() * 2.5 + 0.5) step = math.sqrt(size**2 - (size / 2.0)**2) canvas.move_to(x - step, y - (size / 2.0)) canvas.add_line(x, y + size) canvas.add_line(x + step, y - (size / 2.0)) canvas.add_line(x - step, y - (size / 2.0)) canvas.fill_path() canvas.draw_line(x - step, y - (size / 2.0), x, y + size)