Why change the grid-size when switching media-query? - singularitygs

I have been using singularity for about a small year now and I'm still not 100% I'm using it at its full potential, or the "correct" way really.
The main question I have is why you should change the grid-size depending on a media-query.
I'm using SGS like this at the moment:
grids: 12;
$gutters: 1/2;
.column {
// mobile first ... full-width
#include breakpoint($from-medium) { // 2 columns on medium devices
#include grid-span(6, first);
&:nth-child(even) {
#include grid-span(6, last);
}
}
#include breakpoint($from-large) { // 3 columns on larger devices
#include grid-span(4);
&:nth-child(even) {
#include grid-span(4); // needed to override previous MQ since I'm only using min-width.
}
&:nth-child(3n) {
#include grid-span(4, last);
}
&:nth-child(3n+1) {
#include grid-span(4, first);
}
}
}
I would love to reduce the code for this and maybe changing grids in between MQ's might help but I'm not seeing how?

I have different number of columns for different screen sizes so that gutter size is consistent.
If you have one grid definition for all grid columns, then the smaller the screen -- the smaller the gutters. For example, with a grid definition of 12, 0.1 (that is, 12 columns and gutter size is 0.1 of column size), on a portrait phone screen (320px wide) each gutter will be only 2.4px wide. It's ridiculously small and ruins grid looks.
On the other hand, if you had a 3, 0.1 grid for 320px screen, then gutter size would be a substantial 10px.
Not only gutter sizes become consistent throughout your screen sizes, but columns too. Have a look at the bottommost demo on this page: http://lolmaus.github.io/singularity-quick-spanner/ When you adjust browser window width, the width of each item in the grid varies in a predictable range. I. e. it's always between 154 and 180 pixels wide, on any device.
This approach changes your mind model of responsive web design. You can now design with consistent blocks that fit into certain number of columns, regardless of the device.
To make the most out of this approach, i recommend switching from media queries to element queries. Element queries require some JS help, that is you need a JS library. There are several implementations. EQ.js from the author of Singularity is not the ideal, but definitely the best one.

Related

How to make a high ISO effect in a dark room?

