Output stylus loop variable in selector - stylus

I am trying to use a for loop to generate selectors and properties but it's not working. Here is my code:
colours = cola lychee lemonade tonic cherry ginger pineapple lemon lime elderflower cream-soda cream-soda-diet blackberry blueberry grape tropical raspberry
cola = #1f2023
lychee = #9ca6b1
lemonade = #e0e5ed
tonic = #f8f9fa
cherry = #f7362b
ginger = #f79945
pineapple = #ffad00
lemon = #f5d600
lime = #6ecc54
elderflower = #4acccf
cream-soda = #00abff
cream-soda-diet = #F2FBFF
blackberry = #45388c
blueberry = #8f78e8
grape = #663da6
tropical = #cc78d1
raspberry = #fc007a
bubblegum = #f78cbf
button
for colour in colours
&.{colour}
background colour
I want it to output something like this:
button.cola {
background: #1f2023;
}
button.lychee {
background: #9ca6b1
}
...

Using Stylus hashes would be the way to go here.
colours = {
cola: #1f2023
lychee: #9ca6b1
lemonade: #e0e5ed
tonic: #f8f9fa
cherry: #f7362b
// etc
}
button
for colour, value in colours
&.{colour}
background value
generates the output you're looking for.

Related

getattribute in OSL is not giving expected results

I'm working on a custom OSL shader for Maya. I'm adding attributes to the shape node of objects and using getattribute() in my OSL code to manipulate those attributes. I have attributes for color correct, base color, rim width and rim color. (the last 2 are for facing ratio). My OSL always compiles and I'm always able to connect it to the material I'm using. But every time I check if it's working in the Arnold render view, my sliders on my attributes don't do anything. The goal is to have an image file connected to the base color of the material and have the color correct node affect base color (which would affect the texture file)
At first I thought my problem was I was trying to do too much in a single OSL node (I was using getattribute for all of the attributes I listed above). So I tried isolating it to just the color correct attribute and still nothing. Is anyone familiar with OSL and can help me?
This is what my OSL code is for color correct:
shader
colorCorrect
(
float modifier = 1[[float min = 0, float max = 72]],
color bob = 0,
output color result = 0
)
{
color temp = transformc("rgb", "hsv", bob);
temp[0] = temp[0] * modifier;
result = transformc("hsv", "rgb", temp);
}
This is what my OSL code is for facing ratio:
shader
Velvet(
float rim_width = 0.2
[[
string label = "Rim Width",
]],
color basecolor = color(1,1,1)
[[
string label = "Base Color",
string widget = "checkBox",
]],
color rimcolor = color(1,0,0)
[[
string label = "Rim Color",
]],
output color resultRGB = 0,
output float resultF = 0)
{
vector i = normalize(I);
vector n = normalize(N);
float d = fabs(dot(-i, n));
d = smoothstep(rim_width, 1.0, d);
getattribute("base_color", resultRGB = mix(rimcolor, basecolor, d));
getattribute("rim_width", resultF = d - 0.5);
}

How to eliminate grayish ARKit/SceneKit shadow plane?

I've implemented one of the many ways to add a shadow plane to an ARKit and SceneKit scene. It works pretty well and the shadows look fine.
The problem is that most of the time the plane also has a grayish cast to it. In other words, it's not completely transparent. On the other hand, sometimes the grayish cast goes away only to reappear a few seconds later. I've tried tweaking just about every SCNNode and SCNMaterial property I can think of, but so far, I can't seem to get the gray to reliably go away. Does anyone have any suggestion on how to solve this?
// Make a transparent shadow plane for the Ground.
let shadowPlane = SCNPlane(width: CGFloat(self.width * 2), height: CGFloat(self.depth * 2))
shadowPlane.cornerRadius = 2
let shadowPlaneNode = SCNNode(geometry: shadowPlane)
shadowPlaneNode.name = shadowPlaneNodeName
shadowPlaneNode.eulerAngles.x = -.pi / 2
shadowPlaneNode.castsShadow = false
let material = SCNMaterial()
material.isDoubleSided = false
material.lightingModel = .constant // .shadowOnly does not show any shadows on iOS
material.colorBufferWriteMask = [.alpha]
shadowPlane.materials = [material]
node.addChildNode(shadowPlaneNode)
After more experimentation I found a solution that seems to be working well. Setting the material .lightingModel to .shadowOnly actually works correctly without any gray cast, but only if you set the .shadowModel on the shadow-producing direct light to .forward instead of .deferred.
In addition, I found that there seems to be a bug in .shadowOnly that causes the plane to be rendered completely black if there is any light in the scene with .type == .omni or == .spot.
Here's the code that's working for me:
let shadowPlane = SCNPlane(width: CGFloat(self.width * 1.5), height: CGFloat(self.depth * 1.5))
let shadowPlaneNode = SCNNode(geometry: shadowPlane)
shadowPlaneNode.name = shadowPlaneNodeName
shadowPlaneNode.eulerAngles.x = -.pi / 2
shadowPlaneNode.castsShadow = false
let material = SCNMaterial()
material.isDoubleSided = false
material.lightingModel = .shadowOnly // Requires SCNLight shadowMode = .forward and no .omni or .spot lights in the scene or material rendered black
shadowPlane.materials = [material]
node.addChildNode(shadowPlaneNode)

