Interactive Generative Art Series – 06 – lineStyle

gen-art-06-linestyle-1gen-art-06-linestyle-2gen-art-06-linestyle-3

The last example in this series discussed getting the anchor to move in a way that our ball would paint more interesting and we worked on restricting the colors to a certain RGB range. This one is a very simple change, but has a pretty significant effect. We’re just editing the cap style of our lines in lineStyle. The default value we’ve been using so far is ROUND, but now if we test NONE the lines drawn will have no ends and basically be rectangles (since the width is so wide). This gets interesting especially when the path curves and we can see all the angles and corners exposed by the rectangles and it makes me think of a wooden snake toy (Wooden Wiggle Snake). I started playing around with the opacity or alpha property of the lines as well so that the flat ended lines would show better. What else would you toy with in here?

06 lineStyle, play here

Please visit the blog article to view this interactive flash content. Flash plug-in required: Get Adobe Flash player

actionscript source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
var ball:Sprite = new Sprite();
ball.graphics.beginFill(0x000000, 1);
ball.graphics.drawCircle(0, 0, 10);
ball.graphics.endFill();
addChild(ball);

var anchor:Sprite = new Sprite();

anchor.graphics.beginFill(0x333333, .6);
anchor.graphics.drawCircle(0, 0, 12);
anchor.graphics.endFill();
addChild(anchor);

var div:Number = .1;
var line_max_width:Number = 64;
var line_min_width:Number = 2;
var line_width:Number = randomRange(line_min_width, line_max_width);
var line_width_velocity:Number = 0;
var dampen:Number = 0.95;

var ballax:Number = 0;
var ballay:Number = 0;
var oldx:Number = ball.x;
var oldy:Number = ball.y;

var anchorvx:Number = 0;
var anchorvy:Number = 0;

anchor.x = stage.stageWidth/2;
anchor.y = stage.stageHeight/2;
var gradientBoxMatrix:Matrix = new Matrix();

var colors:Object = new Object();
colors.r = 255;
colors.g = 255;
colors.b = 255;
colors.rv = 0;
colors.gv = 0;
colors.bv = 0;
colors.rmin = 0;
colors.rmax = 150;
colors.gmin = 100;
colors.gmax = 200;
colors.bmin = 200;
colors.bmax = 250;
colors.rate_of_change = 12;
var color_first:Number = 0xFFFFFF;
var color_second:Number = rgb2hex(colors.r, colors.g, colors.b);


function loop () {
   
    oldx = ball.x;
    oldy = ball.y;
   
    anchorvx += randomRangeAxis(10);
    anchorvy += randomRangeAxis(10);

    anchor.x += anchorvx;
    anchor.y += anchorvy;
   
    anchorvx *= dampen;
    anchorvy *= dampen;
   
    if(anchor.x > stage.stageWidth) {
        anchor.x = 0 - anchor.width;
    }
    else if(anchor.x < 0 - anchor.width) {
        anchor.x = stage.stageWidth;
    }
    if(anchor.y > stage.stageHeight) {
        anchor.y = 0 - anchor.height;
    }
    else if(anchor.y < 0 - anchor.height) {
        anchor.y = stage.stageHeight;
    }
   
    ball.x -= ballax = (ballax + (ball.x - anchor.x) * div) * .9;
    ball.y -= ballay = (ballay + (ball.y - anchor.y) * div) * .9;
       
    line_width_velocity += randomRangeAxis(1);
    line_width += line_width_velocity;
    line_width_velocity *= dampen;
    if(line_width > line_max_width) {
        line_width = line_max_width;
        line_width_velocity = 0;
    }
    else if (line_width < line_min_width) {
        line_width = line_min_width;
        line_width_velocity = 0;
    }
   
    color_step();
    color_first = color_second;
    color_second = rgb2hex(colors.r, colors.g, colors.b);
   
    var dx:Number = ball.x - oldx;
    var dy:Number = ball.y - oldy;
    this.graphics.lineStyle(line_width, color_first, (line_width+100-line_max_width)/100, true, LineScaleMode.NONE, CapsStyle.NONE);
    gradientBoxMatrix.createGradientBox(Math.abs(dx), Math.abs(dy), Math.atan2(dy,dx), Math.min(oldx, ball.x), Math.min(oldy, ball.y));
    this.graphics.lineGradientStyle(GradientType.LINEAR, [color_first, color_second], [(line_width+100-line_max_width)/100,(line_width+100-line_max_width)/100], [0, 255], gradientBoxMatrix);
    this.graphics.lineTo(ball.x, ball.y);
}