When we use mobile or semiprofessional cameras in the room with bad light they increase ISO as a rule, the result is shown below:
This is a frame from video, as you can see there is a lot of noise. Maybe it's a little weird but I need to generate a similar noise on high quality video. However, a simple noise generator will produce a something like that:
Does anyone have some ideas how to get result like on the first frame? Or maybe there is a some existing noise generator/algorithm to make it? I will be grateful for any help.
I assume you simply added small random RGB to your image...
I would leave color as is and try to reduce color intensity by small random amount to darken the image and create a similar form of noise. Just by multiply your RGB color with random number less than one ...
To improve result visual the random value should be with gauss distribution or similar. Here small C++/VCL example:
//$$---- Form CPP ----
//---------------------------------------------------------------------------
#include <vcl.h>
#include <math.h>
#pragma hdrstop
#include "win_main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMain *Main;
Graphics::TBitmap *bmp0,*bmp1;
//---------------------------------------------------------------------------
__fastcall TMain::TMain(TComponent* Owner) : TForm(Owner)
{
// init bmps and load from file
bmp0=new Graphics::TBitmap;
bmp1=new Graphics::TBitmap;
bmp0->LoadFromFile("in.bmp");
bmp0->HandleType=bmDIB;
bmp0->PixelFormat=pf32bit;
bmp1->Assign(bmp0);
ClientWidth=bmp0->Width;
ClientHeight=bmp0->Height;
Randomize();
}
//---------------------------------------------------------------------------
void __fastcall TMain::FormDestroy(TObject *Sender)
{
// free bmps before exit
delete bmp0;
delete bmp1;
}
//---------------------------------------------------------------------------
void __fastcall TMain::tim_updateTimer(TObject *Sender)
{
// skip if App not yet initialized
if (bmp0==NULL) return;
if (bmp1==NULL) return;
int x,y,i,a;
union _color
{
BYTE db[4];
DWORD dd;
};
// copy bmp0 into bmp1 with light reduction and noise
for (y=0;y<bmp0->Height;y++)
{
_color *p0=(_color*)bmp0->ScanLine[y];
_color *p1=(_color*)bmp1->ScanLine[y];
for (x=0;x<bmp0->Width;x++)
{
p1[x]=p0[x];
for (a=40,i=0;i<10;i++) a+=Random(10); // "gauss" PRNG in range 40 .. 140
for (i=0;i<3;i++) p1[x].db[i]=(DWORD(p1[x].db[i])*a)>>8; // multiply RGB by a/256
}
}
// render frame on App canvas
Canvas->Draw(0,0,bmp1);
// bmp1->SaveToFile("out.bmp");
}
//---------------------------------------------------------------------------
input image:
output image:
You can play with the PRNG properties to tweak light and noissyness.
What you see in that frame is not the raw sensor noise, nor a simulation of film grain as the accepted answer seems to suggest. Instead, it is the result of a noise-reduction filter that is applied to the high-ISO image. Without the filter, you’d see a lot of noise, mostly Poisson noise.
I don’t know what noise-reduction filter is built into the camera, but it likely is applied to the raw image, before conversion to RGB. Here are many papers describing such filters.
You basically need to increase "grain" size, and maybe flat out your noise spots. It will be hard to obtain a natural-looking result, as those grain spots in a video are obtained from various types of interpolations over values obtained from the camera sensor (with specific noise that a sensor produces). Take for example "analog" film cameras (the pictures taken with the film have that grainy natural look from the effective grains sizes/shapes of minerals that are used in the film itself). If it were so easy to produce a natural-looking film alike filter over digital images the film industry would not see the comeback that happens now.
With that said there are three things that come to my mind that could work:
Median Blur over (image + some noise): https://docs.opencv.org/master/d4/d13/tutorial_py_filtering.html
An image that has is generated with Perlin noise, scaled accordingly to your specific frame size + added over colors of your image * some factor:
https://github.com/ruslangrimov/perlin-noise-python-numpy
* factor + your image = result
Film a really dark room with a camera set up to produce the same frame resolution and with high iso, add obtained video frames over your video (some image manipulation to be applied).
Hope any of this helps and good luck with your project.

Remove padding in thumbnail grid

