Other Websites

  • SeaCloud9 Interactive
  • SeaCloud9 Commercial Development
  • i-os
  • stArcade9

Brendon Smith Social Networks

  • On Linkedin
  • Bookmarks
  • On Twitter
  • On Facebook
Open ↓ Close ↑
  • Home
  • Subscribe
Browse: Home / .net, ActionScript, Adobe, C#, i-create, Silverlight / Technologically Agnostic
i-create | therefore-i am
i-create | therefore i-am | a blog about opensource technology and rich internet applications
 

Technologically Agnostic

By Brendon Smith on June 6, 2009

 

Technologically agnostic and liking it. When it comes to new technologies many come and go so it can be a challenge to see which ones really take root. People love to talk about open source technology and I myself love open technology because it encourages developers like myself to play with whatever I want and experiment with it and see what kind of results I get. People can be extremely opinionated on this subject in particular and it gets to be like discussing religion or politics. In short no one really wins there are great technology offerings on both sides! I believe if you treat these opinions as religion you will lose. What is important to me? Have fun become a better programmer by experimenting with all the different stacks that are offered. You always win if you don’t really care and can honestly recognize which particular stack is well suited for the job and back it up with undeniable facts. It is also important to notice your crowd. With that being said please take it from me any opportunity you have to learn something new is always a good opportunity! Never be afraid of failure. Lately I have been working on relatively simple generative code examples and I have been working on porting these examples to Silverlight, Flash, and Processing. Why no reason it’s just fun. To be 100% honest when I saw silverlight 1 I absolutely hated it. Now I am getting a little more comfortable with it and love the fact I can use C# to program in for silverlight. This is not to say I have lost my intense love and fascination with flash and ActionScript because I never have or will. It is just the quest to learn experiment and know both technologies with confidence. I have been reading Kostas Algorithms for Visual Design by Kostas TezidisTerzidis’s book Algorithms for Visual Design and I found I love the book and what I learn in the book doesn’t just apply to Processing but all programming languages in general and it helps me to know how to problem solve relatively complex questions quickly! I have a high regard for Terzidis’s book it is an exceptional book in many ways it also happens to have a whole chapter devoted to writing image processing algorithms. I might try to port one to show you processing/hydra/c# pixel shader/pixel bender example. Anyway here is quick and dirty example of how you can use processing /silverlight/flash for mouse tracking apply it to scale, and rotate a rectangle. You will also apply a gradient programatically with processing /c#/actionscript3. This is just meant to be a ridiculously simple example. If you play with the same principles that are laid out in this example you could use it to build a rudimentary on-line drawing application. (of course in silverlight you could just use ink canvas but what is the fun in that?)

This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.



color[] shadeTable;
void setShades(color c){
  float r,g,b;
  r = red(c);
  g = green(c);
  b = blue(c);
  r /= 255.;
  g /= 255.;
  b /= 255.;
  shadeTable = new color[256];
  for ( int i = 0; i < 255; i++)
  shadeTable [i] = color((int)(r*i),(int)(g*i),(int)(b*i));
}
 
void setup(){
  noFill();
  size(500,500);
}
void draw(){
  setShades(color(255,0,0));
  background(255);
  for (float i=1; i<20; i++){
    pushMatrix();
    translate(width/2,height/2);
    scale(1/(i/mouseY*90),1/(i/mouseY*90));
    rotate(radians(i*mouseX));
    for (int x=1; x<155; x++){
    fill(shadeTable[x]);
    noStroke();
    rect(0,x,200,100);
 
    }
    popMatrix();
  }
}



Get Microsoft Silverlight




C# XAML Silverlight 3 Example of simple mouse tracking.

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Messaging;
using System.Globalization;
using System.Diagnostics;
 
namespace rectGen
{
    public partial class MainPage : UserControl
    {
        public Point mousePoint;
        public Point renderT = new Point(0.0 ,1.0);
        public Point vectorLength = new Point();
        public Rectangle[] blueRectangle = new Rectangle[20];
        public double angle;
 
        public MainPage()
        {
            InitializeComponent();
 
            renderRectangle();
            LayoutRoot.MouseMove += new MouseEventHandler(LayoutRoot_MouseMove);
 
        }
        public void renderRectangle()
        {
            for (int i = 0; i < 19; i++)
            {
                blueRectangle[i] = new Rectangle();
                blueRectangle[i].Height = 200;
                blueRectangle[i].Width = 300;
                LinearGradientBrush blueGR = new LinearGradientBrush();
                blueGR.StartPoint = new Point(0, 0);
                blueGR.EndPoint = new Point(1, 1);
                GradientStop blueGS = new GradientStop();
                blueGS.Color = Colors.Blue;
                blueGS.Offset = 0.2;
                blueGR.GradientStops.Add(blueGS);
                GradientStop greenGS = new GradientStop();
                greenGS.Color = Colors.Green;
                greenGS.Offset = 0.75;
                blueGR.GradientStops.Add(greenGS);
                blueRectangle[i].Fill = blueGR;
                blueRectangle[i].Name = "blueRect" + i;
                blueRectangle[i].Opacity = 0.4;
                LayoutRoot.Children.Add(blueRectangle[i]);
            }
 
        }
        private void LayoutRoot_MouseMove(object sender, MouseEventArgs e)
        {
            for (int i = 0; i < 19; i++)
            {
                Point mousePoint = e.GetPosition(null);
                RotateTransform rectR = new RotateTransform();
                ScaleTransform rectT = new ScaleTransform();
                rectT.ScaleX = mousePoint.X * .005;
                rectT.ScaleY = mousePoint.Y * .005;
                double radians = Math.Atan2(mousePoint.Y, mousePoint.X * i+1);
                angle = Convert.ToInt16(720 / Math.PI * radians);
                Debug.WriteLine(angle);
                rectR.Angle = angle;
                TransformGroup[] myTransformGroup = new TransformGroup[20];
                myTransformGroup[i] = new TransformGroup();
                myTransformGroup[i].Children.Add(rectT);
                myTransformGroup[i].Children.Add(rectR);
                blueRectangle[i].RenderTransform = myTransformGroup[i];
            }
        }
 
    }
}




