ActionScript 3 随机彩色弹性条纹

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 随机彩色弹性条纹相关的知识,希望对你有一定的参考价值。

//Get Traer.Physics for AS3 at http://blog.sqrtof5.com/?p=53
import traer.physics.Attraction;
import traer.physics.Particle;
import traer.physics.ParticleSystem;
import traer.physics.Spring;

//get k-lib Kuler API Library at http://code.google.com/p/k-lib/
import com.adobe.kuler.events.GetResultEvent;
import com.adobe.kuler.params.SearchParams;
import com.adobe.kuler.swatches.swatch.color.Color;
import com.adobe.kuler.KLibService;

import flash.geom.Vector3D;

//
//
//
//
// Get a Kuler API key at http://kuler.adobe.com/api/
//
// BE SURE TO ENTER YOUR API KEY HERE FOR THIS TO WORK
//		||
//		||
//		||
//		\/

var YOUR_KULER_API_KEY = "";



var s:ParticleSystem = new ParticleSystem(new Vector3D(0, 0, 0), .2);
var waterMolecules = new Array();
var waterParticles = new Array();
var sky = new Array();
var earth = new Array();
var magnet = s.makeParticle(0.12, new Vector3D(0, 0, 0));
var hover=new Molecule();
var points = new Array();
var water = new Sprite();
var lastColor = "000000";
var container = new Sprite();
var stripes = new Array();
var colors = new Array();
var totalWidth = 0;
var swatch;


var klib:KLibService = new KLibService(YOUR_KULER_API_KEY);
klib.addEventListener(GetResultEvent.GET_RESULTS, onResults);
klib.getRecent();


function onResults(e){
	swatch = e.results.swatches[0];
	trace(swatch.colors[ int(Math.random() * swatch.colors.length -1) ]);
	init();
}



function init(){
	magnet.makeFixed();
	magnet.position.y=200;
	var i=0;
	while(totalWidth<stage.stageWidth){

		colors[i] = lastColor;
		while(colors[i]==lastColor){
			colors[i]= swatch.colors[ int(Math.random() * swatch.colors.length -1) ].swatchHexColor;
			trace(colors[i]);
		}
		sky[i]=s.makeParticle(10, new Vector3D(totalWidth, 100, 0)); sky[i].makeFixed();
		waterParticles[i]=s.makeParticle(0.5, new Vector3D(totalWidth, 200, 0));
		earth[i]=s.makeParticle(10, new Vector3D(totalWidth, 300, 0)); earth[i].makeFixed();
		var thisWidth = Math.random()*20 + 5;
		totalWidth += thisWidth;
		stripes[i]=new Sprite();
		addChild(stripes[i]);

		if(i>0){
			s.makeSpring(waterParticles[i-1], waterParticles[i], 0.1 , .05, 0);
			s.makeSpring(sky[i], waterParticles[i], 0.05 , .05, 0);
			s.makeSpring(earth[i], waterParticles[i], 0.05 , .05, 0);
			
			s.makeAttraction(magnet, waterParticles[i], -15000 , 10);
			
		}
		lastColor = colors[i];
		i++
	}
	
	waterParticles[0].makeFixed();
	waterParticles[waterParticles.length-1].makeFixed();
	waterParticles[waterParticles.length-1].position.x=stage.stageWidth;

	stage.addEventListener(Event.ENTER_FRAME,loop);
}

function loop(e){
	s.tick(1);
	magnet.position.x = hover.x = mouseX;

	for(var i in waterParticles){
		stripes[i].graphics.clear();
		stripes[i].graphics.beginFill("0x"+colors[i]);
		if(i<waterParticles.length){
			stripes[i].graphics.moveTo(waterParticles[i].position.x,0);
			stripes[i].graphics.lineTo(waterParticles[i].position.x,stage.stageHeight);
		}
		if(i>0){
			stripes[i].graphics.lineTo(waterParticles[i-1].position.x,stage.stageHeight);
			stripes[i].graphics.lineTo(waterParticles[i-1].position.x,0);			
		}
		stripes[i].graphics.endFill();

	}

}

以上是关于ActionScript 3 随机彩色弹性条纹的主要内容,如果未能解决你的问题,请参考以下文章

[ActionScript 3.0] 模拟win7彩色气泡屏保效果

DT::datatable 的条纹

ActionScript 3 拖动整个弹性应用程序窗口

如何创建彩色条纹背景,动画以缓慢转动 360 度,不使用光栅图像或 js?

ActionScript 3 ActionScript 3 - 随机播放(随机不重复)

FPGA驱动OV5640用VGA显示画面上有很多彩色条纹