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()
Beispiel #2
0
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 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()
Beispiel #5
0
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))
Beispiel #6
0
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...')
Beispiel #7
0
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...')
Beispiel #8
0
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...')
Beispiel #9
0
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...')
Beispiel #10
0
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)
Beispiel #11
0
def coloredCircle(inColor, inX, inY):
    canvas.set_fill_color(*inColor)
    canvas.fill_ellipse(inX, inY, circleHeight, circleHeight)
Beispiel #12
0
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):
	end_x, end_y = lollipop_points[x]
	size = random.random() * 128.0 + 32.0
	canvas.fill_ellipse(end_x - (size / 2.0), end_y - (size / 2.0), size, size)
	canvas.set_line_width(1.25)
	canvas.draw_ellipse(end_x - (size / 2.0), end_y - (size / 2.0), size, size)

size = random.random() * 128.0 + 32.0
canvas.fill_ellipse(start_x - (size / 2.0), start_y - (size / 2.0), size, size)
canvas.set_line_width(1.25)
canvas.draw_ellipse(start_x - (size / 2.0), start_y - (size / 2.0), size, size)

canvas.end_updates()
Beispiel #13
0
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
	canvas.set_stroke_color(1.0, 1.0, 1.0, a)
	canvas.draw_line(start_x, start_y, end_x, end_y)

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),
Beispiel #14
0
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.colors))
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)

size = random.random() * (width * 0.10)
canvas.fill_ellipse(start_x - (size / 2.0), start_y - (size / 2.0), size, size)
canvas.set_line_width(1.25)
canvas.draw_ellipse(start_x - (size / 2.0), start_y - (size / 2.0), size, size)

for x in xrange(64):
    end_x, end_y = lollipop_points[x]
    size = random.random() * (width * 0.10)
    canvas.fill_ellipse(end_x - (size / 2.0), end_y - (size / 2.0), size, size)
    canvas.set_line_width(1.25)
    canvas.draw_ellipse(end_x - (size / 2.0), end_y - (size / 2.0), size, size)

canvas.end_updates()
Beispiel #15
0
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
    canvas.set_stroke_color(1.0, 1.0, 1.0, a)
    canvas.draw_line(start_x, start_y, end_x, end_y)


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)
Beispiel #16
0
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)
Beispiel #17
0
import canvas
import random
from math import pi

w = h = 500
canvas.set_size(w, h)

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)

#gradient circles
r = 1.0
x = 50
y = 50
width = 400
height = 400
#canvas.translate(50, 50)
for i in range(30):
    canvas.set_fill_color(r, 0.0, 0.0, 0.5)
    canvas.fill_ellipse(x, y, width, height)
    r -= 0.03
    x += 5
    y += 5
    width -= 10
    height -= 10

#random dots
canvas.begin_updates()
for i in range(12):
Beispiel #18
0
# coding: utf-

# https://gist.github.com/jsbain/389a67c5aacb097b87fd

from __future__ import print_function
from objc_util import *
import canvas
import os


def save_canvas_to_png(filename):
    rootVC = UIApplication.sharedApplication().keyWindow().rootViewController()
    image = rootVC.accessoryViewController().consoleViewController(
    ).canvasImageView().image()
    if image:
        data = ObjCInstance(c.UIImagePNGRepresentation(image))
        data.writeToFile_atomically_(os.path.abspath(filename), True)
    else:
        print('canvas was empty')


if __name__ == '__main__':
    #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, h)
    save_canvas_to_png('canvas.png')
def add_ellipse(x, y, r, color):
    canvas.set_fill_color(*color)
    for alpha in range(256):
        canvas.set_alpha(alpha / 256)
        canvas.fill_ellipse(x, y, r * 2, r * 2)
Beispiel #20
0
#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)
def draw_circle(x, y, r):
	canvas.set_line_width(3)
	canvas.set_stroke_color(0, 0, 0)
	canvas.set_fill_color(255,255,255)
	canvas.fill_ellipse(x - r, y - r, 2 * r, 2 * r)
	canvas.draw_ellipse(x - r, y - r, 2 * r, 2 * r)
Beispiel #22
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)

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
    a = random.random() * 0.25 + 0.05
    canvas.set_stroke_color(r, g, b, a)
    canvas.draw_line(start_x, start_y, end_x, end_y)


def hexacircle(start_x, start_y):
    r, g, b = random.choice(palette.colors)

    canvas.set_fill_color(r, g, b, random.random() * 0.75 + 0.25)
Beispiel #23
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)

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
	a = random.random() * 0.25 + 0.05
	canvas.set_stroke_color(r, g, b, a)
	canvas.draw_line(start_x, start_y, end_x, end_y)

def hexacircle(start_x, start_y):
	r, g, b = random.choice(palette.colors)

	canvas.set_fill_color(r, g, b, random.random() * 0.75 + 0.25)
	s_r, s_g, s_b = palette.lightest
	canvas.set_stroke_color(s_r, s_g, s_b, random.random() * 0.50 + 0.50)