Example #1
0
def scanPixel(pixel, x, y, preview, laser, w,h):
    sX=(float(x)/float(w))*2.0 - 1.0
    sY=(float(y)/float(h))*2.0 - 1.0
    if pixel[0] != 0:
        if preview:
            pygame.draw.line(window, (255, 255, 255), (x, y), (x, y))
            pygame.display.flip()
        if laser:
            ol.dot((sX,sY),100,ol.C_WHITE)
            ol.renderFrame(100)             
Example #2
0
def render_frame():
    global renderFrame
    global openPath

    if renderFrame:
        if openPath:
            ol.end()
            openPath = False
        ol.renderFrame(30)
    renderFrame = False
Example #3
0
def draw_frame():
        global DRAW, frame_number

        #print "drawing frame ", frame_number
        frame_number = frame_number + 1
        
        ol.loadIdentity()
        #ol.scale((MAX_X, MAX_Y))
        DRAW.draw()
        ol.renderFrame(50)
Example #4
0
def scanPixel(pixel, x, y, preview, laser, w, h):
    sX = (float(x) / float(w)) * 2.0 - 1.0
    sY = (float(y) / float(h)) * 2.0 - 1.0
    if pixel[0] != 0:
        if preview:
            pygame.draw.line(window, (255, 255, 255), (x, y), (x, y))
            pygame.display.flip()
        if laser:
            ol.dot((sX, sY), 100, ol.C_WHITE)
            ol.renderFrame(100)
Example #5
0
    def run(self):
        ol.init()
        params = ol.RenderParams()
        params.render_flags = ol.RENDER_NOREORDER | ol.RENDER_GRAYSCALE
        ol.setRenderParams(params)

        while not self.die:
            ol.loadIdentity()
            for x, y in self.dots:
                ol.dot((x, y), 30, ol.C_WHITE)

            ol.renderFrame(100)
        ol.shutdown()
Example #6
0
	def run(self):
		ol.init()
		params = ol.RenderParams()
		params.render_flags = ol.RENDER_NOREORDER | ol.RENDER_GRAYSCALE
		ol.setRenderParams(params)

		while not self.die:
			ol.loadIdentity()
			for x,y in self.dots:
				ol.dot((x,y), 30, ol.C_WHITE)

			ol.renderFrame(100)
		ol.shutdown()
Example #7
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()
Example #8
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()
Example #9
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()
Example #10
0
def render():
        global gbl_frames
        global gbl_time
        global audiotime
        
	ftime = ol.renderFrame(150)
	gbl_frames += 1
	gbl_time += ftime

	audiotime = gbl_time * AB

        print "Frame time: {}, FPS:{}, Avg FPS:{}, Audio: {}".format(ftime, 1/ftime, gbl_frames/gbl_time, audiotime)
	return ftime
Example #11
0
	def run(self):
		if ol.init(10) < 0:
			return
		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)
		ol.setPixelShader(self.shade)
		time = 0
		frames = 0
		cur_tweets = self.tweets
		xpos = 0
		idx = 0
		startpos = 1.3
		while not self.die:
			ol.loadIdentity3()
			ol.loadIdentity()

			if cur_tweets is None and self.tweets is not None:
				cur_tweets = self.tweets
				idx = 0
				xpos = startpos

			w = 0
			#print cur_tweets
			if cur_tweets is not None:
				font = ol.getDefaultFont()
				w = ol.getStringWidth(font, 0.4, cur_tweets[idx])
				col = ol.C_WHITE
				#print "Render %f %s 0x%x"%(xpos, cur_tweets[idx], col)
				ol.drawString(font, (xpos,0.1), 0.4, col, cur_tweets[idx])
	
			#print "render"
			ftime = ol.renderFrame(60)
			#print "done"
			xpos -= 0.6*ftime
			if xpos < (-w-1) and cur_tweets is not None:
				xpos = startpos
				idx += 1
				idx %= len(cur_tweets)
				if self.tweets != cur_tweets:
					idx = 0
					cur_tweets = self.tweets
					print("Reset and update")
				print("Finished, new idx: %d"%idx)
			frames += 1
			time += ftime
		ol.shutdown()
Example #12
0
    def run(self):
        if ol.init(10) < 0:
            return
        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)
        ol.setPixelShader(self.shade)
        time = 0
        frames = 0
        cur_tweets = self.tweets
        xpos = 0
        idx = 0
        startpos = 1.3
        while not self.die:
            ol.loadIdentity3()
            ol.loadIdentity()

            if cur_tweets is None and self.tweets is not None:
                cur_tweets = self.tweets
                idx = 0
                xpos = startpos

            w = 0
            #print cur_tweets
            if cur_tweets is not None:
                font = ol.getDefaultFont()
                w = ol.getStringWidth(font, 0.4, cur_tweets[idx])
                col = ol.C_WHITE
                #print "Render %f %s 0x%x"%(xpos, cur_tweets[idx], col)
                ol.drawString(font, (xpos, 0.1), 0.4, col, cur_tweets[idx])

            #print "render"
            ftime = ol.renderFrame(60)
            #print "done"
            xpos -= 0.6 * ftime
            if xpos < (-w - 1) and cur_tweets is not None:
                xpos = startpos
                idx += 1
                idx %= len(cur_tweets)
                if self.tweets != cur_tweets:
                    idx = 0
                    cur_tweets = self.tweets
                    print("Reset and update")
                print("Finished, new idx: %d" % idx)
            frames += 1
            time += ftime
        ol.shutdown()
