how to rotate polygon pentagon dial

Former Member
Former Member

I cant figure out how to rotate this polygon

dc.fillPolygon([ [223, 125], [120, 125], [120, 115], [223, 115], [230, 120] ]);

iknow i have to use Math.sin(alpha) and  Math.cos(alpha) alpha being var alpha = Math.PI/6*(1.0*clockTime.hour+clockTime.min/60.0);

but i cant figure it out. Any help would be super nice.

  • Former Member
    0 Former Member over 5 years ago in reply to jim_m_58

    that works. but i have another issue. when i try these i get out of memory. I have no background prosesses, but eclipse says i'm out of mem.

    My total time is high, about 60 000 ms. and i don't know ha to get that down?

    are the too many lines of code?(1800 lines)

    function drawHands(dc, xPos, yPos, clockTime) {
    var hourHand;
    var minuteHand;

    // draw the hour hand; convert it to minutes and compute the angle.
    hourHand = (((clockTime.hour % 12) * 60) + clockTime.min);
    hourHand = hourHand / (12 * 60.0);
    hourHand = hourHand * Math.PI * 2 - RAD_90_DEG;

    //drawHand3Color(dc, xPos, yPos, hourHand, 70, 9, Gfx.COLOR_LT_GRAY);

    // draw the minute hand
    minuteHand = (clockTime.min / 60.0) * Math.PI * 2 - RAD_90_DEG;

    //drawHand3Color(dc, xPos, yPos, minuteHand, 102, 8.5, Gfx.COLOR_LT_GRAY);

    //Functions.DrawPolygon(dc, 40, time);
    //time = Math.PI/30.0*clockTime.min;
    //Functions.DrawPolygonHour(dc);
    //Functions.DrawPolygon(dc);

    var time = Sys.getClockTime();
    var hour = (((time.hour % 12) * 60 + (time.min)).toFloat() / 12);
    var hourHand2 = getHand(120, 120, hour, 65, 4, 0);
    var minute = time.min.toFloat() + time.sec.toFloat()/60;
    var minuteHand2 = getHand(120, 120, minute, 102, 4, 0);
    //drawShadow(dc, minuteHand2);
    //drawShadow(dc, hourHand2);
    dc.setColor(Gfx.COLOR_LT_GRAY, Gfx.COLOR_TRANSPARENT);
    dc.fillPolygon(hourHand2);
    dc.fillPolygon(minuteHand2);


    }

    function getHand(centerX, centerY, minute, length, width, radius) {
    var angle = minute * Math.PI / 30;
    var handShape = [ [-width, -radius], [-width, -length], [width, -length], [width, -radius] ];
    var result = new [handShape.size()];
    var cosAngle = Math.cos(angle);
    var sinAngle = Math.sin(angle);

    // Transform the coordinates
    for (var i = 0; i < result.size(); i += 1)
    {
    var x = (handShape[i][0] * cosAngle) - (handShape[i][1] * sinAngle);
    var y = (handShape[i][0] * sinAngle) + (handShape[i][1] * cosAngle);
    result[i] = [ centerX+x, centerY+y];
    }
    return result;
    }

  • do you have the background permission on?  Turn it off if you don't use backgrounding, or you'll get one or two out of memory errors when you first start up.

    If that's not it, what target and what do you see for memory (current and peak) in the memory viewer in the sim.

  • Former Member
    0 Former Member over 5 years ago in reply to jim_m_58

    background is off. current peak is 91.6kb

  • And the max for the target is 92k, correct?  Is that before or after you tried the app settings editor in eclipse?  Even after, I'd look at cutting back on the WF.

  • Former Member
    0 Former Member over 5 years ago in reply to jim_m_58

    after. I'm trying to cut back. but i cant se what is taking so much mem.

  • Former Member
    0 Former Member over 5 years ago in reply to Former Member

    I have now remove everything execpt background and analog hour, min and sec. still 67 kb. 

  • Check you are setting the clip region correctly.  What I'll do sometimes is set the clip, then set a color and do a dc.clear(), so you can see exactly what it is on the screen.

  • Former Member
    0 Former Member over 5 years ago in reply to jim_m_58

    Hmm could you show me an example on how please? 

  • When you do the clip do this:

    dc.setClip(whatever you're using);

    dc.setColor(Gfx.COLOR_BLUE,Gfx.COLOR_BLUE); //different color than your background color

    dc.clear();

    dc.setColor(whatever you want them to be);

  • Former Member
    0 Former Member over 5 years ago in reply to jim_m_58

    Thank you very much :D. The clip is a bit big så now i can work on that. And i found som bad code so i optimized it and now i'm down from 89.2kb to 73 kb mem use :D