Please look at this gist:
http://sassmeister.com/gist/6d575ec85663865fa567
There you can see a placehold.it thumbnail grid realized via float-span
What i need now is:
The padding-left of the first .item in each row should be 0
The padding-right of the last .item in each row should be 0
this would then end up in the thumbnail grid perfectly aligning with the rest of the content (e.g. the lorem ipsum text)
What is the beast way to achieve this with singularitygs?
UPD 2014-07-21
what i need can be seen in this screen:
i don't need another padding style, i need the padding from the first and last item in each row removed. this can't be done via css, because the sass calculations would be wrong.
UPD 2014-07-30
based on various sources, i managed to establish this mixin:
#mixin thegrid($layout, $cols, $el: "div", $thegutter: .1){
#include layout($layout, $gutter: $thegutter) {
#for $i from 1 through $cols {
#if $i == 1 {
#{$el}:nth-child(#{$cols}n+#{$i}) {
#include isolation-span(1, $i, left);
}
}
#else if $i < $cols {
#{$el}:nth-child(#{$cols}n+#{$i}) {
#include isolation-span(1, $i, none);
}
}
#else {
#{$el}:nth-child(#{$cols}n+#{$i}) {
#include isolation-span(1, $i, right);
}
}
}
}
}
which can be called e.g. via:
$layout: 1 1 1;
#include thegrid($layout, 3, $el: ".item");
an example can be seen here: http://sassmeister.com/gist/7a45960747ad3d4bbf56
Not sure what you mean.
You're applying gutters with an absolute value. This is what Singularity calls fixed gutters.
Singularity realizes fixed gutters by applying padding to grid elements.
Padding can be applied in two styles:
split: the gutter size is divided by two and the resulting value is applied as left and right padding to every grid item.
opposite: the value of gutter size is applied as right padding to every item except items occupying the last column.
So if you are unhappy with split gutters, switch to opposite gutters. That's the default behavior, so you can simply comment out #include add-gutter-style('split');.
If you are unhappy with either gutter style, well, you can manually remove padding that you don't need. This doesn't make a lot of sense because if you apply zero padding to items other than occupying the first and the last columns, you will distort your grid. And if you apply them only to the items occupying the first and the last columns, you basically get the same setup as with opposite gutter styles.
You might get better help if you make a pencil drawing of desired layout.
UPD 2014-07-21
OK, now it's clear what you mean.
So you basically want split gutters for the outer level and opposite gutters for the inner level. You're already using the layout() mixin required to override grid settings, so you could just tell it to override gutter styles, e. g.:
#mixin layout(2, $gutter-style: 'opposite') {
Unfortunately, due to the fact that Singularity creates fixed gutters via padding, they only play nice in split mode. In opposite mode fixed gutters produce uneven columns.
So you'll have to use relative gutters:
#mixin layout(2, 0.1, $gutter-style: 'opposite') {
There are a couple of things you have to keep in mind:
Spanning the last item in each row separately.
With the opposite gutter style, the last item in each row is special: it contains no right gutter. So you will have to tell Singularity which item is the last one in row.
To do this, we will use the :nth-child(Xn + Y) selector, where X is the number of items in the row and Y is the number of target item in the row. As we're targeting the last item, X and Y will be equal:
#include float-span(1);
&:nth-child(4n + 4) {
#include float-span(1, last);
}
Isolating media queries.
Once you do that for each breakpoint, you'll end up with styles applied to different items in different breakpoints. Those styles will not be overridden and thus will leak from smaller to larger breakpoints, breaking the layout.
You could override them manually, but that's a lot of thankless job. Instead, isolate your media queries so that styles don't leak:
$beforeMediumBreakpoint: max-width 799px;
$mediumBreakpoint: 800px;
// Mobile view (formerly without a media query)
#include breakpoint($beforeMediumBreakpoint) {
Demo: http://sassmeister.com/gist/dd9f1af025900d7e63db
PS A piece of advice from me: don't use fixed gutters and split mode. Use fluid gutters and the default opposite mode. This will save you from a lot of trouble! You can always simulate split gutters by applying padding to the outermost container.
You can do some math to calculate relative padding for the container that will be equal to the gutter between grid items! With the magic of math, you can even apply bottom margins to grid items equal to grid gutters, producing a beautiful uniform thumbnail grid.
I've created a nifty extension Singularity Quick Spanner that can reduce the amount of work you need to do to set up thumbnail grids. See it in action (note vertical gutters equal to horizontal gutters).

Why are my grid-spans getting extra margins?