Example #13
0
def render():
    global gbl_frames
    global gbl_time
    global audiotime

    ftime = ol.renderFrame(150)
    gbl_frames += 1
    gbl_time += ftime

    audiotime = gbl_time * AB

    print "Frame time: {}, FPS:{}, Avg FPS:{}, Audio: {}".format(
        ftime, 1 / ftime, gbl_frames / gbl_time, audiotime)
    return ftime
Example #14
0
		ol.vertex3((-1,  1, -1))
		ol.vertex3((-1, -1, -1))
		ol.vertex3((-1, -1,  1))
		ol.end()

		ol.begin(ol.LINESTRIP);
		ol.vertex3(( 1,  1,  1))
		ol.vertex3((-1,  1,  1))
		ol.vertex3((-1, -1,  1))
		ol.vertex3(( 1, -1,  1))
		ol.vertex3(( 1,  1,  1))
		ol.vertex3(( 1,  1, -1))
		ol.end()

		ol.begin(ol.LINESTRIP)
		ol.vertex3(( 1, -1, -1))
		ol.vertex3(( 1, -1,  1))
		ol.end()

		ol.begin(ol.LINESTRIP)
		ol.vertex3((-1,  1,  1))
		ol.vertex3((-1,  1, -1))
		ol.end()

	ftime = ol.renderFrame(60) # Takes max_fps as argument
	frames += 1
	time += ftime
	print "Frame time: %f, FPS:%f"%(ftime, frames/time)

ol.shutdown()
Example #15
0
# 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:]

SIZE = 0.4

while True:
    lc = len(lines)

    font = ol.getDefaultFont()
    yoff = (lc / 2.0) * 0.4

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

    ftime = ol.renderFrame(60)
Example #16
0
# 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:]

SIZE = 0.4

while True:
	lc = len(lines)

	font = ol.getDefaultFont()
	yoff = (lc/2.0) * 0.4

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

	ftime = ol.renderFrame(60)
Example #17
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)
Example #18
0
    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
Example #19
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)
Example #20
0
    def run(self):

        # Run the render loop.  This will repeatedly render frames of the current plugin.
        print '\t--> Starting up LUX Engine.'
        ftime = 0
        frames = 0

        # Initialize OpenLase.  This also creates the lux_engine jack endpoints.
        if (ol.init(3, 96000) != 0):
            raise Exception("Could not initialize openlase")

        # Connect the output engine to the lux_engine.
        self.output_engine.connect_ports("lux_engine:out_x", "lux_output:in_x")
        self.output_engine.connect_ports("lux_engine:out_y", "lux_output:in_y")
        self.output_engine.connect_ports("lux_engine:out_r", "lux_output:in_r")
        self.output_engine.connect_ports("lux_engine:out_g", "lux_output:in_g")
        self.output_engine.connect_ports("lux_engine:out_b", "lux_output:in_b")

        # Turn off the hardware safety interlock.
        self.output_engine.setOutputInitialized(True)

        # Create a local settings object for this thread.
        settings = LuxSettings()

        while not self.exiting:
            # Grab local references to these class variables
            self.lock.lock()
            current_plugin = self.current_plugin
            video_engine = self.video_engine
            self.lock.unlock()

            # SET PARAMETERS
            #
            # Check to see if the GUI parameter override has been set,
            # and we need to update OL parameters.
            if (self.ol_update_params
                    and settings['calibration'].parameterOverride
                    and current_plugin):
                current_plugin.setParametersToGuiValues()
                self.ol_update_params = False

            if (current_plugin
                    and not settings['calibration'].parameterOverride):
                current_plugin.setParameters()

            if (self.reset_plugin_on_next_frame):
                current_plugin.reset()
                self.reset_plugin_on_next_frame = False

            # RENDER
            #
            # We call out to the current plugin's draw() method, or
            # the video plugin, depending on the current state of the
            # GUI.
            if (current_plugin):
                if (settings['video'].videoMode):
                    # Cause video color cycling to happen
                    ol.loadIdentity3()
                    ol.loadIdentity()
                    ol.perspective(60, 1, 1, 100)
                    ol.translate3((0, 0, -3))

                    ol.color3(*(self.video_color_drift.color_cycle()))
                    video_engine.draw_lasers()
                else:
                    current_plugin.draw()

                frame_render_time = ol.renderFrame(
                    60)  # Takes max_fps as argument
                frames += 1
                ftime += frame_render_time
                #print "Frame time: %f, FPS:%f"%(frame_render_time, frame_render_time/ftime)
            else:
                # If there is no plugin for some reason, kill time
                # rather than burning CPU in a loop that does nothing.
                time.sleep(0.1)
