Esempio n. 1
0
	def run(self):
		while self.trace is None and not self.die:
			time.sleep(0.1)

		if self.die:
			return

		if ol.init(4) < 0:
			return
		print "OL Initialized"
		params = ol.RenderParams()
		params.render_flags = ol.RENDER_GRAYSCALE
		params.on_speed = 2/120.0
		params.off_speed = 2/30.0
		params.flatness = 0.000001
		params.max_framelen = 48000 / 25
		params.min_length = 30
		params.snap = 0.04
		ol.setRenderParams(params)
		ol.loadIdentity()
		ol.scale((2, -2))
		ol.translate((-0.5, -0.5))
		ol.scale((1/640.0, 1/640.0))
		ol.translate((0, (640-480)/2))

		while not self.die:
			#ol.rect((100, 100), (640-100, 480-100), ol.C_WHITE)
			objects = self.trace
			for o in objects:
				ol.begin(ol.POINTS)
				for point in o[::2]:
					ol.vertex(point, ol.C_WHITE)
				ol.end()
			ftime = ol.renderFrame(60)
		ol.shutdown()
Esempio n. 2
0
def play_ugo(size, frames, meta):
    frame_pts = []
    total_time = 0
    for frame_meta in meta['frames']:
        frame_pts.append(total_time)
        total_time += frame_meta['delay'] / 1000.0

    if ol.init(3) < 0:
        return

    width, height = size

    params = ol.RenderParams()
    params.render_flags = ol.RENDER_GRAYSCALE
    params.on_speed = 2 / 60.0
    params.off_speed = 2 / 30.0
    params.flatness = 0.000001
    params.max_framelen = 48000 / 25
    params.min_length = 30
    params.snap = 0.04
    ol.setRenderParams(params)
    ol.loadIdentity()
    ol.scale((2, -2))
    ol.translate((-0.5, -0.5))
    mw = float(max(width, height))
    print width, height, mw
    ol.scale((1 / mw, 1 / mw))
    ol.translate(((mw - width) / 2, (mw - height) / 2))

    frame = 0
    time = 0

    DECIMATE = 2

    while True:
        while time > total_time:
            time -= total_time
            frame = 0

        while (frame + 1) < len(frames) and frame_pts[frame + 1] < time:
            frame += 1

        print "t=%.02f frame=%d" % (time, frame)

        objects = frames[frame]
        points = 0
        for o in objects:
            ol.begin(ol.POINTS)
            for point in o[::DECIMATE]:
                ol.vertex(point, ol.C_WHITE)
                points += 1
            ol.end()
        print "%d objects, %d points" % (len(objects), points)
        time += ol.renderFrame(60)

    ol.shutdown()
Esempio n. 3
0
def play_ugo(size, frames, meta):
    frame_pts = []
    total_time = 0
    for frame_meta in meta['frames']:
        frame_pts.append(total_time)
        total_time += frame_meta['delay'] / 1000.0

    if ol.init(3) < 0:
        return

    width, height = size

    params = ol.RenderParams()
    params.render_flags = ol.RENDER_GRAYSCALE
    params.on_speed = 2/60.0
    params.off_speed = 2/30.0
    params.flatness = 0.000001
    params.max_framelen = 48000 / 25
    params.min_length = 30
    params.snap = 0.04
    ol.setRenderParams(params)
    ol.loadIdentity()
    ol.scale((2, -2))
    ol.translate((-0.5, -0.5))
    mw = float(max(width, height))
    print width, height, mw
    ol.scale((1/mw, 1/mw))
    ol.translate(((mw-width)/2, (mw-height)/2))

    frame = 0
    time = 0

    DECIMATE = 2

    while True:
        while time > total_time:
            time -= total_time
            frame = 0

        while (frame+1) < len(frames) and frame_pts[frame+1] < time:
            frame += 1

        print "t=%.02f frame=%d" % (time, frame)

        objects = frames[frame]
        points = 0
        for o in objects:
            ol.begin(ol.POINTS)
            for point in o[::DECIMATE]:
                ol.vertex(point, ol.C_WHITE)
                points += 1
            ol.end()
        print "%d objects, %d points" % (len(objects), points)
        time += ol.renderFrame(60)

    ol.shutdown()
Esempio n. 4
0
            [pixel_on, PixelCoordToGalvoCoord(x, y, width, height)])
        scanning_on = False
    if len(scanline) > 0:
        scanlines.append(scanline)
    scanlines.append(scanline)

