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 Well I am almost finished with my commercial website development...
  2. Fun with Yahoo! Pipes JSON – C# – ActionScript3 What are yahoo pipes and why should I care? Yahoo!...
  3. Mono is Spreading What is mono?  Mono is the OpenSouce version of C#...
  4. Kuler-Splash with Flex What Kuler-Splash does: Click the button in the far right...
  5. Got Flint? Well it being the fourth of July and all I...

Related posts brought to you by Yet Another Related Posts Plugin.

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 ASP.NET Blend C# CakePHP CSS Experiment Flash Flash Develop Flex Games Generative Design Google Informatics JavaScript Joshua Davis JSON Life Lingo Linux MashUp Open Source OpenSource PaperVision3D PC History Processing quick tip RIA Silverlight Technology/Internet travel twitter Web Web 3.0 Webware XML Yahoo Pipes

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

  • Monthly
  • Yearly
  • Links
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • agit8
  • Bit-101
  • D.I.Y.
  • draw.logic
  • Flight404
  • Flong
  • generatorX
  • haXe
  • Jonathan Snook
  • Joshua Davis
  • Jot
  • Kirupa
  • LifeHacker
  • Make
  • NurseOnTheRun
  • octane42
  • PV3D
  • Senocular
  • Sephiroth
  • ShineDraw
  • SWX
  • Tech News
  • Toxi
  • ZeusLabs

Brendon's Photos

IMG_0368.jpg

Recent Comments

  • morganae23 on Processing JS
  • morganae23 on Processing JS

RSS LifeStream

  • Building a Windows Phone 7 Twitter Application using Silverlight
  • Mozilla Labs builds add-on to bring address book to Firefox
  • WePad is yet another Android tablet that will be supporting Flash 10.1