Example #21
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)
Example #22
0
    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

Example #23
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)
Example #24
0
    def run(self):

        # Run the render loop.  This will repeatedly render frames of the current plugin.
        print '\t--> Starting up LUX Engine.'
        ftime = 0
        frames = 0

        # Initialize OpenLase.  This also creates the lux_engine jack endpoints.
        if (ol.init(3, 96000) != 0):
            raise Exception("Could not initialize openlase")

        # Connect the output engine to the lux_engine.
        self.output_engine.connect_ports("lux_engine:out_x", "lux_output:in_x")
        self.output_engine.connect_ports("lux_engine:out_y", "lux_output:in_y")
        self.output_engine.connect_ports("lux_engine:out_r", "lux_output:in_r")
        self.output_engine.connect_ports("lux_engine:out_g", "lux_output:in_g")
        self.output_engine.connect_ports("lux_engine:out_b", "lux_output:in_b")

        # Turn off the hardware safety interlock.
        self.output_engine.setOutputInitialized(True)

        # Create a local settings object for this thread.
        settings = LuxSettings()
        
        while not self.exiting:
            # Grab local references to these class variables
            self.lock.lock()
            current_plugin = self.current_plugin
            video_engine = self.video_engine
            self.lock.unlock()
            
            # SET PARAMETERS
            #
            # Check to see if the GUI parameter override has been set,
            # and we need to update OL parameters.
            if (self.ol_update_params and settings['calibration'].parameterOverride and current_plugin):
                current_plugin.setParametersToGuiValues()
                self.ol_update_params = False

            if (current_plugin and not settings['calibration'].parameterOverride):
                current_plugin.setParameters();

            # RENDER
            #
            # We call out to the current plugin's draw() method, or
            # the video plugin, depending on the current state of the
            # GUI.
            if (current_plugin):
                if (settings['video'].videoMode):
                    # Cause video color cycling to happen
                    ol.loadIdentity3();
                    ol.loadIdentity();
                    ol.perspective(60, 1, 1, 100);
                    ol.translate3((0, 0, -3));

                    ol.color3(*(self.video_color_drift.color_cycle()))
                    video_engine.draw_lasers()
                else:
                    current_plugin.draw()

                frame_render_time = ol.renderFrame(60)   # Takes max_fps as argument
                frames += 1
                ftime += frame_render_time
                #print "Frame time: %f, FPS:%f"%(frame_render_time, frame_render_time/ftime)
            else:
                # If there is no plugin for some reason, kill time
                # rather than burning CPU in a loop that does nothing.
                time.sleep(0.1)
Example #25
0
params.flatness = 0.000001
ol.setRenderParams(params)

height = float(sys.argv[1])
xpos = float(sys.argv[2])
ypos = float(sys.argv[3])
x_scroll_rate = float(sys.argv[4])
y_scroll_rate = float(sys.argv[5])
lines = sys.argv[6:]
lc = len(lines)

font = ol.getDefaultFont()
yoff = (lc/2.0) * height

while True:
	for i,line in enumerate(lines):
		w = ol.getStringWidth(font, height, line)
		ol.drawString(font, (-w/2+xpos,yoff-i*height+ypos), height, ol.C_WHITE, line)

	ftime = ol.renderFrame(30)
        xpos = xpos + x_scroll_rate
        if xpos < -3.0:
           xpos = 3.0
        if xpos > 3.0:
           xpos = -3.0
        ypos = ypos + y_scroll_rate
        if ypos < -3.0:
           ypos = 3.0
        if ypos > 3.0:
           ypos = -3.0
Example #26
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))
Example #27
0
ol.setRenderParams(params)

height = float(sys.argv[1])
xpos = float(sys.argv[2])
ypos = float(sys.argv[3])
x_scroll_rate = float(sys.argv[4])
y_scroll_rate = float(sys.argv[5])
lines = sys.argv[6:]
lc = len(lines)

font = ol.getDefaultFont()
yoff = (lc / 2.0) * height

while True:
    for i, line in enumerate(lines):
        w = ol.getStringWidth(font, height, line)
        ol.drawString(font, (-w / 2 + xpos, yoff - i * height + ypos), height,
                      ol.C_WHITE, line)

    ftime = ol.renderFrame(30)
    xpos = xpos + x_scroll_rate
    if xpos < -3.0:
        xpos = 3.0
    if xpos > 3.0:
        xpos = -3.0
    ypos = ypos + y_scroll_rate
    if ypos < -3.0:
        ypos = 3.0
    if ypos > 3.0:
        ypos = -3.0