Choose random data from an Array in Swift

I would like to create a new Array of 3 random values pulled from this list to be used in two other view controllers. Not sure how to assign the Array so those values are accessible.
class WorkoutDataSource {
var allWorkouts:[Workout]
init() {
allWorkouts = []
let bh1 = Workout(title: "Figure 8s - Clockwise", workoutText: "Clockwise around each leg.", color: UIColor.flatNavyBlueColorDark())
allWorkouts.append(bh1)
let bh2 = Workout(title: "Figure 8s - Counter Clockwise", workoutText: "Counter Clockwise around each leg.", color: UIColor.flatNavyBlue())
allWorkouts.append(bh2)
let bh3 = Workout(title: "Dribble Left Handed", workoutText: "Low and Powerfull.", color: UIColor.flatTealColorDark())
allWorkouts.append(bh3)
let bh4 = Workout(title: "Dribble Right Handed", workoutText: "Low and powerfull", color: UIColor.flatTeal())
allWorkouts.append(bh4)
let bh5 = Workout(title: "Around Both Feet", workoutText: "With feet together, circles around ankles-waist-head, work up & down, the full length of body.", color: UIColor.flatSkyBlueColorDark())
allWorkouts.append(bh5)
let bh6 = Workout(title: "Spider Dribble", workoutText: "feet apart, 1 dribble with each hand in front, then 1 dribble with each hand in back. ", color: UIColor.flatSkyBlue())
allWorkouts.append(bh6)
let bh7 = Workout(title: "Helicopter", workoutText: "1 hand in front, 1 hand in back – move your hands from front to back while catching the ball between your legs.", color: UIColor.flatGreenColorDark())
allWorkouts.append(bh7)
let bh8 = Workout(title: "Scissors - Legs Not Moving", workoutText: "One leg forward and one leg back. Dribble between your legs low and fast.", color: UIColor.flatGreen())
allWorkouts.append(bh8)
let bh9 = Workout(title: "Behind the Back", workoutText: ".",color: UIColor.flatGray())
allWorkouts.append(bh9)
let bh10 = Workout(title: "Fingertip Squeeze", workoutText: ".",color: UIColor.flatPink())
allWorkouts.append(bh10)
}
func getWorkOuts() -> [Workout]{
return allWorkouts
}
}
Thank you
If you simply want to get a random value from the allWorkouts array, then you can do something like this:
let ndx = Int(arc4random_uniform(UInt32(allWorkouts.count)))
let workout = allWorkouts[ndx]
If you want to get three workouts at random, and you don't care if they are unique or not, then you can do something like this:
var workouts = [Workout]()
for i in 0 ..< 3 {
let ndx = Int(arc4random_uniform(UInt32(allWorkouts.count)))
let workout = allWorkouts[ndx]
workouts.append(workout)
}
The workouts array will have the three workouts at that point.
If you want the random items to be unique, then you should use a Set instead of an array and ensure that you run till you get three items, like this:
var workouts = Set<Workout>()
while workouts.count < 3 {
let ndx = Int(arc4random_uniform(UInt32(allWorkouts.count)))
let workout = allWorkouts[ndx]
workouts.insert(workout)
}

AS3 saving from a timeline to a sharedObject (possible to place in an array)

I was hoping someone could offer a simple solution. I am trying to save a 'labeled' frame on the timeline by storing it as a SharedObject.
The user can flip between various different backgrounds on the stage by clicking a button - button one corresponds to background one, background 2 corresponds to btn two and so on... For your reference these backgrounds are stored in a sub timeline in a movieClip. Any tips on how to get this to store..?
I'm open to new theories as I'm not having a lot of success saving from the movieClip on the time line.
I have already posted a question similar to this but I was wandering if it was possible to store these frames in an array? Array1 = image1 Array2 = image2 and so making it easier to store. I'm guessing I would need to make a loadermodule to store these images on the stage as well.
Thanks
// SAVE FUNCTIONS ---------------------------------------
//---------------------------------------------------
//---------------------------------------------------
var mySO:SharedObject = SharedObject.getLocal("iDesign");
bones_mc.x = mySO.data.my_x;
bones_mc.y = mySO.data.my_y;
if (!mySO.data.my_y) {
bones_mc.x = 424;
bones_mc.y = 119;
}
//----
save_btn.addEventListener (MouseEvent.CLICK, clickersave);
function clickersave (e:MouseEvent):void {
mySO.data.my_x = bones_mc.x;
mySO.data.my_y = bones_mc.y;
mySO.data.mybut_x = btrfly_mc.x;
mySO.data.mybut_y = btrfly_mc.y;
mySO.data.mytig_x = tiger_mc.x;
mySO.data.mytig_y = tiger_mc.y;
mySO.data.mybow_x = pink_bow_mc.x;
mySO.data.mybow_y = pink_bow_mc.y;
mySO.data.myblkbow_y = pink_bow_mc.y;
mySO.data.myblkbow_x = pink_bow_mc.x;
// tears saved - - - - - - -
mySO.data.mytear_drop_mc_three_x = tear_drop_mc_three.x;
mySO.data.mytear_drop_mc_three_y = tear_drop_mc_three.y;
mySO.data.mytear_drop_mc_one_x = tear_drop_mc_one.x;
mySO.data.mytear_drop_mc_one_y = tear_drop_mc_one.y;
mySO.data.mytear_drop_mc_two_x = tear_drop_mc.x;
mySO.data.mytear_drop_mc_two_y = tear_drop_mc.y;
mySO.data.mytear_drop_mc_four_x = tear_drop_mc_four.x;
mySO.data.mytear_drop_mc_four_y = tear_drop_mc_four.y;
mySO.data.myframe = caseSwapper.currentFrame;
trace(caseSwapper.currentFrame)
mySO.flush ();
}
//caseSwapper.currentFrame = mySO.data.myframe;
tear_drop_mc_three.x = mySO.data.mytear_drop_mc_three_x;
tear_drop_mc_three.y = mySO.data.mytear_drop_mc_three_y;
CODE ADDED TO MAKE THE TIMELINE SAVE - - - - - - - - - -
// applied to the clickersave function
mySO.data.myBgFrame = 2;
mySO.flush ();
}
if (mySO.data.myBgFrame){
caseSwapper.gotoAndStop(mySO.data.myBgFrame);
}
Not sure I understood exactly what you mean, but if you use click on button1 for BG1, in the click function you could write:
mySO.myBgFrame = 1;
mySO.flush ();
and than, when you need to set the saved BG:
if (mySO.myBgFrame){
bgMovieClip.gotoAndStop(mySO.myBgFrame);
}
Is this what you need?

Amcharts SerialChart multiple line graphs different category value member paths (Silverlight)

EDIT I rewrote my question to make it more understandable after the conversation below with Tony (thanks!).
GOAL Render multiple line graphs (let's say 2) in the same chart. The charts have different x/y value pairs. For one x-value, I do not know both y-values.
I am using Silverlight. The classes available for this are SerialChart and LineGraph. The data source for both graphs is the same and is set at the SerialChart level. The name of the property for the x-axis is also defined there for both graphs (CategoryValueMemberPath).
As suggested by the amCharts documentation, we need to create objects that have a property for the category axis (x-axis) and then one property per graph. Let's call them "Graph1" and "Graph2". So the data source looks something like this:
List<MyClass> data = new List<MyClass>()
{
new MyClass() { Category = 0.1, Graph1 = 0.14, Graph2 = ??? }
,new MyClass() { Category = 0.15, Graph1 = ???, Graph2 = 0.05 }
,new MyClass() { Category = 0.2, Graph1 = 0.35, Graph2 = ??? }
,new MyClass() { Category = 0.18, Graph1 = ???, Graph2 = 0.12 }
... and so on ...
}
PROBLEM What am I supposed to do about the "???" values? I do not have the actual value for that graph for that category value.
If I do not set a value, the default value of 0.0 is assumed and it draws a spike to the x-axis. If I set the previously known Graph1/Graph2 value, then it creates a horizontal connection where there is not supposed to be one. I am basically altering the graph which leads to a wrong result.
So how do I solve this? I am getting the feeling that amCharts do not support this scenario.
You need to add two 'value' axes, one in the X direction and one in the Y direction (imagine, like a bubble chart).
// AXES
// X
var xAxis = new AmCharts.ValueAxis();
xAxis.position = "bottom";
xAxis.gridAlpha = 0.1;
xAxis.autoGridCount = true;
chart.addValueAxis(xAxis);
// Y
var yAxis = new AmCharts.ValueAxis();
yAxis.position = "left";
yAxis.gridAlpha = 0.1;
yAxis.autoGridCount = true;
chart.addValueAxis(yAxis);
Merge all your data points into one array with a common X axis field name ('x' in my example) and for points on line 1, add a property of 'line1' with its value, and for points on line 2, add a property of 'line2'.
For example, your data would look like this:
var chartData = [
{x:0.1,line1:0.25},
{x:0.246,line1:0.342},
{x:0.12,line2:0.16},
{x:0.3,line2:0.485}
];
Then add a 'graph' for each line to your chart specifying where to get the value from in the object array.
// GRAPHS
var graph = new AmCharts.AmGraph();
graph.xField = "x";
graph.yField = "line1";
graph.lineAlpha = 1;
graph.lineColor = '#FF9E01';
chart.addGraph(graph);
var graph2 = new AmCharts.AmGraph();
graph2.xField = "x";
graph2.yField = "line2";
graph.lineAlpha = 1;
graph2.lineColor = '#9EFF01';
chart.addGraph(graph2);
I've put all this into a Fiddle for you - http://jsfiddle.net/64EWx/

Resources