ActionScript 3:

package 
{
	//import com.adobe.protocols.dict.events.ConnectedEvent;
	import flash.display.GradientType;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;
 
	/**
	 * ...
	 * @author brendon smith
	 */
	public class Main extends Sprite 
	{
		 public var xPos:Number = new Number();  
         public var yPos:Number = new Number();  
         public var rWidth:Number = new Number();  
         public var rHeight:Number = new Number();  
         public var color:uint = new uint();
		 public var rect:Sprite;
		 public var matrix:Matrix;
		 public var rectArray:Array;
 
		public function Main():void 
		{
			stage.stageWidth = 325; 
			stage.stageHeight = 400;
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
 
		}
		 public function createRectangles():void
		{
			rectArray = new Array();
			for (var i:uint = 0; i<60; i++ )
			{
			 xPos = 300;
			 rWidth = 160;
			 yPos = 300;
			 rHeight = 100;
			 rect = new Sprite();
			 addChild(rect);
			 rectArray.push(rect);
			 var fillType:String = GradientType.LINEAR;
             var colors:Array = [0x078cfb, 0x07fb07];
             var alphas:Array = [.05, .05 ];
             var ratios:Array = [0x00, 0xFF];
             var matr:Matrix = new Matrix();
             matr.createGradientBox(162, 200, 0, 0, 0);
			 var spreadMethod:String = SpreadMethod.PAD;//SpreadMethod.PAD, SpreadMethod.REFLECT
             rect.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);
			 rect.graphics.drawRect(0, 0, rWidth, rHeight);
             rect.graphics.endFill();
			 rect.x = 162;
			 rect.y = 200;
			}
			stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseStretchRotate);
		}
		 public function mouseStretchRotate(e:MouseEvent):void 
		{
			for (var i:uint = 0; i<rectArray.length; i++ )
			{
			 var radian:Number = Math.atan2(mouseX, mouseY + 1);
			 var angle:Number = i * (720 / Math.PI * radian);
			 rectArray[i].rotation = angle;
			 rectArray[i].scaleX = mouseX * .005;
			 rectArray[i].scaleY =  mouseY * .005;
			}
 
 
		}
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			createRectangles();
		}
 
	}
 
}



Processing Code

C# Code

ActionScript Code

  • Share/Bookmark

Related posts:

  1. SeaCloud9 Commercial Development
  2. Fun with Yahoo! Pipes JSON – C# – ActionScript3
  3. Mono is Spreading
  4. Kuler-Splash with Flex
  5. Simple Flip3D in ActionScript3

Posted in .net, ActionScript, Adobe, C#, i-create, Silverlight | Tagged ActionScript, art, C#, Flash Develop, Open Source, Silverlight

Brendon Smith

GUI Development, Action Script, Java Script, .NET, AJAX, Java, PHP, CakePHP, Mashup Development, Flash, Silverlight, C#, XML, SQL, Apache, IIS, Photoshop, Fireworks,etc.. Oh, and Biking and Camping

blog comments powered by Disqus
« Previous Next »
 
 

3d ActionScript Adobe Air Android Apollo Apple art as3 Away3D C# CakePHP CSS Experiment Flash Flash Develop Flex Games Generative Design Google HTML5 hype JavaScript Joshua Davis JQuery JSON Life Linux MashUp OpenSource Open Source PaperVision3D PC History Processing quick tip RIA Silverlight Technology/Internet travel twitter Web webGL Webware XML Yahoo Pipes

WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.

  • Monthly
  • Yearly
  • Links
  • August 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • agit8
  • Away3D
  • Ben Nadel
  • Bit-101
  • Bruce Jawn
  • Causecast
  • D.I.Y.
  • Dr Woohoo
  • draw.logic
  • Flight404
  • Flong
  • generatorX
  • gSkinner
  • haXe
  • Jonathan Snook
  • Joshua Davis
  • Jot
  • Kirupa
  • LifeHacker
  • Make
  • Minor White
  • Mr Doob
  • NihiLogic
  • NurseOnTheRun
  • octane42
  • OpenFrameWorks
  • Processing
  • PV3D
  • Senocular
  • Sephiroth
  • ShineDraw
  • Stroep
  • SWX
  • Tech News
  • Toxi
  • UnitZeroOne
  • World We Live In
  • ZeusLabs

Photos

PC280086.JPG

Recent Comments

  • seacloud9 on Tweet Tank in Away3D and Hype pt. 2
  • Brendon Smith on Tweet Tank in Away3D and Hype pt. 2

RSS LifeStream

  • Elysium
  • Giles Bowkett: Archaeopteryx: A Ruby MIDI Generator
  • Grant Nestor » Blog Archive » Generative music, huh?

Copyright © 2010 i-create | therefore-i am.