if options.preview:
    pygame.init()
    #create the screen
    window = pygame.display.set_mode((scaledWidth, scaledHeight))

print "Found ", len(scanlines), "non blank scan lines... scanning now..."
for l in scanlines:
    if options.laser:
        ol.loadIdentity()
        ol.scale((float(options.xscale), float(options.yscale)))
    for s in l:
        if options.preview:
            pygame.draw.line(
                window, (0, 255, 0),
                GalvoCoordToPixelCoord(s[0], scaledWidth, scaledHeight),
                GalvoCoordToPixelCoord(s[1], scaledWidth, scaledHeight))
        if options.laser:
            ol.line((s[0][0], s[0][1]), (s[1][0], s[1][1]), ol.C_WHITE)
    if options.preview:
        pygame.display.flip()
    if options.laser:
        ol.renderFrame(int(options.power))

print options.pngfile,
print " Height:",
Esempio n. 5
0
#!/usr/bin/python3
#         OpenLase - a realtime laser graphics toolkit
#
# Copyright (C) 2009-2011 Hector Martin "marcan" <*****@*****.**>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 or version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

import pylase as ol
from math import pi

ol.init()

while True:
    ol.loadIdentity()
    ol.scale((0.999, 0.999))
    ol.rect((-1, -1), (1, 1), ol.C_WHITE)
    ol.renderFrame(100)
Esempio n. 6
0
#         OpenLase - a realtime laser graphics toolkit
#
# Copyright (C) 2009-2011 Hector Martin "marcan" <*****@*****.**>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 or version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

import pylase as ol
from math import pi

ol.init()

while True:
	ol.loadIdentity()
	ol.scale((0.999, 0.999))
	ol.rect((-1,-1),(1,1),ol.C_WHITE)
	ol.renderFrame(100)
Esempio n. 7
0
import svg

image = svg.load_svg(sys.argv[1])

params = ol.RenderParams()
params.render_flags = 0
params.on_speed = 2/110.0
params.off_speed = 2/70.0
params.flatness = 0.0001
params.corner_dwell = 4
params.start_dwell = 3
params.end_dwell = 3
params.curve_dwell = 0
params.curve_angle = cos(30.0 * (pi / 180.0))
params.snap = 0.0001

ol.init()
ol.setRenderParams(params)

while True:
	ol.loadIdentity()
	ol.translate((-1,-1))
	ol.scale((1.99,1.99))
	xmin, ymin, xmax, ymax = image.bbox()
	w = xmax - xmin
	h = ymax - ymin
	ol.scale((1.0/max(w,h), 1.0/max(w,h)))
	ol.translate((-xmin, -ymin))
	image.draw()
	ol.renderFrame(60)
Esempio n. 8
0
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

import pylase as ol

import sys

if ol.init(10) < 0:
	sys.exit(1)
params = ol.RenderParams()
params.render_flags = ol.RENDER_NOREORDER | ol.RENDER_GRAYSCALE
params.on_speed = 2/120.0
params.off_speed = 2/30.0
params.flatness = 0.000001
ol.setRenderParams(params)

lines = sys.argv[1:]
ol.scale((-1,1));
while True:
	lc = len(lines)
	font = ol.getDefaultFont()
	yoff = (lc/2.0) * 0.3

	for i,line in enumerate(lines):
		w = ol.getStringWidth(font, 0.3, line)
		ol.drawString(font, (-w/2,yoff-i*0.3), 0.3, ol.C_WHITE, line)

	ftime = ol.renderFrame(60)

Esempio n. 9
0
        scanline.append([pixel_on, PixelCoordToGalvoCoord(x, y, width, height)])
        scanning_on = False
    if len(scanline) > 0:
        scanlines.append(scanline)
    scanlines.append(scanline)

if options.preview:
    pygame.init() 
    #create the screen
    window = pygame.display.set_mode((scaledWidth, scaledHeight)) 

print "Found ",len(scanlines),"non blank scan lines... scanning now..."
for l in scanlines:
    if options.laser:
        ol.loadIdentity()
        ol.scale((float(options.xscale), float(options.yscale)))
    for s in l: 
        if options.preview:
            pygame.draw.line(window, (0, 255, 0), GalvoCoordToPixelCoord(s[0], scaledWidth, scaledHeight), GalvoCoordToPixelCoord(s[1], scaledWidth, scaledHeight))
        if options.laser:
            ol.line((s[0][0],s[0][1]), (s[1][0],s[1][1]), ol.C_WHITE)   
    if options.preview:
        pygame.display.flip()
    if options.laser:
        ol.renderFrame(int(options.power))

