### Author Topic: Rolling Shutter Effect Explained Even Cheaper (than Matt Parker)  (Read 1512 times)

0 Members and 1 Guest are viewing this topic.

#### @rt

• Frequent Contributor
• Posts: 747
##### Rolling Shutter Effect Explained Even Cheaper (than Matt Parker)
« on: July 16, 2017, 05:49:26 am »
Hi Guys
This is a video reply to a video reply by standupmaths, to a video by SmarterEveryDay.
I hope you enjoy

The following users thanked this post: Cliff Matthews

#### @rt

• Frequent Contributor
• Posts: 747
##### Re: Rolling Shutter Effect Explained Even Cheaper (than Matt Parker)
« Reply #1 on: July 19, 2017, 01:58:08 am »
I cleaned up the software a little, mainly because I forgot the all important comparison propeller without the effect.
This is roughly 120x240 with a palette of 256 colours.

The following users thanked this post: BravoV

#### firewalker

• Super Contributor
• Posts: 2160
• Country:
##### Re: Rolling Shutter Effect Explained Even Cheaper (than Matt Parker)
« Reply #2 on: July 19, 2017, 03:17:17 am »
No code? How do you expect us to criticize and correct you?

Alexander.
Become a realist, stay a dreamer.

#### @rt

• Frequent Contributor
• Posts: 747
##### Re: Rolling Shutter Effect Explained Even Cheaper (than Matt Parker)
« Reply #3 on: July 20, 2017, 01:04:20 am »
It was definitely about making an animation rather than writing a program, but go for your life

First thing I’d do is roll the circle drawing into loops, then create an array of the four rotating points,
and roll the propeller blades into a loop as well.