setInterval(loop, 1000/30);

function rgb2hex(r:Number, g:Number, b:Number):Number {
    return(r<<16 | g<<8 | b);
}
function color_step(){
    colors.rv += randomRangeAxis(colors.rate_of_change);
    colors.r  += colors.rv;
    colors.rv *= dampen;
    if (colors.r > colors.rmax) {
        colors.r = colors.rmax;
    } else if (colors.r < colors.rmin){
        colors.r = colors.rmin;
    }
   
    colors.gv += randomRangeAxis(colors.rate_of_change);
    colors.g  += colors.gv;
    colors.gv *= dampen;
    if (colors.g > colors.gmax) {
        colors.g = colors.gmax;
    } else if (colors.g < colors.gmin){
        colors.g = colors.gmin;
    }
   
    colors.bv += randomRangeAxis(colors.rate_of_change);
    colors.b  += colors.bv;
    colors.bv *= dampen;
    if (colors.b > colors.bmax) {
        colors.b = colors.bmax;
    } else if (colors.b < colors.bmin){
        colors.b = colors.bmin;
    }
}
//random number between min and max
function randomRange(max:Number, min:Number = 0):Number {
    return Math.random() * (max - min) + min;
}
//random number range centered at 0 with the specified max, randomRange(-max, max)
function randomRangeAxis(max:Number, axis:Number = 0):Number {
    return Math.random() * (max * 2) - max + axis;
}

download

Here’s the gen-art-06-linestyle.swf as well as the gen-art-06-linestyle.fla to download and tinker.

Reference

This entry was posted in generative art and tagged , , , , , , , , , , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Subscribe without commenting

  • Recent Posts

    speaker-lineup

    Presenting at WordCamp Atlanta – Child Themes

    The presentation? Your firstborn child theme. Child themes 101+2. I’m speaking at wordcamp atlanta this afternoon about themes and child themes. I’ll update this post with post-presentation notes. Learn how to mod themes the right way. Using child themes you won’t loose your edits when there’s a theme update. (101) We’ll go over the advantages [...]

    hooks-nutshell

    Hooks, In a Nutshell – WP Daily

    I’ve published another article over on wpdaily.co exploring the concept of hooks. I remember when starting out that people kept mentioning hooks and filters and actions and… it took a while to grasp what they each meant. I think the first time I started to grasp it was when I read the codex and saw [...]

    speaker-lineup

    Speaker at WordCamp Atlanta 2013

    I’m excited to be speaking at WordCamp Atlanta again this year! The time is quickly approaching for WordCamp Atlanta 2013, March 15-16. I spoke last year and discussed the process of going from Photoshop PSD to WordPress Theme, here are my slides and notes for that WordCamp Presentation. This year I’m speaking along the same [...]

    many-theme-options

    WP Features: Theme or Plugin

    Reading my wpdaily.co updates today and saw this post talking about WordPress theme features. Eric explains the debate: Generally-speaking, the conversations have always circled around features: There are those that believe every feature you could ever imagine should be included like text color, font selector, and more. On the flip-side, there are those that feel [...]

    Packery Preview, from Metafizzy & descended from Masonry

    David Desandro / metafizzy, maker of masonry and isotope of which I’m a big fan and user of has been busy with a new project called Packery. Packery, looks to be a child of Masonry. As you would expect it seems to be pushing things much further and addressing a few pain points of masonry. [...]

    trent-walton-thumb

    On Going Responsive (responding to Where to Start)

    I needed to write this up about going responsive in response after reading Where to Start (by Trent Walton of Paravel) about getting started with responsive web design. Thanks for sharing your thoughts Trent, I agree whole heartedly. In my experience it is the same. I wanted to share his post and also add my [...]

  • Recent Comments

    Evan Mullins

    Evan Mullins

    The keystore is used for creating valid apps that are associated with the author. It is not...
    Rohan Dave

    Rohan Dave

    I am new in android and have certain question about KeyStore. Is KeyStore used in user...
    arpit

    arpit

    very useful thank you …..
    Duan

    Duan

    @ugh You’re joking, right? I do some basics in Flash, but come on – all you do is...
    Cátia Vala

    Cátia Vala

    Thank you so much Evan! That’s great! Keep going with your amazing work. :)
    zproxy

    zproxy

    thanks :) i bet its faster to google and find some ad hoc documentation than the other way.