Using the Singularity Grid System:
I have a nested grid. Nothing fancy, just 2 column. Code is like this:
main-content { #include grid-span(8,1); }
sidebar { #include grid-span(4,9); }
It renders fine, but I keep getting undesired margins. The main content has a small margin-left and the sidebar has a small margin-right. I want these to have zero margins on the edge, similar to declaring main-content as "alpha" and sidebar as "omega."
Here is the CSS (at full desktop width):
main-content { width: 65%;float: left;margin-right: -100%;margin-left: 0.83333%;clear: none;}
sidebar-first {width: 31.66667%;float: right;margin-left: 0;margin-right: 0.83333%;clear:none;}
I didn't think this was default Singularity behavior, to add those small margins on the outer edges of my grid. Or is it? Can I get around it somehow? (besides just manually adding margin-left:0 and margin-right:0). Of course if there's margin on the outer edges, the total width of each DIV should increase as well (e.g. - for the main-content, instead of 65%, it'd be 65.83333)

Using singularity, I find some inconsistencies in floats with wide containers

Im trying singularity for the first time, and I'm trying to recreate a grid I have. Simple one.
This is a simple structure, for the test:
<header>
header
</header>
<main>
main content
</main>
<aside>
aside
</aside>
<footer>footer, nav, social icons etc</footer>
So in a 12 col grid, the header is full width, the main is 9 cols width, the aside is 3 cols width and the footer is full 12 cols.
Anyway, the inconsistency is this: the header, the aside, and the footer have float:right, but the main is float:left, so it gets out of the flow of the document.
This is the grid:
/* grid */
$grids: 3;
$grids: add-grid(5 at 500px);
$grids: add-grid(7 at 768px);
$grids: add-grid(12 at 1024px);
$gutters: 1/3;
This is the rest:
html, body {
margin: 0;
padding: 0;
height: 100%;
background: #e1e1e1;
color: #333;
}
.container {
min-height: 100%;
margin: 0 auto;
#include background-grid;
}
/* main layout */
header {
#include grid-span(3, 1);
background: red;
#include breakpoint(1024px) {
#include grid-span(12, 1);
}
}
main {
#include grid-span(3, 1);
background: green;
#include breakpoint(1024px) {
#include grid-span(7, 2);
}
}
So the issue is that, it does not respect the flow and it overlaps with the header, like this http://imageupload.maxmendez.net/images/incon.png. The green main, should be below the header.
In order to fix that, I had to do this:
main {
#include grid-span(3, 1);
background: green;
#include breakpoint(1024px) {
#include grid-span(7, 2, $options: 'right');
}
}
Adding options right, seems to clear to the right and fix my issue. Is there a reason that im overlooking as to why the mai is floating left?
Still havent tested in IE, but im worried about compatibility.
It seems as if you are unfamiliar with what the clear property does or how it works. When using the Isolation output method, you need to clear your own floats, something you may not have been exposed to with more traditional Float output method based grid systems/frameworks. A good place to read up on them is MDN's Clear section.
In the example you've provided, header spans the whole grid width. Because the last item in a grid is floated right, the header is likewise floated right. This is to hide any percentage rounding issues with the last item in a row and have them all line up to the right edge. Otherwise, all grid items are floated to the left. Because this item is floated right, in order to clear it's border edge (not have it overlap), we need to tell the next item in the DOM (your main element) to clear items floated right. This will push it below header, creating a new row. Because footer is full width and is therefore floated right, and your aside is also floated right, there is only enough room on the main/aside row for an item of width 100%-width(aside). Because footer is too wide for that remaining area, it drops to the next row without needing to clear its float. That being said, this will only not overlap with main because main and aside are the same height; if main becomes taller than aside, footer will overlap it. To prevent this, you should tell footer to clear things floated to the left, which main is.
While this all sounds fairly complicated, don't be worried about cross-browser compatibility. We have tested Singularity extensively across all browsers, including IE, and it works fine.
If after all of this you are still uncomfortable with the Isolation output method, you can switch to the Float output method. The two have very different mental models; Isolation is about discretely positioning elements in relation to each other whereas Float is more akin to walking across a row on your grid. Keep in mind that if you switch to Float you will then need to use the push and pull mixins to nudge things around the grid.
Hope this helps!

Evenly distribute items on the screen

I am trying to solve this little puzzle (the algorithm): I have N image icons and I want to distribute them evenly on users screen. Say, I put them in a table. If there is one image, there will be one cell in a table. If two - one row with two columns, if three - one row and three columns, if four - two rows, two columns... and so on until row space is gone and since then the table should only grow in columns without adding extra rows.
I'm trying to figure an algorithm for this and perhaps this is something that has a solution already somewhere?
My attempt is so far something like this:
obtain_max_rows()
obtain_visible_columns()
if (number_of_pictures > max_rows*max_columns)
{
columns = roundup(number_of_pictures/max_rows)
for(max_rows){generate row;for columns{generate column}}
}
else
{
**here comes to trouble...**
}
This logic is bit silly though - it somehow needs to think cases where there are 12 pictures on first screen and 2 on the other trying to balance it say 8/6 or somehow like that.
I think I found your answer:
typedef struct{int width, height;} rectangle;
...
rectangle findOptimalDivision(int numberOfCuts){
int x = numberOfCuts, y = (int)sqrt(numberOfCuts);
while (x%y) { // when y = 1 it will always exit out (anything can be divided by 1)
y--;
}
return (rectangle){y,numberOfCuts/y};
}
This should give you the height and width of the table (or rectangle) in terms of cells.
I tested this with 1 - 100 as the parameter and it seems to give the proper outputs.
Message me if you have any problems.

Resources