Code: [Select]
void transferToScreen() {       unsigned int  lrow;    unsigned int  lcol;    unsigned int  lpixelvalue;        for (lrow = smlsizey-1; lrow > 0; lrow--) { // delete previous frame from bitmap    for (lcol = 0; lcol < FDATA_HEIGHT; lcol++) {    lpixelvalue = 0;firedata[lcol][lrow] = 0x00;    imgdata[bmpindex] = (lpixelvalue >> 16) & 0xFF;    imgdata[bmpindex+1] = (lpixelvalue >> 8) & 0xFF;    imgdata[bmpindex+2] = lpixelvalue & 0xFF;    bmpindex+=3;    }}        // do propeller rotation    int increment = 6    rotation = rotation + increment;    if (rotation > (360-increment)) {rotation = 0;}        ox = 75; oy = 80; // propeller blade a    x = 75; y = 20; // 7    pixelrotation();    drawline(ox,oy,x,y);    lcol = xnew; lrow = ynew;    cx = xnew; cy = ynew; radius=5; drawcircle();    cx = xnew; cy = ynew; radius=4; drawcircle();    cx = xnew; cy = ynew; radius=3; drawcircle();    cx = xnew; cy = ynew; radius=2; drawcircle();    cx = xnew; cy = ynew; radius=1; drawcircle();    firedata[lcol][lrow] = 0x2F; // prop edge a    ox = 75; oy = 80; // propeller blade b    x = 75; y = 140;    pixelrotation();    drawline(ox,oy,x,y);    lcol = xnew; lrow = ynew;    cx = xnew; cy = ynew; radius=5; drawcircle();    cx = xnew; cy = ynew; radius=4; drawcircle();    cx = xnew; cy = ynew; radius=3; drawcircle();    cx = xnew; cy = ynew; radius=2; drawcircle();    cx = xnew; cy = ynew; radius=1; drawcircle();    firedata[lcol][lrow] = 0x3F; // prop edge b        ox = 75; oy = 80; // propeller blade c    x = 135; y = 80;    pixelrotation();    drawline(ox,oy,x,y);    lcol = xnew; lrow = ynew;    cx = xnew; cy = ynew; radius=5; drawcircle();    cx = xnew; cy = ynew; radius=4; drawcircle();    cx = xnew; cy = ynew; radius=3; drawcircle();    cx = xnew; cy = ynew; radius=2; drawcircle();    cx = xnew; cy = ynew; radius=1; drawcircle();    firedata[lcol][lrow] = 0x2F; // prop edge c        ox = 75; oy = 80; // propeller blade d    x = 15; y = 80;    pixelrotation();    drawline(ox,oy,x,y);    lcol = xnew; lrow = ynew;    cx = xnew; cy = ynew; radius=5; drawcircle();    cx = xnew; cy = ynew; radius=4; drawcircle();    cx = xnew; cy = ynew; radius=3; drawcircle();    cx = xnew; cy = ynew; radius=2; drawcircle();    cx = xnew; cy = ynew; radius=1; drawcircle();    firedata[lcol][lrow] = 0x3F; // prop edge d        lcol = ox; lrow = oy;    firedata[lcol][lrow] = 0x0F; // prop centre        if (cycledir == 0) {    pixcol++; pixcol++; // cycle colours    if (pixcol > 0xFD) {cycledir = 1;}    } else {    pixcol--; pixcol--;    if (pixcol < 0x2F) {cycledir = 0;}    } // cycledir        int doline = 0;    while (doline < 145) { // copy line to shutter effect buffer    lcol = shutterline; lrow = doline;    shutdata[lcol][lrow] = firedata[lcol][lrow];    doline++;    } // doline        shutterline--;    if (shutterline < 0) {shutterline = 159;} // move rolling shutter        if (shutenable == 719) {shutterline = 160;} // startup raster delay    if (shutenable > 720) {        doline = 0;    int shuttercnt = 159;    while(shuttercnt > shutterline) {    doline = 0;    while (doline < 145) { // write shutter effect buffer to screen    lcol = shuttercnt; lrow = doline;    firedata[lcol][lrow] = shutdata[lcol][lrow];    doline++;    } // doline    shuttercnt--;    } // shuttercnt        doline = 0;    while (doline < 285) { // moving indicator line    lcol = shutterline - 1; lrow = doline;    firedata[lcol][lrow] = 0xBE;    doline++;    } // doline        } // shutenable    shutenable++;    if (shutenable > 9999) {shutenable = 9999;}        bmpindex = 54;    for (lrow = smlsizey-1; lrow > 0; lrow--) { // write current frame to bitmap image    for (lcol = 0; lcol < FDATA_HEIGHT; lcol++) {    lpixelvalue = palette[firedata[lcol][lrow]];    imgdata[bmpindex] = (lpixelvalue >> 16) & 0xFF;    imgdata[bmpindex+1] = (lpixelvalue >> 8) & 0xFF;    imgdata[bmpindex+2] = lpixelvalue & 0xFF;    bmpindex+=3;    }}}

#### BravoV

• Super Contributor
• Posts: 5065
• Country:
##### Re: Rolling Shutter Effect Explained Even Cheaper (than Matt Parker)
« Reply #4 on: July 20, 2017, 01:26:38 am »
Hey @rt, whats the song's name for the 2nd video ?

#### @rt

• Frequent Contributor
• Posts: 747
##### Re: Rolling Shutter Effect Explained Even Cheaper (than Matt Parker)
« Reply #5 on: July 20, 2017, 02:13:13 am »
Did you like it? Well guess what.... Now you’re a Twilight fan! Go team Edward!!!

Code: [Select]
    unsigned int  lrow;    unsigned int  lcol;    unsigned int  lpixelvalue;    int innercnt = 0;        for (lrow = smlsizey-1; lrow > 0; lrow--) { // delete previous frame from bitmap    for (lcol = 0; lcol < FDATA_HEIGHT; lcol++) {    lpixelvalue = 0;firedata[lcol][lrow] = 0x00;    imgdata[bmpindex] = (lpixelvalue >> 16) & 0xFF;    imgdata[bmpindex+1] = (lpixelvalue >> 8) & 0xFF;    imgdata[bmpindex+2] = lpixelvalue & 0xFF;    bmpindex+=3;    }}        int pointsx[4] = {75,75,135,15};    int pointsy[4] = {20,140,80,80};        // do propeller rotation    int increment = 6; // must be evenly divisible by 360 at the moment    rotation = rotation + increment;    if (rotation > (360-increment)) {rotation = 0;}        innercnt = 0;    while (innercnt < 4) {    ox = 75; oy = 80; // propeller blade    x = pointsx[innercnt]; y = pointsy[innercnt];    pixelrotation();    drawline(ox,oy,x,y);    lcol = xnew; lrow = ynew;    cx = xnew; cy = ynew; radius=5; drawcircle();    cx = xnew; cy = ynew; radius=4; drawcircle();    cx = xnew; cy = ynew; radius=3; drawcircle();    cx = xnew; cy = ynew; radius=2; drawcircle();    cx = xnew; cy = ynew; radius=1; drawcircle();    firedata[lcol][lrow] = 0x2F; // prop edge    innercnt++;    } // innercnt

Smf