print options.pngfile,
print " Height:",
print height,
print " Width:",
print width
Esempio n. 10
0
        if tokens[0] == "palette":
            render_frame()
            continue

        if tokens[0] == "frame":
            render_frame()

            currentFrame += 1
            if currentFrame >= startFrame:
                if endFrame > 0 and currentFrame > endFrame:
                    break
                renderFrame = True
                openPath = False
                ol.loadIdentity()
                ol.scale((1.0/32768, 1.0/32768))
                ol.translate((0, 0))
                if banner != "":
                    ol.drawString(font, (-w/2,yoff), fsize, ol.C_GREEN, banner)
            continue

        if is_number(tokens[0]):
            if renderFrame:
                x = float(tokens[0])
                y = float(tokens[1])
                palette_i = int(tokens[2])
    
                if not openPath:
                    ol.begin(0)
                    openPath = True
                elif palette_i < 0:
Esempio n. 11
0
import svg

image = svg.load_svg(sys.argv[1])

params = ol.RenderParams()
params.render_flags = 0
params.on_speed = 2 / 110.0
params.off_speed = 2 / 70.0
params.flatness = 0.0001
params.corner_dwell = 4
params.start_dwell = 3
params.end_dwell = 3
params.curve_dwell = 0
params.curve_angle = cos(30.0 * (pi / 180.0))
params.snap = 0.0001

ol.init()
ol.setRenderParams(params)

while True:
    ol.loadIdentity()
    ol.translate((-1, -1))
    ol.scale((1.99, 1.99))
    xmin, ymin, xmax, ymax = image.bbox()
    w = xmax - xmin
    h = ymax - ymin
    ol.scale((1.0 / max(w, h), 1.0 / max(w, h)))
    ol.translate((-xmin, -ymin))
    image.draw()
    ol.renderFrame(60)
Esempio n. 12
0
	def ScanLayer(self, png_file, vertical, preview, laser, power, xscale, yscale):
		#png_file = path of png file to scan
		#vertical = True | False (Scan Direction)
		#laser = True | False (Should we laser??)
		#power = Laser Power ( 1-1000)
		#xscale = (float) 0.0-1.0 Scale of X
		#yscale = (float) 0.0-1.0 Scale of X
		
		if laser:
			pylase.init()

		i = Image.open(png_file)

		pixels = i.load() # this is not a list
		width, height = i.size

		scaledWidth=int(float(xscale)*width)
		scaledHeight=int(float(yscale)*height)

		cur_pixel = pixels[0, 0]
		print cur_pixel

		if vertical:
			rangeA = range(width)
			rangeB = range(height)
		else:
			rangeA = range(height)
			rangeB = range(width)
		 
		print "Computing the scanlines...."
		scanlines=[]
		for dirA in rangeA:
			scanline=[]
			scanning_on = False
			pixel_on =[0, 0]
			if laser:
				x = 0
				y = 0
			for dirB in rangeB:
				if vertical:
					x = dirA
					y = dirB
				else:
					x = dirB
					y = dirA
				if self.IsPixelOn(pixels[x, y]):
					if scanning_on == False:
						pixel_on = self.PixelCoordToGalvoCoord(x, y, width, height)
						scanning_on = True
				else:
					if scanning_on:
						scanline.append([pixel_on, self.PixelCoordToGalvoCoord(x, y, width, height)])
						scanning_on = False
			if scanning_on:
				scanline.append([pixel_on, self.PixelCoordToGalvoCoord(x, y, width, height)])
				scanning_on = False
			if len(scanline) > 0:
				scanlines.append(scanline)
			scanlines.append(scanline)

		if preview:
			pygame.init() 
			#create the screen
			window = pygame.display.set_mode((scaledWidth, scaledHeight)) 

		print "Found ",len(scanlines),"non blank scan lines... scanning now..."
		for l in scanlines:
			if laser:
				pylase.loadIdentity()
				pylase.scale((float(xscale), float(yscale)))
			for s in l: 
				if preview:
					pygame.draw.line(window, (0, 255, 0), self.GalvoCoordToPixelCoord(s[0], scaledWidth, scaledHeight), self.GalvoCoordToPixelCoord(s[1], scaledWidth, scaledHeight))
				if laser:
					pylase.line((s[0][0],s[0][1]), (s[1][0],s[1][1]), pylase.C_WHITE)	
			if preview:
				pygame.display.flip()
			if laser:
				pylase.renderFrame(int(power))