Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

mzscheme 352 Portfile (to get Arc working on OS X)

# $Id$

PortSystem 1.0

name mzscheme
version 352
categories lang scheme
platforms darwin
maintainers nomaintainer
description MzScheme is an implementation of the Scheme programming language
long_description ${description}

homepage http://www.plt-scheme.org/software/mzscheme/
set subdir ${version}/mz/
master_sites \
http://download.plt-scheme.org/bundles/${subdir} \
http://plt.cs.uchicago.edu/bundles/${subdir} \
http://www.cs.utah.edu/plt/download/${subdir} \
ftp://archive.informatik.uni-tuebingen.de/unix/language/plt/${subdir} \
ftp://infogroep.be/pub/plt/bundles/${subdir} \
http://gd.tuwien.ac.at/languages/scheme/plt/${subdir}
distfiles mz-${version}-src-unix.tgz
checksums md5 218bad0defbdbb72d94d8a3fb4fa6545

depends_lib port:jpeg \
port:libpng \
port:libiconv

worksrcdir plt/src

post-patch {
reinplace "s|collects|share/mzscheme|g" \
${worksrcpath}/mzscheme/src/startup.ss \
${worksrcpath}/mzscheme/src/startup.inc
reinplace "s|~/Library/PLT Scheme/|${prefix}/share/mzscheme/|g" \
${worksrcpath}/mzscheme/src/file.c
}

configure.env CFLAGS="-I${prefix}/include" \
CPPFLAGS="-I${prefix}/include" \
LDFLAGS="-L${prefix}/lib"

destroot.destdir prefix=${destroot}${prefix}
post-destroot {
file delete -force ${destroot}${prefix}/install \
${destroot}${prefix}/share/man
file rename ${destroot}${prefix}/collects \
${destroot}${prefix}/share/mzscheme
xinstall -m 755 -d ${destroot}${prefix}/share/doc/ \
${destroot}${prefix}/share/mzscheme/${version}/
system "cd ${destroot}${prefix}/share/mzscheme/${version} && ln -s .. collects"
file rename ${destroot}${prefix}/man \
${destroot}${prefix}/share/man
file rename ${destroot}${prefix}/doc \
${destroot}${prefix}/share/doc/mzscheme
file delete -force ${destroot}${prefix}/lib/buildinfo
}

Rubylike slice for strings and lists

(slice "hello" 2 4) => "ll"
Comparable to: "hello"[2...4]

(slice "hello" 2 -1) => "ll"
Comparable to: "hello"[2...-1]

(slice "hello" '(2 2)) => "ll"
Comparable to: "hello"[2,2]

(slice "hello" 1) => "ello"
Comparable to: "hello"[2..-1]

(def slice (str x (o y))
  (if (atom x)
    (if 
      ; (slice "hello" 1) => "ello"
      (no y) 
        (subseq str x)
      ; (slice "hello" 2 -1) => "ll"
      (< y 0) 
        (subseq str x (+ (len str) y))
      ; (slice "hello" 2 4) => "ll"
      (subseq str x y))
    ; (slice "hello" '(2 2)) => "ll"
    (subseq str (car x) (+ (car x) (cadr x)))))

Graphical Plotter //Javascript Class



[UPDATED CODE AND HELP CAN BE FOUND HERE]



An unuseful thing to draw using javascript, it's slow as hell :)

//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/dhtml/graphical-plotter [v1.0]

Canvas = function(){
	var o = this;
	( o.penPos = { x: 0, y: 0 }, o.pixelSize = 10, o.pen = { style: "solid", size: 1, color: "#000" }, o.brush = { style: "solid", color: "#000" } );
};
with( { p: Canvas.prototype } ){
	p.pixel = function( x, y, color ) {
		var o = this, s = document.body.appendChild( document.createElement( "div" ) ).style;
		return ( s.position = "absolute", s.width = ( o.pen.size * o.pixelSize ) + "px", s.height = ( o.pen.size * o.pixelSize ) + "px", s.fontSize = "1px", s.left = ( x * o.pixelSize ) + "px", s.top = ( y * o.pixelSize ) + "px", s.backgroundColor = color || o.pen.color, o );
	};
	p.line = function( x1, y1, x2, y2 ){
		if( Math.abs( x1 - x2 ) < Math.abs( y1 - y2 ) )
			for( y = Math.min( y1, y2 ) - 1, x = Math.max( y1, y2 ); ++y <= x; canvas.pixel( ( y * ( x1 - x2 ) - x1 * y2 + y1 * x2 ) / ( y1 - y2 ), y ) );
		else
			for( x = Math.min( x1, x2 ) - 1, y = Math.max( x1, x2 ); ++x <= y; canvas.pixel( x, ( x * ( y1 - y2 ) - y1 * x2 + x1 * y2 ) / ( x1 - x2 ) ) );
		return this;
	};
	p.arc = function( x, y, raio, startAngle, degrees ) {
		for( degrees += startAngle; degrees --> startAngle; this.pixel( Math.cos( degrees * Math.PI / 180 ) * raio + x, Math.sin( degrees * Math.PI / 180 ) * raio + y ) ); return this;
	};
	p.rectangle = function( x, y, width, height, rotation ){
		return this.moveTo( x, y ).lineBy( 0, height ).lineBy( width, 0 ).lineBy( 0, -height ).lineBy( -width, 0 );
	};
	p.moveTo = function( x, y ){ var o = this; return ( o.penPos.x = x, o.penPos.y = y, o ); };
	p.moveBy = function( x, y ){ var o = this; return o.moveTo( o.penPos.x + x, o.penPos.y + y ); };
	p.lineTo = function( x, y ){ var o = this; return o.line( o.penPos.x, o.penPos.y, x, y ).moveTo( x, y ); };
	p.lineBy = function( x, y ){ var o = this; return o.lineTo( o.penPos.x + x, o.penPos.y + y ); };
	p.curveTo = function( cx, cy, x, y ){};
	p.polyBezier = function( points ){};
	p.path = function( points ){};
}



Example:

canvas = new Canvas;

canvas.pen.color = "#f00";
canvas.rectangle( 30, 20, 20, 20 );
canvas.pen.color = "#080";
canvas.rectangle( 35, 25, 10, 10 );
canvas.pen.color = "#008";
canvas.arc( 50, 30, 10, 180, 270 );
canvas.arc( 30, 30, 10, 0, 270 );
canvas.pen.color = "#ff0";
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS