ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Changing object colour relating to values in json import

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Gary Sweeney
Changing object colour relating to values in json import
on Jul 17, 2018 at 11:40:49 am

Hi,

I'm trying to create a heat map style graphic relating to the image below.



I want each of the zones to change colour depending on values relating to a json import.

Ideally the colour would change from green to red depending on the value, with 0 (min) being green and say 40 (max) being red.

I have very limited knowledge of expressions and would appreciate any help.

Thanks, Gary


Return to posts index

Scott McGee
Re: Changing object colour relating to values in json import
on Jul 17, 2018 at 11:58:56 am

I don't know your layout for your Json, but this is the idea behind it. Also I've just copied and pasted the colours I used for a weather map. So you'll want to look at what colour values you'd want.

txt = footage("file.json").sourceData;
input = txt.zone1

if ( input <= 5 && input >= 0 ){
([0,255,210,255]/255)}
else if ( input <= 10 && input >= 6 ){
([0,255,190,255]/255)}
else if ( input <= 15 && input >= 11 ){
([0,255,170,255]/255)}
else if ( input <= 20 && input >= 16 ){
([0,255,150,255]/255)}
else if ( input <= 25 && input >= 21 ){
([232,255,0,255]/255)}
else if ( input <= 30 && input >= 26 ){
([252,210,0,255]/255)
}else{
([255,255,255,255]/255)};


If you are clever about it, you could label your layers and use

a = thisLayer.name
txt = footage("file.json").sourceData;
input = txt[a]


This would allow you to just copy and paste the expression onto all layers and you layer names will trigger that.


Return to posts index

Gary Sweeney
Re: Changing object colour relating to values in json import
on Jul 18, 2018 at 11:25:02 am

Hi Scott,

Thanks for the reply, I think I understand what you are saying, I'm just struggling to figure out how to link my json to the input part.

I should've attached my json file in the last post, here is what I'm working with.
12559_pitchmap.json.zip
Zone 1 represents an individual receiving a ball & Zone 2 is where it goes.

Sorry for the lack of knowledge, just starting to get my head around it.

Thanks


Return to posts index


Scott McGee
Re: Changing object colour relating to values in json import
on Jul 20, 2018 at 8:10:40 am

I noticed an issue with your json, which was it flagging issues for me when importing it? But it was the Zone: "One" and Zone: "Two". It appeared to not like the "", but after deleting and retyping it let me import it.

otherwise this worked fine for me. Also I included the part that uses the layers name to reference it so you would only need to reference the array you want [0] or [1], based on your json layer.

txt = footage("pitchmap.json").sourceData;
a = thisLayer.name;
input = txt[0][a];

if ( input <= 5 && input >= 0 ){
([0,255,210,255]/255)}
else if ( input <= 10 && input >= 6 ){
([0,255,190,255]/255)}
else if ( input <= 15 && input >= 11 ){
([0,255,170,255]/255)}
else if ( input <= 20 && input >= 16 ){
([0,255,150,255]/255)}
else if ( input <= 25 && input >= 21 ){
([232,255,0,255]/255)}
else if ( input <= 30 && input >= 26 ){
([252,210,0,255]/255)
}else{
([255,255,255,255]/255)};

Don't forget when exporting you also need to put it onto the timeline otherwise the export will come out wrong.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]